Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / ProbeScreen.cpp
CommitLineData
c51bd067
JM
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 "ProbeScreen.h"
9#include "libs/Kernel.h"
10#include "libs/SerialMessage.h"
11#include "Panel.h"
12#include "PanelScreen.h"
13#include "LcdBase.h"
14#include "libs/nuts_bolts.h"
15#include "libs/utils.h"
16#include "StringStream.h"
17#include "Gcode.h"
18
19#include <string>
20
21using namespace std;
22
23ProbeScreen::ProbeScreen()
24{
25 this->do_probe= false;
26 this->do_status= false;
27 this->new_result= false;
28}
29
30void ProbeScreen::on_exit()
31{
f99c7716
JM
32 this->do_probe= false;
33 this->do_status= false;
34 this->new_result= false;
c51bd067
JM
35 delete this;
36}
37
38void ProbeScreen::on_enter()
39{
40 THEPANEL->enter_menu_mode();
41 THEPANEL->setup_menu(3);
42 this->refresh_menu();
43}
44
45void ProbeScreen::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 if(this->new_result) {
54 this->new_result= false;
55 THEPANEL->lcd->setCursor(0, 3);
f99c7716 56 THEPANEL->lcd->printf("%20s", this->result.substr(0, 20).c_str());
f4780d4e 57 if(this->result.size() > 20 && THEPANEL->get_screen_lines() > 4) {
c51bd067 58 THEPANEL->lcd->setCursor(0, 4);
f99c7716 59 THEPANEL->lcd->printf("%20s", this->result.substr(20, 20).c_str());
c51bd067 60 }
6c3ab9b0
JM
61 if(this->result.size() > 40 && THEPANEL->get_screen_lines() > 5) {
62 THEPANEL->lcd->setCursor(0, 5);
63 THEPANEL->lcd->printf("%20s", this->result.substr(40, 20).c_str());
64 }
c51bd067
JM
65 }
66}
67
68void ProbeScreen::display_menu_line(uint16_t line)
69{
70 switch ( line ) {
71 case 0: THEPANEL->lcd->printf("Back"); break;
72 case 1: THEPANEL->lcd->printf("Status"); break;
73 case 2: THEPANEL->lcd->printf("Z Probe"); break;
74 }
75}
76
77void ProbeScreen::clicked_menu_entry(uint16_t line)
78{
f99c7716 79 this->do_status= false;
c51bd067
JM
80 switch ( line ) {
81 case 0: THEPANEL->enter_screen(this->parent); return;
f99c7716 82 case 1: this->do_status= true; this->tcnt= 1; break;
c51bd067
JM
83 case 2: this->do_probe= true; break;
84 }
85}
86
87// queuing commands needs to be done from main loop
88void ProbeScreen::on_main_loop()
89{
90 if (this->do_probe) {
91 this->do_probe= false;
92 StringStream string_stream;
93 Gcode gcode("G30", &string_stream);
94 THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode);
95 this->result= string_stream.getOutput();
96 this->new_result= true;
97
f99c7716
JM
98 }else if (this->do_status && --this->tcnt == 0) {
99 // this will refresh the results every 10 main loop iterations
100 this->tcnt= 10; // update every 10 times
c51bd067
JM
101 StringStream string_stream;
102 Gcode gcode("M119", &string_stream);
103 THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode);
104 this->result= string_stream.getOutput();
105 this->new_result= true;
106 }
107}