Enumerate hotends for display in panel temperature settings
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / ModifyValuesScreen.cpp
index 11aa3b7..2d48504 100644 (file)
@@ -27,44 +27,52 @@ ModifyValuesScreen::ModifyValuesScreen()
     control_mode = MENU_CONTROL_MODE;
 }
 
+ModifyValuesScreen::~ModifyValuesScreen()
+{
+    // free up the strdup() name
+    for(auto i : menu_items) {
+        free(std::get<0>(i));
+    }
+}
+
 void ModifyValuesScreen::on_enter()
 {
-    this->panel->enter_menu_mode();
-    this->panel->setup_menu(menu_items.size() + 1);
+    THEPANEL->enter_menu_mode();
+    THEPANEL->setup_menu(menu_items.size() + 1);
     this->refresh_menu();
 }
 
 void ModifyValuesScreen::on_refresh()
 {
-    if ( this->panel->menu_change() ) {
+    if ( THEPANEL->menu_change() ) {
         this->refresh_menu();
     }
 
     if (this->control_mode == VALUE_CONTROL_MODE) {
 
-        if ( this->panel->click() ) {
+        if ( THEPANEL->click() ) {
             // done changing value
             execute_function= selected_item; // this causes on_main_loop to change the value
             this->control_mode = MENU_CONTROL_MODE;
-            this->panel->enter_menu_mode(true);
+            THEPANEL->enter_menu_mode(true);
 
-        } else if (this->panel->control_value_change()) {
-            this->new_value = this->panel->get_control_value();
+        } else if (THEPANEL->control_value_change()) {
+            this->new_value = THEPANEL->get_control_value();
             if(!isnan(this->min_value) && this->new_value < this->min_value) {
-                this->panel->set_control_value((this->new_value = this->min_value));
-                this->panel->reset_counter();
+                THEPANEL->set_control_value((this->new_value = this->min_value));
+                THEPANEL->reset_counter();
             }
             if(!isnan(this->max_value) && this->new_value > this->max_value) {
-                this->panel->set_control_value((this->new_value = this->max_value));
-                this->panel->reset_counter();
+                THEPANEL->set_control_value((this->new_value = this->max_value));
+                THEPANEL->reset_counter();
             }
-            this->panel->lcd->setCursor(0, 2);
-            this->panel->lcd->printf("%10.3f    ", this->new_value);
+            THEPANEL->lcd->setCursor(0, 2);
+            THEPANEL->lcd->printf("%10.3f    ", this->new_value);
         }
 
     } else {
-        if ( this->panel->click() ) {
-            this->clicked_menu_entry(this->panel->get_menu_current_line());
+        if ( THEPANEL->click() ) {
+            this->clicked_menu_entry(THEPANEL->get_menu_current_line());
         }
     }
 }
@@ -72,19 +80,19 @@ void ModifyValuesScreen::on_refresh()
 void ModifyValuesScreen::display_menu_line(uint16_t line)
 {
     if (line == 0) {
-        this->panel->lcd->printf("Back");
+        THEPANEL->lcd->printf("Back");
     } else {
         line--;
         const char *name = std::get<0>(menu_items[line]);
         float value = std::get<1>(menu_items[line])();
-        this->panel->lcd->printf("%-12s %8.3f", name, value);
+        THEPANEL->lcd->printf("%-12s %8.3f", name, value);
     }
 }
 
 void ModifyValuesScreen::clicked_menu_entry(uint16_t line)
 {
     if (line == 0) {
-        this->panel->enter_screen(this->parent);
+        THEPANEL->enter_screen(this->parent);
 
     } else {
         line--;
@@ -94,16 +102,16 @@ void ModifyValuesScreen::clicked_menu_entry(uint16_t line)
         const char *name = std::get<0>(menu_items[line]);
         float value = std::get<1>(menu_items[line])();
         float inc= std::get<3>(menu_items[line]);
-        this->panel->enter_control_mode(inc, inc / 10);
+        THEPANEL->enter_control_mode(inc, inc / 10);
         this->min_value= std::get<4>(menu_items[line]);
         this->max_value= std::get<5>(menu_items[line]);
 
-        this->panel->set_control_value(value);
-        this->panel->lcd->clear();
-        this->panel->lcd->setCursor(0, 0);
-        this->panel->lcd->printf("%s", name);
-        this->panel->lcd->setCursor(0, 2);
-        this->panel->lcd->printf("%10.3f", value);
+        THEPANEL->set_control_value(value);
+        THEPANEL->lcd->clear();
+        THEPANEL->lcd->setCursor(0, 0);
+        THEPANEL->lcd->printf("%s", name);
+        THEPANEL->lcd->setCursor(0, 2);
+        THEPANEL->lcd->printf("%10.3f", value);
     }
 }
 
@@ -118,12 +126,7 @@ void ModifyValuesScreen::on_main_loop()
     execute_function = -1;
 }
 
-void ModifyValuesScreen::addMenuItem(const MenuItemType& item)
-{
-    menu_items.push_back(item);
-}
-
 void ModifyValuesScreen::addMenuItem(const char *name, std::function<float()> getter, std::function<void(float)> setter, float inc, float  min, float max)
 {
-    menu_items.push_back(make_tuple(name, getter, setter, inc, min, max));
+    menu_items.push_back(make_tuple(strdup(name), getter, setter, inc, min, max));
 }