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/>.
7 #include "ModifyValuesScreen.h"
8 #include "libs/Kernel.h"
10 #include "checksumm.h"
13 #include "ConfigValue.h"
21 #define MENU_CONTROL_MODE 0
22 #define VALUE_CONTROL_MODE 1
24 ModifyValuesScreen::ModifyValuesScreen()
26 execute_function
= -1;
27 control_mode
= MENU_CONTROL_MODE
;
30 ModifyValuesScreen::~ModifyValuesScreen()
32 // free up the strdup() name
33 for(auto i
: menu_items
) {
38 void ModifyValuesScreen::on_enter()
40 THEPANEL
->enter_menu_mode();
41 THEPANEL
->setup_menu(menu_items
.size() + 1);
45 void ModifyValuesScreen::on_refresh()
47 if ( THEPANEL
->menu_change() ) {
51 if (this->control_mode
== VALUE_CONTROL_MODE
) {
53 if ( THEPANEL
->click() ) {
54 // done changing value
55 execute_function
= selected_item
; // this causes on_main_loop to change the value
56 this->control_mode
= MENU_CONTROL_MODE
;
57 THEPANEL
->enter_menu_mode(true);
59 } else if (THEPANEL
->control_value_change()) {
60 this->new_value
= THEPANEL
->get_control_value();
61 if(!isnan(this->min_value
) && this->new_value
< this->min_value
) {
62 THEPANEL
->set_control_value((this->new_value
= this->min_value
));
63 THEPANEL
->reset_counter();
65 if(!isnan(this->max_value
) && this->new_value
> this->max_value
) {
66 THEPANEL
->set_control_value((this->new_value
= this->max_value
));
67 THEPANEL
->reset_counter();
69 THEPANEL
->lcd
->setCursor(0, 2);
70 THEPANEL
->lcd
->printf("%10.3f ", this->new_value
);
74 if ( THEPANEL
->click() ) {
75 this->clicked_menu_entry(THEPANEL
->get_menu_current_line());
80 void ModifyValuesScreen::display_menu_line(uint16_t line
)
83 THEPANEL
->lcd
->printf("Back");
86 const char *name
= std::get
<0>(menu_items
[line
]);
87 float value
= std::get
<1>(menu_items
[line
])();
88 THEPANEL
->lcd
->printf("%-12s %8.3f", name
, value
);
92 void ModifyValuesScreen::clicked_menu_entry(uint16_t line
)
95 THEPANEL
->enter_screen(this->parent
);
99 this->selected_item
= line
;
100 this->control_mode
= VALUE_CONTROL_MODE
;
102 const char *name
= std::get
<0>(menu_items
[line
]);
103 float value
= std::get
<1>(menu_items
[line
])();
104 float inc
= std::get
<3>(menu_items
[line
]);
105 THEPANEL
->enter_control_mode(inc
, inc
/ 10);
106 this->min_value
= std::get
<4>(menu_items
[line
]);
107 this->max_value
= std::get
<5>(menu_items
[line
]);
109 THEPANEL
->set_control_value(value
);
110 THEPANEL
->lcd
->clear();
111 THEPANEL
->lcd
->setCursor(0, 0);
112 THEPANEL
->lcd
->printf("%s", name
);
113 THEPANEL
->lcd
->setCursor(0, 2);
114 THEPANEL
->lcd
->printf("%10.3f", value
);
118 // queuing commands needs to be done from main loop
119 void ModifyValuesScreen::on_main_loop()
122 if (execute_function
== -1) return;
124 // execute the setter function for the specified menu item
125 std::get
<2>(menu_items
[execute_function
])(new_value
);
126 execute_function
= -1;
129 void ModifyValuesScreen::addMenuItem(const char *name
, std::function
<float()> getter
, std::function
<void(float)> setter
, float inc
, float min
, float max
)
131 menu_items
.push_back(make_tuple(strdup(name
), getter
, setter
, inc
, min
, max
));