Add multiple temps to panel watchscreen if there are more than two enabled, top line...
authorJim Morris <morris@wolfman.com>
Sun, 26 Oct 2014 02:13:26 +0000 (19:13 -0700)
committerJim Morris <morris@wolfman.com>
Sun, 26 Oct 2014 02:13:26 +0000 (19:13 -0700)
src/libs/ConfigSources/FileConfigSource.cpp
src/modules/utils/panel/Panel.cpp
src/modules/utils/panel/Panel.h
src/modules/utils/panel/panels/LcdBase.cpp
src/modules/utils/panel/screens/ModifyValuesScreen.h
src/modules/utils/panel/screens/PrepareScreen.cpp
src/modules/utils/panel/screens/WatchScreen.cpp
src/modules/utils/panel/screens/WatchScreen.h

index aa6db2d..0a97efd 100644 (file)
@@ -91,6 +91,8 @@ void FileConfigSource::transfer_values_to_cache( ConfigCache *cache, const char
                     else if(file_exists("/local" + inc_file_name)) inc_file_name = "/local" + inc_file_name;
                 }
                 if(file_exists(inc_file_name)) {
+                    printf("Including config file: %s\n", inc_file_name.c_str());
+
                     // save position in current config file
                     fpos_t pos;
                     fgetpos(lp, &pos);
@@ -102,6 +104,8 @@ void FileConfigSource::transfer_values_to_cache( ConfigCache *cache, const char
                     // reopen the current config file and restore position
                     freopen(file_name, "r", lp);
                     fsetpos(lp, &pos);
+                }else{
+                    printf("Unable to find included config file: %s\n", inc_file_name.c_str());
                 }
             }
         }else break;
index 1433f94..12aa7fb 100644 (file)
@@ -631,6 +631,7 @@ void Panel::setup_temperature_screen()
         bool ok = PublicData::get_value( temperature_control_checksum, i, current_temperature_checksum, &returned_data );
         if (!ok) continue;
 
+        this->temperature_modules.push_back(i);
         struct pad_temperature t =  *static_cast<struct pad_temperature *>(returned_data);
 
         // rename if two of the known types
index 3ea8bdb..b46ffc2 100644 (file)
@@ -21,6 +21,7 @@ using std::string;
 
 class LcdBase;
 class PanelScreen;
+class ModifyValuesScreen;
 class SDCard;
 class SDFAT;
 
@@ -86,6 +87,7 @@ class Panel : public Module {
         LcdBase* lcd;
         PanelScreen* custom_screen;
         PanelScreen* temperature_screen;
+        vector<uint16_t> temperature_modules;
 
         // as panelscreen accesses private fields in Panel
         friend class PanelScreen;
index dd2d2c7..9d77140 100644 (file)
@@ -13,5 +13,5 @@ int LcdBase::printf(const char* format, ...){
     int n= vsnprintf(buffer, sizeof(buffer), format, args);
     va_end(args);
     this->write(buffer, n);
-    return 0;
+    return n;
 }
index dbddc23..2c6c69c 100644 (file)
@@ -33,7 +33,6 @@ public:
     typedef std::tuple<char *, std::function<float()>, std::function<void(float)>, float, float, float, bool> MenuItemType;
     void addMenuItem(const char *name, std::function<float()> getter, std::function<void(float)> setter, float inc= 1.0F, float min= NAN, float max= NAN, bool instant= false);
 
-
 private:
     void addMenuItem(const MenuItemType& item);
 
index d30ba19..3208930 100644 (file)
@@ -17,7 +17,7 @@
 #include "PublicDataRequest.h"
 #include "PublicData.h"
 #include "TemperatureControlPublicAccess.h"
-
+#include "ModifyValuesScreen.h"
 #include <string>
 using namespace std;
 
index 6d134ee..20f897e 100644 (file)
@@ -22,7 +22,6 @@
 #include "SwitchPublicAccess.h"
 #include "checksumm.h"
 #include "Pauser.h"
-
 #include <math.h>
 #include <string.h>
 #include <string>
@@ -58,6 +57,7 @@ WatchScreen::WatchScreen()
     speed_changed = false;
     issue_change_speed = false;
     ipstr = nullptr;
+    update_counts= 0;
 }
 
 WatchScreen::~WatchScreen()
