specify variant in ctor
authorJim Morris <morris@wolfman.com>
Sat, 27 Sep 2014 08:36:23 +0000 (01:36 -0700)
committerJim Morris <morris@wolfman.com>
Sat, 27 Sep 2014 08:36:23 +0000 (01:36 -0700)
add mini_viki2 as it needs different contrast and encoder resolution

ConfigSamples/AzteegX5Mini.delta/config
src/modules/utils/panel/Panel.cpp
src/modules/utils/panel/panels/ST7565.cpp
src/modules/utils/panel/panels/ST7565.h

index 572855b..e1a9958 100644 (file)
@@ -173,14 +173,14 @@ zprobe.probe_height                          5               # how much above be
 pause_button_enable                          true             #
 
 # Panel See http://smoothieware.org/panel
-panel.enable                                 false               # set to true to enable the panel code
+panel.enable                                 false             # set to true to enable the panel code
 
 # Example viki2 config
 panel.lcd                                    viki2             # set type of panel
 panel.spi_channel                            0                 # set spi channel to use P0_18,P0_15 MOSI,SCLK
 panel.spi_cs_pin                             0.16              # set spi chip select
-panel.encoder_a_pin                          3.25!^            # encoder pin
-panel.encoder_b_pin                          3.26!^            # encoder pin
+panel.encoder_a_pin                          3.26!^            # encoder pin
+panel.encoder_b_pin                          3.25!^            # encoder pin
 panel.click_button_pin                       2.11!^            # click button
 panel.a0_pin                                 2.6               # st7565 needs an a0
 #panel.contrast                              8                 # override contrast setting (default is 9)
@@ -191,7 +191,18 @@ panel.buzz_pin                               1.31              # pin for buzzer
 panel.red_led_pin                            0.26              # pin for red led on viki2 on EXP1
 panel.blue_led_pin                           0.25              # pin for blue led on viki2 on EXP1
 
-panel.menu_offset                            1                 # some panels will need 1 here
+# Example mini viki2 config
+#panel.lcd                                    mini_viki2        # set type of panel
+#panel.spi_channel                            0                 # set spi channel to use P0_18,P0_15 MOSI,SCLK
+#panel.spi_cs_pin                             0.16              # set spi chip select
+#panel.encoder_a_pin                          3.25!^            # encoder pin
+#panel.encoder_b_pin                          3.26!^            # encoder pin
+#panel.click_button_pin                       2.11!^            # click button
+#panel.a0_pin                                 2.6               # st7565 needs an a0
+##panel.contrast                               18                # override contrast setting (default is 18)
+##panel.encoder_resolution                     2                 # override number of clicks to move 1 item (default is 2)
+
+panel.menu_offset                            1                 # here controls how sensitive the menu is. some panels will need 1
 
 panel.alpha_jog_feedrate                     6000              # x jogging feedrate in mm/min
 panel.beta_jog_feedrate                      6000              # y jogging feedrate in mm/min
index c5bcb60..9be36b2 100644 (file)
@@ -93,11 +93,9 @@ void Panel::on_module_loaded()
     } 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);
