add viki2 and miniviki2 panels
authorJim Morris <morris@wolfman.com>
Fri, 26 Sep 2014 21:30:53 +0000 (14:30 -0700)
committerJim Morris <morris@wolfman.com>
Fri, 26 Sep 2014 21:30:53 +0000 (14:30 -0700)
allow configure menu items to be set as the encoder turns (be careful with use)
add set lcd contrast to Configure menu (needs to be set permanently in config)

src/modules/utils/panel/Panel.cpp
src/modules/utils/panel/panels/LcdBase.h
src/modules/utils/panel/panels/ST7565.cpp
src/modules/utils/panel/panels/ST7565.h
src/modules/utils/panel/screens/MainMenuScreen.cpp
src/modules/utils/panel/screens/ModifyValuesScreen.cpp
src/modules/utils/panel/screens/ModifyValuesScreen.h

index 1c3cd2c..c5bcb60 100644 (file)
@@ -38,6 +38,8 @@
 #define lcd_checksum               CHECKSUM("lcd")
 #define rrd_glcd_checksum          CHECKSUM("reprap_discount_glcd")
 #define st7565_glcd_checksum       CHECKSUM("st7565_glcd")
+#define viki2_checksum             CHECKSUM("viki2")
+#define mini_viki2_checksum        CHECKSUM("mini_viki2")
 #define universal_adapter_checksum CHECKSUM("universal_adapter")
 
 #define menu_offset_checksum        CHECKSUM("menu_offset")
