Added new Panel stuff
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / WatchScreen.cpp
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #include "libs/Kernel.h"
9 #include "Panel.h"
10 #include "PanelScreen.h"
11 #include "MainMenuScreen.h"
12 #include "WatchScreen.h"
13 #include "libs/nuts_bolts.h"
14 #include "libs/utils.h"
15 #include "modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h"
16 #include "modules/robot/RobotPublicAccess.h"
17 #include "modules/utils/player/PlayerPublicAccess.h"
18
19 #include <string>
20 using namespace std;
21
22 WatchScreen::WatchScreen(){}
23
24 void WatchScreen::on_enter(){
25 this->panel->lcd->clear();
26 this->panel->setup_menu(4, 4);
27 get_temp_data();
28 get_current_pos(this->pos);
29 get_sd_play_info();
30 this->current_speed= get_current_speed();
31 this->refresh_screen(false);
32 this->panel->enter_control_mode(1,0.5);
33 this->panel->set_control_value(this->current_speed);
34 }
35
36 void WatchScreen::on_refresh(){
37 // Exit if the button is clicked
38 if( this->panel->click() ){
39 this->panel->enter_screen(this->parent);
40 return;
41 }
42
43 // see if speed is being changed
44 if(this->panel->control_value_change()) {
45 this->current_speed= this->panel->get_control_value();
46 // change actual speed
47 set_current_speed();
48 this->refresh_screen(false);
49 }
50
51 // Update Only every 20 refreshes, 1 a second
52 static int update_counts = 0;
53 update_counts++;
54 if( update_counts % 20 == 0 ){
55 get_sd_play_info();
56 get_current_pos(this->pos);
57 get_temp_data();
58 this->current_speed= get_current_speed();
59 this->refresh_screen(false);
60 }
61 }
62
63 // fetch the data we are displaying
64 void WatchScreen::get_temp_data() {
65 void *returned_data;
66 bool ok;
67
68 ok= THEKERNEL->public_data->get_value( temperature_control_checksum, bed_checksum, current_temperature_checksum, &returned_data );
69 if(ok) {
70 struct pad_temperature temp= *static_cast<struct pad_temperature*>(returned_data);
71 this->bedtemp= round(temp.current_temperature);
72 this->bedtarget= round(temp.target_temperature);
73 //this->bedpwm= temp.pwm;
74 }
75
76 ok= THEKERNEL->public_data->get_value( temperature_control_checksum, hotend_checksum, current_temperature_checksum, &returned_data );
77 if(ok) {
78 struct pad_temperature temp= *static_cast<struct pad_temperature*>(returned_data);
79 this->hotendtemp= round(temp.current_temperature);
80 this->hotendtarget= round(temp.target_temperature);
81 //this->hotendpwm= temp.pwm;
82 }
83 }
84
85 // fetch the data we are displaying
86 double WatchScreen::get_current_speed() {
87 void *returned_data;
88
89 bool ok= THEKERNEL->public_data->get_value( robot_checksum, speed_override_percent_checksum, &returned_data );
90 if(ok) {
91 double cs= *static_cast<double *>(returned_data);
92 return cs;
93 }
94 return 0.0;
95 }
96
97 void WatchScreen::set_current_speed() {
98 bool ok= THEKERNEL->public_data->set_value( robot_checksum, speed_override_percent_checksum, &this->current_speed );
99 if(!ok) this->current_speed= 0;
100
101 }
102
103 void WatchScreen::get_current_pos(double *cp){
104 void *returned_data;
105
106 bool ok= THEKERNEL->public_data->get_value( robot_checksum, current_position_checksum, &returned_data );
107 if(ok) {
108 double *p= static_cast<double *>(returned_data);
109 cp[0]= p[0];
110 cp[1]= p[1];
111 cp[2]= p[2];
112 }
113 }
114
115 void WatchScreen::get_sd_play_info(){
116 void *returned_data;
117 bool ok= THEKERNEL->public_data->get_value( player_checksum, get_progress_checksum, &returned_data );
118 if(ok) {
119 struct pad_progress p= *static_cast<struct pad_progress*>(returned_data);
120 this->elapsed_time= p.elapsed_secs;
121 this->sd_pcnt_played= p.percent_complete;
122 }else{
123 this->elapsed_time= 0;
124 this->sd_pcnt_played= 0;
125 }
126 }
127
128 void WatchScreen::display_menu_line(uint16_t line){
129 // in menu mode
130 switch( line ){
131 case 0: this->panel->lcd->printf("H%03d/%03dc B%03d/%03dc", this->hotendtemp, this->hotendtarget, this->bedtemp, this->bedtarget); break;
132 case 1: this->panel->lcd->printf("X%4d Y%4d Z%7.2f", (int)round(this->pos[0]), (int)round(this->pos[1]), this->pos[2]); break;
133 case 2: this->panel->lcd->printf("%3d%% %2d:%02d %3d%% sd", (int)round(this->current_speed), this->elapsed_time/60, this->elapsed_time%60, this->sd_pcnt_played); break;
134 case 3: this->panel->lcd->printf("%19s", panel->is_playing() ? panel->get_playing_file().substr(4, 19).c_str() : "Smoothie ready"); break;
135 }
136
137 }