Merge pull request #255 from wolfmanjm/upstreamedge
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / PrepareScreen.cpp
CommitLineData
446deda2 1/*
35089dc7
JM
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.
446deda2 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
35089dc7
JM
6*/
7
8#include "libs/Kernel.h"
9#include "Panel.h"
10#include "PanelScreen.h"
11#include "PrepareScreen.h"
27102c66 12#include "ExtruderScreen.h"
35089dc7
JM
13#include "libs/nuts_bolts.h"
14#include "libs/utils.h"
35089dc7 15#include "libs/SerialMessage.h"
f19a841a
JM
16#include "PublicDataRequest.h"
17#include "modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h"
18
19#include <string>
35089dc7
JM
20using namespace std;
21
22PrepareScreen::PrepareScreen(){
58d6d841 23 // Children screens
27102c66 24 this->extruder_screen = (new ExtruderScreen() )->set_parent(this);
58d6d841 25// this->temp_screen = (new TempScreen() )->set_parent(this);
35089dc7
JM
26}
27
28void PrepareScreen::on_enter(){
29 this->panel->enter_menu_mode();
f65ce58f 30 this->panel->setup_menu(7); // 7 menu items
35089dc7
JM
31 this->refresh_screen();
32}
33
34void PrepareScreen::on_refresh(){
35 if( this->panel->menu_change() ){
36 this->refresh_screen();
37 }
38 if( this->panel->click() ){
446deda2 39 this->clicked_menu_entry(this->panel->get_menu_current_line());
35089dc7
JM
40 }
41}
42
43void PrepareScreen::refresh_screen(){
44 this->refresh_menu();
45}
46
47void PrepareScreen::display_menu_line(uint16_t line){
48 switch( line ){
446deda2
JM
49 case 0: this->panel->lcd->printf("Back" ); break;
50 case 1: this->panel->lcd->printf("Home All Axis" ); break;
51 case 2: this->panel->lcd->printf("Set Home" ); break;
52 case 3: this->panel->lcd->printf("Pre Heat" ); break;
53 case 4: this->panel->lcd->printf("Cool Down" ); break;
54 case 5: this->panel->lcd->printf("Extrude" ); break;
55 case 6: this->panel->lcd->printf("Motors off" ); break;
56 //case 7: this->panel->lcd->printf("Set Temperature"); break;
35089dc7
JM
57 }
58}
59
60void PrepareScreen::clicked_menu_entry(uint16_t line){
61 switch( line ){
27102c66 62 case 0: this->panel->enter_screen(this->parent); break;
dcf86322
JM
63 case 1: send_command("G28"); break;
64 case 2: send_command("G92 X0 Y0 Z0"); break;
35089dc7
JM
65 case 3: this->preheat(); break;
66 case 4: this->cooldown(); break;
27102c66 67 case 5: this->panel->enter_screen(this->extruder_screen); break;
dcf86322 68 case 6: send_command("M84"); break;
f65ce58f 69 //case 7: this->panel->enter_screen(this->temp_screen ); break;
35089dc7
JM
70 }
71
35089dc7
JM
72}
73
35089dc7 74void PrepareScreen::preheat() {
f19a841a
JM
75 double t= panel->get_default_hotend_temp();
76 THEKERNEL->public_data->set_value( temperature_control_checksum, hotend_checksum, &t );
77 t= panel->get_default_bed_temp();
78 THEKERNEL->public_data->set_value( temperature_control_checksum, bed_checksum, &t );
35089dc7
JM
79}
80
81void PrepareScreen::cooldown() {
f19a841a
JM
82 double t= 0;
83 THEKERNEL->public_data->set_value( temperature_control_checksum, hotend_checksum, &t );
84 THEKERNEL->public_data->set_value( temperature_control_checksum, bed_checksum, &t );
35089dc7
JM
85}
86
dcf86322
JM
87void PrepareScreen::send_command(const char* gcstr) {
88 string cmd(gcstr);
58d6d841 89 struct SerialMessage message;
dcf86322 90 message.message = cmd;
58d6d841
JM
91 message.stream = &(StreamOutput::NullStream);
92 THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
35089dc7 93}