Commit | Line | Data |
---|---|---|
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 | 14 | #include "Gcode.h" |
7af0714f | 15 | #include "LcdBase.h" |
fc7b9a7b | 16 | #include "libs/StreamOutput.h" |
61134a65 | 17 | |
35089dc7 JM |
18 | using namespace std; |
19 | ||
1aa0cc67 | 20 | // static as it is shared by all screens |
58850714 | 21 | std::deque<std::string> PanelScreen::command_queue; |
1aa0cc67 | 22 | |
862fc625 | 23 | PanelScreen::PanelScreen() {} |
dedae247 | 24 | PanelScreen::~PanelScreen() {} |
35089dc7 | 25 | |
862fc625 | 26 | void PanelScreen::on_refresh() {} |
35089dc7 | 27 | |
862fc625 | 28 | void PanelScreen::on_enter() {} |
35089dc7 | 29 | |
862fc625 JM |
30 | void PanelScreen::refresh_menu(bool clear) |
31 | { | |
cee1bb2d JM |
32 | if (clear) THEPANEL->lcd->clear(); |
33 | for (uint16_t i = THEPANEL->menu_start_line; i < THEPANEL->menu_start_line + min( THEPANEL->menu_rows, THEPANEL->panel_lines ); i++ ) { | |
34 | THEPANEL->lcd->setCursor(2, i - THEPANEL->menu_start_line ); | |
35089dc7 JM |
35 | this->display_menu_line(i); |
36 | } | |
cee1bb2d JM |
37 | THEPANEL->lcd->setCursor(0, THEPANEL->menu_current_line - THEPANEL->menu_start_line ); |
38 | THEPANEL->lcd->printf(">"); | |
35089dc7 JM |
39 | } |
40 | ||
862fc625 JM |
41 | void PanelScreen::refresh_screen(bool clear) |
42 | { | |
cee1bb2d JM |
43 | if (clear) THEPANEL->lcd->clear(); |
44 | for (uint16_t i = THEPANEL->menu_start_line; i < THEPANEL->menu_start_line + min( THEPANEL->menu_rows, THEPANEL->panel_lines ); i++ ) { | |
45 | THEPANEL->lcd->setCursor(0, i - THEPANEL->menu_start_line ); | |
58d6d841 JM |
46 | this->display_menu_line(i); |
47 | } | |
35089dc7 JM |
48 | } |
49 | ||
862fc625 JM |
50 | PanelScreen *PanelScreen::set_parent(PanelScreen *passed_parent) |
51 | { | |
35089dc7 | 52 | this->parent = passed_parent; |
35089dc7 JM |
53 | return this; |
54 | } | |
55 | ||
82d1ceb3 | 56 | // Helper for screens to send a gcode, must be called from main loop |
862fc625 JM |
57 | void PanelScreen::send_gcode(std::string g) |
58 | { | |
dcf86322 JM |
59 | Gcode gcode(g, &(StreamOutput::NullStream)); |
60 | THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode ); | |
61 | } | |
82d1ceb3 | 62 | |
2fa50ca0 JM |
63 | void PanelScreen::send_gcode(const char *gm_code, char parameter, float value) |
64 | { | |
65 | char buf[132]; | |
66 | int n = snprintf(buf, sizeof(buf), "%s %c%f", gm_code, parameter, value); | |
67 | string g(buf, n); | |
68 | send_gcode(g); | |
2fa50ca0 JM |
69 | } |
70 | ||
f153eec7 JM |
71 | // Helper to send commands, may be called from on_idle will delegate all commands to on_main_loop |
72 | // may contain multiple commands separated by \n | |
862fc625 JM |
73 | void PanelScreen::send_command(const char *gcstr) |
74 | { | |
82d1ceb3 | 75 | string cmd(gcstr); |
862fc625 | 76 | while (cmd.size() > 0) { |
82d1ceb3 | 77 | size_t b = cmd.find_first_of("\n"); |
862fc625 | 78 | if ( b == string::npos ) { |
f153eec7 | 79 | command_queue.push_back(cmd); |
82d1ceb3 JM |
80 | break; |
81 | } | |
f153eec7 | 82 | command_queue.push_back(cmd.substr( 0, b )); |
862fc625 | 83 | cmd = cmd.substr(b + 1); |
82d1ceb3 | 84 | } |
f153eec7 | 85 | } |
82d1ceb3 | 86 | |
f153eec7 JM |
87 | void PanelScreen::on_main_loop() |
88 | { | |
89 | // for each command in queue send it | |
58850714 | 90 | while(command_queue.size() > 0) { |
82d1ceb3 | 91 | struct SerialMessage message; |
58850714 | 92 | message.message = command_queue.front(); |
215e7f90 | 93 | command_queue.pop_front(); |
82d1ceb3 JM |
94 | message.stream = &(StreamOutput::NullStream); |
95 | THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message ); | |
96 | } | |
97 | } |