Merge pull request #353 from wolfmanjm/cleanup/headers
[clinton/Smoothieware.git] / src / modules / utils / panel / PanelScreen.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 "libs/nuts_bolts.h"
12 #include "libs/utils.h"
13 #include "libs/SerialMessage.h"
14 #include "Gcode.h"
15 #include "LcdBase.h"
16
17 #include <string>
18 #include <vector>
19
20 using namespace std;
21
22 PanelScreen::PanelScreen() {}
23
24 void PanelScreen::on_refresh() {}
25 void PanelScreen::on_main_loop() {}
26
27 PanelScreen *PanelScreen::set_panel(Panel *parent)
28 {
29 this->panel = parent;
30 return this;
31 }
32
33 void PanelScreen::on_enter() {}
34
35 void PanelScreen::refresh_menu(bool clear)
36 {
37 if (clear) this->panel->lcd->clear();
38 for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->panel_lines ); i++ ) {
39 this->panel->lcd->setCursor(2, i - this->panel->menu_start_line );
40 this->display_menu_line(i);
41 }
42 this->panel->lcd->setCursor(0, this->panel->menu_current_line - this->panel->menu_start_line );
43 this->panel->lcd->printf(">");
44 }
45
46 void PanelScreen::refresh_screen(bool clear)
47 {
48 if (clear) this->panel->lcd->clear();
49 for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->panel_lines ); i++ ) {
50 this->panel->lcd->setCursor(0, i - this->panel->menu_start_line );
51 this->display_menu_line(i);
52 }
53 }
54
55 PanelScreen *PanelScreen::set_parent(PanelScreen *passed_parent)
56 {
57 this->parent = passed_parent;
58 this->set_panel( passed_parent->panel );
59 return this;
60 }
61
62 // Helper for screens to send a gcode, must be called from main loop
63 void PanelScreen::send_gcode(std::string g)
64 {
65 Gcode gcode(g, &(StreamOutput::NullStream));
66 THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode );
67 }
68
69 // Helper to send commands, must be called from mainloop
70 // may contain multipe commands separated by \n
71 void PanelScreen::send_command(const char *gcstr)
72 {
73 string cmd(gcstr);
74 vector<string> q;
75 while (cmd.size() > 0) {
76 size_t b = cmd.find_first_of("\n");
77 if ( b == string::npos ) {
78 q.push_back(cmd);
79 break;
80 }
81 q.push_back(cmd.substr( 0, b ));
82 cmd = cmd.substr(b + 1);
83 }
84
85 // for each command send it
86 for (std::vector<string>::iterator i = q.begin(); i != q.end(); ++i) {
87 struct SerialMessage message;
88 message.message = *i;
89 message.stream = &(StreamOutput::NullStream);
90 THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
91 }
92 }