@@ -69,7 +69,7 @@ void WatchScreen::on_enter()
 {
     THEPANEL->lcd->clear();
     THEPANEL->setup_menu(4);
-    get_temp_data();
+    get_current_status();
     get_current_pos(this->pos);
     get_sd_play_info();
     this->current_speed = lround(get_current_speed());
@@ -102,12 +102,11 @@ void WatchScreen::on_refresh()
     }
 
     // Update Only every 20 refreshes, 1 a second
-    static int update_counts = 0;
     update_counts++;
     if ( update_counts % 20 == 0 ) {
         get_sd_play_info();
         get_current_pos(this->pos);
-        get_temp_data();
+        get_current_status();
         if (this->speed_changed) {
             this->issue_change_speed = true; // trigger actual command to change speed
             this->speed_changed = false;
@@ -121,11 +120,22 @@ void WatchScreen::on_refresh()
         this->refresh_screen(THEPANEL->lcd->hasGraphics() ? true : false); // graphics screens should be cleared
 
         // for LCDs with leds set them according to heater status
-        // TODO should be enabled and disabled and settable from config
-        THEPANEL->lcd->setLed(LED_BED_ON, this->bedtarget > 0);
-        THEPANEL->lcd->setLed(LED_HOTEND_ON, this->hotendtarget > 0);
+        bool bed_on= false, hotend_on= false, is_hot= false;
+        for(auto m : THEPANEL->temperature_modules) {
+            // query each heater
+            void *p= getTemperatures(m);
+            struct pad_temperature *temp= static_cast<struct pad_temperature *>(p);
+            if(temp != nullptr) {
+                if(temp->designator.front() == 'B' && temp->target_temperature > 0) bed_on= true;   // bed on/off
+                if(temp->designator.front() == 'T' && temp->target_temperature > 0) hotend_on= true;// hotend on/off (anyone)
+                if(temp->current_temperature > 50) is_hot= true; // anything is hot
+            }
+        }
+        THEPANEL->lcd->setLed(LED_BED_ON, bed_on);
+        THEPANEL->lcd->setLed(LED_HOTEND_ON, hotend_on);
+        THEPANEL->lcd->setLed(LED_HOT, is_hot);
+
         THEPANEL->lcd->setLed(LED_FAN_ON, this->fan_state);
-        THEPANEL->lcd->setLed(LED_HOT, this->hotendtemp > 50 || this->bedtemp > 40);
 
         if (THEPANEL->lcd->hasGraphics()) {
             // display the graphical icons below the status are
@@ -133,10 +143,10 @@ void WatchScreen::on_refresh()
             // for (int i = 0; i < 5; ++i) {
             //     THEPANEL->lcd->bltGlyph(i*24, 38, 23, 19, icons, 15, i*24, 0);
             // }
-            if (this->hotendtarget > 0)
+            if (hotend_on)
                 THEPANEL->lcd->bltGlyph(8, 38, 20, 19, icons, 15, 0, 0);
 
-            if (this->bedtarget > 0)
+            if (bed_on)
                 THEPANEL->lcd->bltGlyph(32, 38, 23, 19, icons, 15, 64, 0);
 
             if(this->fan_state)
@@ -154,38 +164,23 @@ void WatchScreen::on_main_loop()
     }
 }
 
-// fetch the data we are displaying
-void WatchScreen::get_temp_data()
+void *WatchScreen::getTemperatures(uint16_t heater_cs)
 {
     void *returned_data;
-    bool ok;
+    bool ok = PublicData::get_value( temperature_control_checksum, heater_cs, current_temperature_checksum, &returned_data );
 
-    ok = PublicData::get_value( temperature_control_checksum, bed_checksum, current_temperature_checksum, &returned_data );
     if (ok) {
-        struct pad_temperature temp =  *static_cast<struct pad_temperature *>(returned_data);
-        this->bedtemp = round(temp.current_temperature);
-        if (this->bedtemp > 100000) this->bedtemp = -2;
-        this->bedtarget = round(temp.target_temperature);
-        //this->bedpwm= temp.pwm;
-    } else {
-        // temp probably disabled
-        this->bedtemp = -1;
-        this->bedtarget = -1;
+        return returned_data;
     }
 
+    return nullptr;
+}
 
-    ok = PublicData::get_value( temperature_control_checksum, hotend_checksum, current_temperature_checksum, &returned_data );
-    if (ok) {
-        struct pad_temperature temp =  *static_cast<struct pad_temperature *>(returned_data);
-        this->hotendtemp = round(temp.current_temperature);
-        if (this->hotendtemp > 100000) this->hotendtemp = -2;
-        this->hotendtarget = round(temp.target_temperature);
-        //this->hotendpwm= temp.pwm;
-    } else {
-        // temp probably disabled
-        this->hotendtemp = -1;
-        this->hotendtarget = -1;
-    }
+// fetch the data we are displaying
+void WatchScreen::get_current_status()
+{
+    void *returned_data;
+    bool ok;
 
     // get fan status
     ok = PublicData::get_value( switch_checksum, fan_checksum, 0, &returned_data );
@@ -245,9 +240,27 @@ void WatchScreen::display_menu_line(uint16_t line)
     // in menu mode
     switch ( line ) {
         case 0:
-            if(THEPANEL->temperature_screen != nullptr) {
+            if(THEPANEL->temperature_modules.size() > 0) {
                 // only if we detected heaters in config
-                THEPANEL->lcd->printf("H%03d/%03dc B%03d/%03dc", this->hotendtemp, this->hotendtarget, this->bedtemp, this->bedtarget);
+                auto tm= THEPANEL->temperature_modules;
+                int n= 0;
+                if(tm.size() > 2) {
+                    // more than two temps we need to cycle between them
+                    n= update_counts/100; // increments every 5 seconds
+                    int ntemps= (tm.size()+1)/2;
+                    n= n%ntemps; // which of the pairs of temps to display
+                }
+
+                int off= 0;
+                for (size_t i = 0; i < 2; ++i) {
+                    size_t o= i+(n*2);
+                    if(o>tm.size()-1) break;
+                    struct pad_temperature *temp= static_cast<struct pad_temperature *>(getTemperatures(tm[o]));
+                    if(temp == nullptr) continue;
+                    THEPANEL->lcd->setCursor(off, 0); // col, row
+                    off += THEPANEL->lcd->printf("%s:%03d/%03d ", temp->designator.substr(0, 2).c_str(), (int)roundf(temp->current_temperature), (int)roundf(temp->target_temperature));
+                }
+
             }else{
                 //THEPANEL->lcd->printf("No Heaters");
             }
index cde2464..bf723ca 100644 (file)
@@ -10,6 +10,8 @@
 
 #include "PanelScreen.h"
 
+#include <tuple>
+
 class WatchScreen : public PanelScreen
 {
 public:
@@ -21,27 +23,27 @@ public:
     void display_menu_line(uint16_t line);
 
 private:
-    void get_temp_data();
+    void get_current_status();
     float get_current_speed();
     void set_speed();
     void get_current_pos(float *cp);
     void get_sd_play_info();
     const char *get_status();
     const char *get_network();
+    void *getTemperatures(uint16_t heater_cs);
 
-    bool speed_changed;
-    bool issue_change_speed;
-    bool fan_state;
-    int hotendtemp;
-    int hotendtarget;
-    int bedtemp;
-    int bedtarget;
+    uint32_t update_counts;
     int current_speed;
     float pos[3];
     unsigned long elapsed_time;
     unsigned int sd_pcnt_played;
-
     char *ipstr;
+
+    struct {
+        bool speed_changed:1;
+        bool issue_change_speed:1;
+        bool fan_state:1;
+    };
 };
 
 #endif