add buzz and red/blue leds for viki2 panel
authorJim Morris <morris@wolfman.com>
Fri, 26 Sep 2014 22:36:20 +0000 (15:36 -0700)
committerJim Morris <morris@wolfman.com>
Fri, 26 Sep 2014 22:36:20 +0000 (15:36 -0700)
add example coinfig for viki2

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

index 4972d48..572855b 100644 (file)
@@ -172,12 +172,24 @@ zprobe.probe_height                          5               # how much above be
 # Pause button
 pause_button_enable                          true             #
 
-# Panel http://smoothieware.org/panel
+# Panel See http://smoothieware.org/panel
 panel.enable                                 false               # set to true to enable the panel code
-panel.lcd                                    viki_lcd       # set type of panel also viki_lcd, i2c_lcd is a generic i2c panel, panelolu2
+
+# 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.i2c_pins                               3                 # set i2c channel to use
+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)
+#panel.encoder_resolution                    4                 # override number of clicks to move 1 item (default is 4)
+#panel.button_pause_pin                      4.29^             # kill/pause set one of these for the auxilliary button on viki2
+#panel.back_button_pin                       4.29!^            # back button recommended to use this on EXP1
+panel.buzz_pin                               1.31              # pin for buzzer on EXP2
+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
 
index 234f4d3..c7e5136 100755 (executable)
@@ -171,21 +171,24 @@ zprobe.probe_height                          5               # how much above be
 # Pause button
 pause_button_enable                          true             #
 
-# Panel
+# Panel See http://smoothieware.org/panel
 panel.enable                                 false             # set to true to enable the panel code
 
-# Example for reprap discount GLCD
-# on glcd EXP1 is to left and EXP2 is to right, pin 1 is bottom left, pin 2 is top left etc.
-# +5v is EXP1 pin 10, Gnd is EXP1 pin 9
-#panel.lcd                                   reprap_discount_glcd     #
-#panel.spi_channel                           0                 # pins 0.18, 0.15     ; GLCD EXP1 Pins 3,5 (MOSI, SCLK)
-#panel.spi_cs_pin                            0.16              # spi chip select     ; GLCD EXP1 Pin 4
-#panel.encoder_a_pin                         3.25!^            # encoder pin         ; GLCD EXP2 Pin 3
-#panel.encoder_b_pin                         3.26!^            # encoder pin         ; GLCD EXP2 Pin 5
-#panel.click_button_pin                      2.11!^            # click button        ; GLCD EXP1 Pin 2
-#panel.buzz_pin                              1.31              # pin for buzzer      ; GLCD EXP1 Pin 1
-#panel.button_pause_pin                      4.29^             # kill/pause          ; GLCD EXP2 Pin 8 either
-#panel.back_button_pin                       4.29!^            # back button         ; GLCD EXP2 Pin 8 or
+# 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.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)
+#panel.encoder_resolution                    4                 # override number of clicks to move 1 item (default is 4)
+#panel.button_pause_pin                      4.29^             # kill/pause set one of these for the auxilliary button on viki2
+#panel.back_button_pin                       4.29!^            # back button recommended to use this on EXP1
+panel.buzz_pin                               1.31              # pin for buzzer on EXP2
+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                            0                 # some panels will need 1 here
 
index a66ca30..e6325b8 100644 (file)
 #define click_button_pin_checksum  CHECKSUM("click_button_pin")
 #define up_button_pin_checksum     CHECKSUM("up_button_pin")
 #define down_button_pin_checksum   CHECKSUM("down_button_pin")
+#define pause_button_pin_checksum  CHECKSUM("pause_button_pin")
+#define back_button_pin_checksum   CHECKSUM("back_button_pin")
+#define buzz_pin_checksum          CHECKSUM("buzz_pin")
 #define contrast_checksum          CHECKSUM("contrast")
 #define reverse_checksum           CHECKSUM("reverse")
 #define rst_pin_checksum           CHECKSUM("rst_pin")
 #define a0_pin_checksum            CHECKSUM("a0_pin")
+#define red_led_checksum           CHECKSUM("red_led_pin")
+#define blue_led_checksum          CHECKSUM("blue_led_pin")
 
 #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; }
@@ -72,10 +77,34 @@ ST7565::ST7565() {
     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();
 
+    // 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(aux_but != "nc") {
+            this->aux_pin.from_string(aux_but)->as_input();
+            this->use_back= true;
+            this->use_pause= false;
+        }
+    }
+
     this->click_pin.from_string(THEKERNEL->config->value( panel_checksum, click_button_pin_checksum )->by_default("nc")->as_string())->as_input();
     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();
 
+    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(0);
+    this->blue_led.set(0);
+
     // contrast
     this->contrast= THEKERNEL->config->value(panel_checksum, contrast_checksum)->by_default(9)->as_number();
     // reverse display
@@ -265,6 +294,10 @@ uint8_t ST7565::readButtons(void) {
         state |= (this->up_pin.get() ? BUTTON_UP : 0);
         state |= (this->down_pin.get() ? BUTTON_DOWN : 0);
     }
+    if(this->aux_pin.connected() && this->aux_pin.get()) {
+        if(this->use_pause) state |= BUTTON_PAUSE;
+        else if(this->use_back) state |= BUTTON_LEFT;
+    }
     return state;
 }
 
@@ -327,3 +360,28 @@ void ST7565::pixel(int x, int y, int colour)
     else
         *byte |= mask; // set pixel
 }
+
+// cycle the buzzer pin at a certain frequency (hz) for a certain duration (ms)
+void ST7565::buzz(long duration, uint16_t freq) {
+    if(!this->buzz_pin.connected()) return;
+
+    duration *=1000; //convert from ms to us
+    long period = 1000000 / freq; // period in us
+    long elapsed_time = 0;
+    while (elapsed_time < duration) {
+        this->buzz_pin.set(1);
+        wait_us(period / 2);
+        this->buzz_pin.set(0);
+        wait_us(period / 2);
+        elapsed_time += (period);
+    }
+}
+
+void ST7565::setLed(int led, bool onoff) {
+    if(!is_viki2) return;
+
+    switch(led) {
+        case LED_HOTEND_ON: red_led.set(onoff); break;
+        case LED_BED_ON: blue_led.set(onoff); break;
+    }
+}
index 0963774..cec33c4 100644 (file)
@@ -52,6 +52,8 @@ public:
     void setContrast(uint8_t c);
 
     void set_variant(int n);
+    void buzz(long duration, uint16_t freq);
+    void setLed(int led, bool onoff);
 
 private:
     //buffer
@@ -62,9 +64,13 @@ private:
        Pin a0;
        Pin click_pin;
        Pin up_pin;
-       Pin down_pin;
+    Pin down_pin;
+    Pin buzz_pin;
+       Pin aux_pin;
     Pin encoder_a_pin;
     Pin encoder_b_pin;
+    Pin red_led;
+    Pin blue_led;
 
        // text cursor position
        uint8_t tx, ty;
@@ -73,6 +79,8 @@ private:
         bool reversed:1;
         bool is_viki2:1;
         bool is_mini_viki2:1;
+        bool use_pause:1;
+        bool use_back:1;
     };
 };