@@ -90,6 +92,12 @@ void Panel::on_module_loaded()
         this->lcd = new ReprapDiscountGLCD();
     } else if (lcd_cksm == st7565_glcd_checksum) {
         this->lcd = new ST7565();
+    } else if (lcd_cksm == viki2_checksum) {
+        this->lcd = new ST7565();
+        this->lcd->set_variant(1);
+    } else if (lcd_cksm == mini_viki2_checksum) {
+        this->lcd = new ST7565();
+        this->lcd->set_variant(2);
     } else if (lcd_cksm == universal_adapter_checksum) {
         this->lcd = new UniversalAdapter();
     } else {
index e54142d..8f01a76 100644 (file)
@@ -53,6 +53,8 @@ class LcdBase {
         virtual void buzz(long,uint16_t){};
         virtual bool hasGraphics() { return false; }
         virtual bool encoderReturnsDelta() { return false; } // set to true if the panel handles encoder clicks and returns a delta
+        virtual uint8_t getContrast() { return 0; }
+        virtual void setContrast(uint8_t c) { }
 
         // on graphics panels, the input bitmap is in X windows XBM format but
         // with the bits in a byte reversed so bit7 is left most and bit0 is
@@ -63,7 +65,7 @@ class LcdBase {
         virtual void on_main_loop(){};
         // override this if the panel can handle more or less screen lines
         virtual uint16_t get_screen_lines() { return 4; }
-        // used to set a variant for a panel (like viki vs panelolou2)
+        // used to set a variant for a panel (like viki2 vs st7565)
         virtual void set_variant(int n) {};
 
     protected:
index 060f5b7..a66ca30 100644 (file)
@@ -76,15 +76,18 @@ ST7565::ST7565() {
     this->encoder_a_pin.from_string(THEKERNEL->config->value( panel_checksum, encoder_a_pin_checksum)->by_default("nc")->as_string())->as_input();
     this->encoder_b_pin.from_string(THEKERNEL->config->value( panel_checksum, encoder_b_pin_checksum)->by_default("nc")->as_string())->as_input();
 
-    // contrast, mviki needs  0x018
+    // contrast
     this->contrast= THEKERNEL->config->value(panel_checksum, contrast_checksum)->by_default(9)->as_number();
     // reverse display
     this->reversed= THEKERNEL->config->value(panel_checksum, reverse_checksum)->by_default(false)->as_bool();
 
-    framebuffer= (uint8_t *)AHB0.alloc(FB_SIZE); // grab some memoery from USB_RAM
+    framebuffer= (uint8_t *)AHB0.alloc(FB_SIZE); // grab some memory from USB_RAM
     if(framebuffer == NULL) {
         THEKERNEL->streams->printf("Not enough memory available for frame buffer");
     }
+
+    // set default for sub variants
+    is_viki2 = is_mini_viki2= false; // defaults to Wulfnors panel
 }
 
 ST7565::~ST7565() {
@@ -92,6 +95,20 @@ ST7565::~ST7565() {
     AHB0.dealloc(framebuffer);
 }
 
+// variant 0 is Wulfnor panel, 1 is viki2, 2 is miniviki2
+void ST7565::set_variant(int n) {
+    switch(n) {
+        case 1:
+            is_viki2= true;
+            this->reversed= true;
+            break;
+        case 2:
+            is_mini_viki2= true;
+            this->reversed= true;
+            break;
+    }
+};
+
 //send commands to lcd
 void ST7565::send_commands(const unsigned char* buf, size_t size){
     cs.set(0);
@@ -176,6 +193,17 @@ void ST7565::init(){
   send_commands(init_seq, sizeof(init_seq));
   clear();
 }
+
+void ST7565::setContrast(uint8_t c){
+    const unsigned char contrast_seq[] = {
+      0x27,    //Contrast set
+      0x81,
+      c    //contrast value
+  };
+  this->contrast= c;
+  send_commands(contrast_seq, sizeof(contrast_seq));
+}
+
 int ST7565::drawChar(int x, int y, unsigned char c, int color){
        int retVal=-1;
          if(c=='\n'){
index 64fbca1..0963774 100644 (file)
@@ -28,7 +28,7 @@ public:
        //encoder which dosent exist :/
        uint8_t readButtons();
        int readEncoderDelta();
-       int getEncoderResolution() { return 2; }
+       int getEncoderResolution() { return (is_viki2 || is_mini_viki2) ? 4 : 2; }
        uint16_t get_screen_lines() { return 8; }
        bool hasGraphics() { return true; }
 
@@ -48,6 +48,11 @@ public:
     void renderGlyph(int x, int y, const uint8_t *g, int pixelWidth, int pixelHeight);
     void pixel(int x, int y, int colour);
 
+    uint8_t getContrast() { return contrast; }
+    void setContrast(uint8_t c);
+
+    void set_variant(int n);
+
 private:
     //buffer
        unsigned char *framebuffer;
@@ -64,7 +69,11 @@ private:
        // text cursor position
        uint8_t tx, ty;
     uint8_t contrast;
-    bool reversed;
+    struct {
+        bool reversed:1;
+        bool is_viki2:1;
+        bool is_mini_viki2:1;
+    };
 };
 
 #endif /* ST7565_H_ */
index 4808494..70d9906 100644 (file)
@@ -85,6 +85,15 @@ void MainMenuScreen::setupConfigureScreen()
         0.1F
         );
 
+    mvs->addMenuItem("Contrast",
+        []() -> float { return THEPANEL->lcd->getContrast(); },
+        [this](float v) { THEPANEL->lcd->setContrast(v); },
+        1,
+        0,
+        255,
+        true // instant update
+        );
+
     THEPANEL->enter_screen(mvs);
 }
 
index 21db378..2a044cd 100644 (file)
@@ -76,6 +76,10 @@ void ModifyValuesScreen::on_refresh()
             }
             THEPANEL->lcd->setCursor(0, 2);
             THEPANEL->lcd->printf("%10.3f    ", value);
+            if(this->instant) {
+                // NOTE this cannot be something that needs to be set in on_main_loop
+                std::get<2>(menu_items[selected_item])(value);
+            }
         }
 
     } else {
@@ -113,6 +117,7 @@ void ModifyValuesScreen::clicked_menu_entry(uint16_t line)
         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->instant= std::get<6>(menu_items[line]);
 
         THEPANEL->set_control_value(value);
         THEPANEL->lcd->clear();
@@ -139,11 +144,11 @@ 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)
+void ModifyValuesScreen::addMenuItem(const char *name, std::function<float()> getter, std::function<void(float)> setter, float inc, float  min, float max, bool instant)
 {
     string n(name);
     if(n.size() > 10) {
         n= n.substr(0, 10);
     }
-    addMenuItem(make_tuple(strdup(n.c_str()), getter, setter, inc, min, max));
+    addMenuItem(make_tuple(strdup(n.c_str()), getter, setter, inc, min, max, instant));
 }
index 289b328..dbddc23 100644 (file)
@@ -30,8 +30,8 @@ public:
     void clicked_menu_entry(uint16_t line);
     int idle_timeout_secs(){ return 60; }
 
-    typedef std::tuple<char *, std::function<float()>, std::function<void(float)>, float, float, float> 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);
+    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:
@@ -44,7 +44,10 @@ private:
     std::vector<MenuItemType> menu_items;
 
     char control_mode;
-    bool delete_on_exit;
+    struct {
+        bool delete_on_exit:1;
+        bool instant:1;
+    };
 
 };