update firmware.bin
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / PrepareScreen.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 "LcdBase.h"
12 #include "PrepareScreen.h"
13 #include "ExtruderScreen.h"
14 #include "libs/nuts_bolts.h"
15 #include "libs/utils.h"
16 #include "checksumm.h"
17 #include "PublicDataRequest.h"
18 #include "PublicData.h"
19 #include "TemperatureControlPublicAccess.h"
20 #include "ModifyValuesScreen.h"
21 #include <string>
22 using namespace std;
23
24 PrepareScreen::PrepareScreen()
25 {
26 this->command = nullptr;
27
28 // Children screens
29 if(THEPANEL->temperature_screen != nullptr) {
30 this->extruder_screen = (new ExtruderScreen())->set_parent(this);
31 THEPANEL->temperature_screen->set_parent(this);
32 }else{
33 this->extruder_screen= nullptr;
34 }
35 }
36
37 void PrepareScreen::on_enter()
38 {
39 THEPANEL->enter_menu_mode();
40 // if no heaters or extruder then don't show related menu items
41 THEPANEL->setup_menu((THEPANEL->temperature_screen != nullptr) ? 9 : 5);
42 this->refresh_menu();
43 }
44
45 void PrepareScreen::on_refresh()
46 {
47 if ( THEPANEL->menu_change() ) {
48 this->refresh_menu();
49 }
50 if ( THEPANEL->click() ) {
51 this->clicked_menu_entry(THEPANEL->get_menu_current_line());
52 }
53 }
54
55 void PrepareScreen::display_menu_line(uint16_t line)
56 {
57 switch ( line ) {
58 case 0: THEPANEL->lcd->printf("Back" ); break;
59 case 1: THEPANEL->lcd->printf("Home All Axis" ); break;
60 case 2: THEPANEL->lcd->printf("Set Home" ); break;
61 case 3: THEPANEL->lcd->printf("Set Z0" ); break;
62 case 4: THEPANEL->lcd->printf("Motors off" ); break;
63 // these won't be accessed if no heaters or extruders
64 case 5: THEPANEL->lcd->printf("Pre Heat" ); break;
65 case 6: THEPANEL->lcd->printf("Cool Down" ); break;
66 case 7: THEPANEL->lcd->printf("Extruder..." ); break;
67 case 8: THEPANEL->lcd->printf("Set Temperature"); break;
68 }
69 }
70
71 void PrepareScreen::clicked_menu_entry(uint16_t line)
72 {
73 switch ( line ) {
74 case 0: THEPANEL->enter_screen(this->parent); break;
75 case 1: command = "G28"; break;
76 case 2: command = "G92 X0 Y0 Z0"; break;
77 case 3: command = "G92 Z0"; break;
78 case 4: command = "M84"; break;
79 case 5: this->preheat(); break;
80 case 6: this->cooldown(); break;
81 case 7: THEPANEL->enter_screen(this->extruder_screen); break;
82 case 8: THEPANEL->enter_screen(THEPANEL->temperature_screen); break;
83 }
84 }
85
86 void PrepareScreen::preheat()
87 {
88 float t = THEPANEL->get_default_hotend_temp();
89 PublicData::set_value( temperature_control_checksum, hotend_checksum, &t );
90 t = THEPANEL->get_default_bed_temp();
91 PublicData::set_value( temperature_control_checksum, bed_checksum, &t );
92 }
93
94 void PrepareScreen::cooldown()
95 {
96 float t = 0;
97 PublicData::set_value( temperature_control_checksum, hotend_checksum, &t );
98 PublicData::set_value( temperature_control_checksum, bed_checksum, &t );
99 }
100
101 // queuing commands needs to be done from main loop
102 void PrepareScreen::on_main_loop()
103 {
104 // change actual axis value
105 if (this->command == nullptr) return;
106 send_command(this->command);
107 this->command = nullptr;
108 }