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