+        this->lcd = new ST7565(1); // variant 1
     } else if (lcd_cksm == mini_viki2_checksum) {
-        this->lcd = new ST7565();
-        this->lcd->set_variant(2);
+        this->lcd = new ST7565(2); // variant 2
     } else if (lcd_cksm == universal_adapter_checksum) {
         this->lcd = new UniversalAdapter();
     } else {
index 0504ae6..6fa1e56 100644 (file)
 #define CLAMP(x, low, high) { if ( (x) < (low) ) x = (low); if ( (x) > (high) ) x = (high); } while (0);
 #define swap(a, b) { uint8_t t = a; a = b; b = t; }
 
-ST7565::ST7565() {
-       //SPI com
+ST7565::ST7565(uint8_t variant) {
+    // set the variant
+    switch(variant) {
+        case 1:
+            is_viki2= true;
+            is_mini_viki2= false;
+            this->reversed= true;
+            this->contrast= 9;
+            break;
+        case 2:
+            is_mini_viki2= true;
+            is_viki2= false;
+            this->reversed= true;
+            this->contrast= 18;
+            break;
+        default:
+            // set default for sub variants
+            is_viki2= false; // defaults to Wulfnors panel
+            is_mini_viki2= false;
+            this->reversed= false;
+            this->contrast= 9;
+            break;
+    }
 
-   // select which SPI channel to use
+    //SPI com
+    // select which SPI channel to use
     int spi_channel = THEKERNEL->config->value(panel_checksum, spi_channel_checksum)->by_default(0)->as_number();
     PinName mosi;
     PinName sclk;
@@ -74,23 +96,30 @@ ST7565::ST7565() {
     this->a0.from_string(THEKERNEL->config->value( panel_checksum, a0_pin_checksum)->by_default("2.13")->as_string())->as_output();
     a0.set(1);
 
-    this->up_pin.from_string(THEKERNEL->config->value( panel_checksum, up_button_pin_checksum )->by_default("nc")->as_string())->as_input();
-    this->down_pin.from_string(THEKERNEL->config->value( panel_checksum, down_button_pin_checksum )->by_default("nc")->as_string())->as_input();
+    if(!is_viki2 && !is_mini_viki2) {
+        this->up_pin.from_string(THEKERNEL->config->value( panel_checksum, up_button_pin_checksum )->by_default("nc")->as_string())->as_input();
+        this->down_pin.from_string(THEKERNEL->config->value( panel_checksum, down_button_pin_checksum )->by_default("nc")->as_string())->as_input();
+    }else{
+        this->up_pin.from_string("nc");
+        this->down_pin.from_string("nc");
+    }
 
-    // the aux pin can be pause or back on a viki2
     this->aux_pin.from_string("nc");
-    string aux_but= THEKERNEL->config->value( panel_checksum, pause_button_pin_checksum )->by_default("nc")->as_string();
-    if(aux_but != "nc") {
-        this->aux_pin.from_string(aux_but)->as_input();
-        this->use_pause= true;
-        this->use_back= false;
-
-    }else{
-        aux_but= THEKERNEL->config->value( panel_checksum, back_button_pin_checksum )->by_default("nc")->as_string();
+    if(is_viki2) {
+        // the aux pin can be pause or back on a viki2
+        string aux_but= THEKERNEL->config->value( panel_checksum, pause_button_pin_checksum )->by_default("nc")->as_string();
         if(aux_but != "nc") {
             this->aux_pin.from_string(aux_but)->as_input();
-            this->use_back= true;
-            this->use_pause= false;
+            this->use_pause= true;
+            this->use_back= false;
+
+        }else{
+            aux_but= THEKERNEL->config->value( panel_checksum, back_button_pin_checksum )->by_default("nc")->as_string();
+            if(aux_but != "nc") {
+                this->aux_pin.from_string(aux_but)->as_input();
+                this->use_back= true;
+                this->use_pause= false;
+            }
         }
     }
 
@@ -100,23 +129,24 @@ ST7565::ST7565() {
 
     this->buzz_pin.from_string(THEKERNEL->config->value( panel_checksum, buzz_pin_checksum)->by_default("nc")->as_string())->as_output();
 
-    this->red_led.from_string(THEKERNEL->config->value( panel_checksum, red_led_checksum)->by_default("nc")->as_string())->as_output();
-    this->blue_led.from_string(THEKERNEL->config->value( panel_checksum, blue_led_checksum)->by_default("nc")->as_string())->as_output();
-    this->red_led.set(false);
-    this->blue_led.set(true);
+    if(is_viki2) {
+        this->red_led.from_string(THEKERNEL->config->value( panel_checksum, red_led_checksum)->by_default("nc")->as_string())->as_output();
+        this->blue_led.from_string(THEKERNEL->config->value( panel_checksum, blue_led_checksum)->by_default("nc")->as_string())->as_output();
+        this->red_led.set(false);
+        this->blue_led.set(true);
+    }
+
+    // contrast override
+    this->contrast= THEKERNEL->config->value(panel_checksum, contrast_checksum)->by_default(this->contrast)->as_number();
 
-    // 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();
+    this->reversed= THEKERNEL->config->value(panel_checksum, reverse_checksum)->by_default(this->reversed)->as_bool();
 
     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() {
@@ -124,20 +154,6 @@ 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);
index cec33c4..4c29e0a 100644 (file)
@@ -14,7 +14,7 @@
 
 class ST7565: public LcdBase {
 public:
-       ST7565();
+       ST7565(uint8_t v= 0);
        virtual ~ST7565();
        void home();
     void clear();
@@ -28,7 +28,7 @@ public:
        //encoder which dosent exist :/
        uint8_t readButtons();
        int readEncoderDelta();
-       int getEncoderResolution() { return (is_viki2 || is_mini_viki2) ? 4 : 2; }
+       int getEncoderResolution() { return is_viki2 ? 4 : 2; }
        uint16_t get_screen_lines() { return 8; }
        bool hasGraphics() { return true; }
 
@@ -51,7 +51,6 @@ public:
     uint8_t getContrast() { return contrast; }
     void setContrast(uint8_t c);
 
-    void set_variant(int n);
     void buzz(long duration, uint16_t freq);
     void setLed(int led, bool onoff);