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 "libs/SerialMessage.h" | |
10 | #include "Panel.h" | |
11 | #include "PanelScreen.h" | |
12 | #include "MainMenuScreen.h" | |
13 | #include "ControlScreen.h" | |
14 | #include "libs/nuts_bolts.h" | |
15 | #include "libs/utils.h" | |
16 | #include <string> | |
564cf1f0 | 17 | #include "Robot.h" |
61134a65 JM |
18 | #include "PublicData.h" |
19 | #include "checksumm.h" | |
383c9c1c | 20 | #include "LcdBase.h" |
61134a65 JM |
21 | |
22 | #include <math.h> | |
383c9c1c | 23 | #include <stdio.h> |
61134a65 | 24 | |
35089dc7 JM |
25 | using namespace std; |
26 | ||
2fa50ca0 JM |
27 | #define NULL_CONTROL_MODE 0 |
28 | #define AXIS_CONTROL_MODE 1 | |
29 | #define INCREMENT_SELECTION_MODE 2 | |
30 | ||
862fc625 JM |
31 | ControlScreen::ControlScreen() |
32 | { | |
35089dc7 JM |
33 | this->control_mode = NULL_CONTROL_MODE; |
34 | } | |
35 | ||
862fc625 JM |
36 | void ControlScreen::on_enter() |
37 | { | |
cee1bb2d JM |
38 | THEPANEL->enter_menu_mode(); |
39 | THEPANEL->setup_menu(4); | |
58d6d841 JM |
40 | get_current_pos(this->pos); |
41 | this->refresh_menu(); | |
862fc625 | 42 | this->pos_changed = false; |
35089dc7 JM |
43 | } |
44 | ||
45 | // called in on_idle() | |
862fc625 JM |
46 | void ControlScreen::on_refresh() |
47 | { | |
cee1bb2d | 48 | if ( THEPANEL->menu_change() ) { |
35089dc7 | 49 | this->refresh_menu(); |
58d6d841 JM |
50 | } |
51 | ||
862fc625 | 52 | if (this->control_mode == AXIS_CONTROL_MODE) { |
446deda2 | 53 | |
cee1bb2d | 54 | if ( THEPANEL->click() ) { |
58d6d841 JM |
55 | this->enter_menu_control(); |
56 | this->refresh_menu(); | |
446deda2 | 57 | |
cee1bb2d JM |
58 | } else if (THEPANEL->control_value_change()) { |
59 | this->pos[this->controlled_axis - 'X'] = THEPANEL->get_control_value(); | |
60 | THEPANEL->lcd->setCursor(0, 2); | |
58d6d841 | 61 | this->display_axis_line(this->controlled_axis); |
862fc625 | 62 | this->pos_changed = true; // make the gcode in main_loop |
58d6d841 | 63 | } |
446deda2 | 64 | |
862fc625 | 65 | } else { |
cee1bb2d JM |
66 | if ( THEPANEL->click() ) { |
67 | this->clicked_menu_entry(THEPANEL->get_menu_current_line()); | |
58d6d841 JM |
68 | } |
69 | } | |
35089dc7 JM |
70 | } |
71 | ||
72 | // queuing gcodes needs to be done from main loop | |
862fc625 JM |
73 | void ControlScreen::on_main_loop() |
74 | { | |
58d6d841 | 75 | // change actual axis value |
862fc625 JM |
76 | if (!this->pos_changed) return; |
77 | this->pos_changed = false; | |
446deda2 | 78 | |
862fc625 | 79 | set_current_pos(this->controlled_axis, this->pos[this->controlled_axis - 'X']); |
35089dc7 JM |
80 | } |
81 | ||
862fc625 JM |
82 | void ControlScreen::display_menu_line(uint16_t line) |
83 | { | |
58d6d841 | 84 | // in menu mode |
862fc625 | 85 | switch ( line ) { |
cee1bb2d | 86 | case 0: THEPANEL->lcd->printf("Back"); break; |
446deda2 JM |
87 | case 1: this->display_axis_line('X'); break; |
88 | case 2: this->display_axis_line('Y'); break; | |
89 | case 3: this->display_axis_line('Z'); break; | |
35089dc7 JM |
90 | } |
91 | } | |
92 | ||
862fc625 JM |
93 | void ControlScreen::display_axis_line(char axis) |
94 | { | |
cee1bb2d | 95 | THEPANEL->lcd->printf("Move %c %8.3f", axis, this->pos[axis - 'X']); |
35089dc7 JM |
96 | } |
97 | ||
98 | ||
862fc625 JM |
99 | void ControlScreen::clicked_menu_entry(uint16_t line) |
100 | { | |
101 | switch ( line ) { | |
cee1bb2d | 102 | case 0: THEPANEL->enter_screen(this->parent ); break; |
35089dc7 JM |
103 | case 1: this->enter_axis_control('X'); break; |
104 | case 2: this->enter_axis_control('Y'); break; | |
105 | case 3: this->enter_axis_control('Z'); break; | |
106 | } | |
107 | } | |
108 | ||
862fc625 JM |
109 | void ControlScreen::enter_axis_control(char axis) |
110 | { | |
35089dc7 JM |
111 | this->control_mode = AXIS_CONTROL_MODE; |
112 | this->controlled_axis = axis; | |
cee1bb2d JM |
113 | THEPANEL->enter_control_mode(this->jog_increment, this->jog_increment / 10); |
114 | THEPANEL->set_control_value(this->pos[axis - 'X']); | |
115 | THEPANEL->lcd->clear(); | |
116 | THEPANEL->lcd->setCursor(0, 2); | |
446deda2 | 117 | this->display_axis_line(this->controlled_axis); |
35089dc7 JM |
118 | } |
119 | ||
862fc625 JM |
120 | void ControlScreen::enter_menu_control() |
121 | { | |
58d6d841 | 122 | this->control_mode = NULL_CONTROL_MODE; |
cee1bb2d | 123 | THEPANEL->enter_menu_mode(); |
35089dc7 JM |
124 | } |
125 | ||
1ad23cd3 | 126 | void ControlScreen::get_current_pos(float *cp) |
862fc625 | 127 | { |
564cf1f0 | 128 | THEKERNEL->robot->get_axis_position(cp); |
35089dc7 | 129 | } |
82d1ceb3 | 130 | |
1ad23cd3 | 131 | void ControlScreen::set_current_pos(char axis, float p) |
862fc625 | 132 | { |
58d6d841 JM |
133 | // change pos by issuing a G0 Xnnn |
134 | char buf[32]; | |
cee1bb2d | 135 | int n = snprintf(buf, sizeof(buf), "G0 %c%f F%d", axis, p, (int)round(THEPANEL->get_jogging_speed(axis))); |
58d6d841 JM |
136 | string g(buf, n); |
137 | send_gcode(g); | |
35089dc7 | 138 | } |