add on_exit to panelscreen
[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
21 #include <string>
22 using namespace std;
23
24 PrepareScreen::PrepareScreen()
25 {
26 this->command = nullptr;
27
28 // Children screens
29 this->extruder_screen = (new ExtruderScreen() )->set_parent(this);
30 THEPANEL->temperature_screen->set_parent(this);
31 }
32
33 void PrepareScreen::on_enter()
34 {
35 THEPANEL->enter_menu_mode();
36 THEPANEL->setup_menu(9);
37 this->refresh_menu();
38 }
39
40 void PrepareScreen::on_refresh()
41 {
42 if ( THEPANEL->menu_change() ) {
43 this->refresh_menu();
44 }
45 if ( THEPANEL->click() ) {
46 this->clicked_menu_entry(THEPANEL->get_menu_current_line());
47 }
48 }
49
50 void PrepareScreen::display_menu_line(uint16_t line)
51 {
52 switch ( line ) {
53 case 0: THEPANEL->lcd->printf("Back" ); break;
54 case 1: THEPANEL->lcd->printf("Home All Axis" ); break;
55 case 2: THEPANEL->lcd->printf("Set Home" ); break;
56 case 3: THEPANEL->lcd->printf("Set Z0" ); break;
57 case 4: THEPANEL->lcd->printf("Pre Heat" ); break;
58 case 5: THEPANEL->lcd->printf("Cool Down" ); break;
59 case 6: THEPANEL->lcd->printf("Extruder..." ); break;
60 case 7: THEPANEL->lcd->printf("Motors off" ); break;
61 case 8: THEPANEL->lcd->printf("Set Temperature"); break;
62 }
63 }
64
65 void PrepareScreen::clicked_menu_entry(uint16_t line)
66 {
67 switch ( line ) {
68 case 0: THEPANEL->enter_screen(this->parent); break;
69 case 1: command = "G28"; break;
70 case 2: command = "G92 X0 Y0 Z0"; break;
71 case 3: command = "G92 Z0"; break;
72 case 4: this->preheat(); break;
73 case 5: this->cooldown(); break;
74 case 6: THEPANEL->enter_screen(this->extruder_screen); break;
75 case 7: command = "M84"; break;
76 case 8: THEPANEL->enter_screen(THEPANEL->temperature_screen); break;
77 }
78 }
79
80 void PrepareScreen::preheat()
81 {
82 float t = THEPANEL->get_default_hotend_temp();
83 PublicData::set_value( temperature_control_checksum, hotend_checksum, &t );
84 t = THEPANEL->get_default_bed_temp();
85 PublicData::set_value( temperature_control_checksum, bed_checksum, &t );
86 }
87
88 void PrepareScreen::cooldown()
89 {
90 float t = 0;
91 PublicData::set_value( temperature_control_checksum, hotend_checksum, &t );
92 PublicData::set_value( temperature_control_checksum, bed_checksum, &t );
93 }
94
95 // queuing commands needs to be done from main loop
96 void PrepareScreen::on_main_loop()
97 {
98 // change actual axis value
99 if (this->command == nullptr) return;
100 send_command(this->command);
101 this->command = nullptr;
102 }