From 6fb9573157bc95df20e7649e32f0d9d1edec5a9a Mon Sep 17 00:00:00 2001 From: gregor Date: Fri, 10 May 2013 21:57:17 +0200 Subject: [PATCH 1/2] added support for the reprapworld keypad --- Marlin/Configuration.h | 10 +++++++++ Marlin/pins.h | 24 +++++++++++++++++--- Marlin/ultralcd.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++ Marlin/ultralcd.h | 18 +++++++++++++++ 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index eed4abc81..693e66a71 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -338,6 +338,11 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib //#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER +// The RepRapWorld Keypad v1.1 +// http://reprapworld.com/?products_details&products_id=202&cPath=1591_1626 +//#define KEYPAD +//#define KEYPAD_MOVE_STEP 10.0 // how much should be moved when a key is pressed, eg 10.0 means 10mm per click + //automatic expansion #if defined (REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) #define DOGLCD @@ -350,6 +355,11 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define NEWPANEL #endif +#if defined(KEYPAD) + #define NEWPANEL + #define ULTIPANEL +#endif + // Preheat Constants #define PLA_PREHEAT_HOTEND_TEMP 180 #define PLA_PREHEAT_HPB_TEMP 70 diff --git a/Marlin/pins.h b/Marlin/pins.h index 2424010aa..53932dc20 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -416,9 +416,27 @@ #define BEEPER 33 // Beeper on AUX-4 //buttons are directly attached using AUX-2 - #define BTN_EN1 37 - #define BTN_EN2 35 - #define BTN_ENC 31 //the click + #ifdef KEYPAD + #define BTN_EN1 64 // encoder + #define BTN_EN2 59 // encoder + #define BTN_ENC 63 // enter button + #define SHIFT_OUT 40 // shift register + #define SHIFT_CLK 44 // shift register + #define SHIFT_LD 42 // shift register + // define register bit values, don't change it + #define BLEN_KEYPAD_F3 0 + #define BLEN_KEYPAD_F2 1 + #define BLEN_KEYPAD_F1 2 + #define BLEN_KEYPAD_UP 3 + #define BLEN_KEYPAD_RIGHT 4 + #define BLEN_KEYPAD_MIDDLE 5 + #define BLEN_KEYPAD_DOWN 6 + #define BLEN_KEYPAD_LEFT 7 + #else + #define BTN_EN1 37 + #define BTN_EN2 35 + #define BTN_ENC 31 //the click + #endif #ifdef G3D_PANEL #define SDCARDDETECT 49 diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index fe0619fb8..1d2a97e7d 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -113,6 +113,7 @@ static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned l /** Used variables to keep track of the menu */ volatile uint8_t buttons;//Contains the bits of the currently pressed buttons. +volatile uint8_t buttons_keypad; // to store the keypad shiftregister values uint8_t currentMenuViewOffset; /* scroll offset in the current menu */ uint32_t blocking_enc; @@ -687,6 +688,25 @@ menu_edit_type(float, float51, ftostr51, 10) menu_edit_type(float, float52, ftostr52, 100) menu_edit_type(unsigned long, long5, ftostr5, 0.01) +#ifdef KEYPAD + static void keypad_move_y_down() { + SERIAL_ECHO("keypad_move_y_down"); + encoderPosition = 1; + move_menu_scale = KEYPAD_MOVE_STEP; + lcd_move_y(); + } + static void keypad_move_y_up() { + encoderPosition = -1; + move_menu_scale = KEYPAD_MOVE_STEP; + lcd_move_y(); + } + static void keypad_move_home() { + //enquecommand_P((PSTR("G28"))); // move all axis home + // TODO gregor: move all axis home, i have currently only one axis on my prusa i3 + enquecommand_P((PSTR("G28 Y"))); + } +#endif + /** End of menus **/ static void lcd_quick_feedback() @@ -750,6 +770,13 @@ void lcd_init() WRITE(BTN_EN1,HIGH); WRITE(BTN_EN2,HIGH); WRITE(BTN_ENC,HIGH); + #ifdef KEYPAD + pinMode(SHIFT_CLK,OUTPUT); + pinMode(SHIFT_LD,OUTPUT); + pinMode(SHIFT_OUT,INPUT); + WRITE(SHIFT_OUT,HIGH); + WRITE(SHIFT_LD,HIGH); + #endif #else pinMode(SHIFT_CLK,OUTPUT); pinMode(SHIFT_LD,OUTPUT); @@ -796,6 +823,17 @@ void lcd_update() if (lcd_next_update_millis < millis()) { #ifdef ULTIPANEL + #ifdef KEYPAD + if (KEYPAD_MOVE_Y_DOWN) { + keypad_move_y_down(); + } + if (KEYPAD_MOVE_Y_UP) { + keypad_move_y_up(); + } + if (KEYPAD_MOVE_HOME) { + keypad_move_home(); + } + #endif if (encoderDiff) { lcdDrawUpdate = 1; @@ -876,6 +914,18 @@ void lcd_buttons_update() if((blocking_enc>1; + if(READ(SHIFT_OUT)) + newbutton_keypad|=(1<<7); + WRITE(SHIFT_CLK,HIGH); + WRITE(SHIFT_CLK,LOW); + } + buttons_keypad=~newbutton_keypad; //invert it, because a pressed switch produces a logical 0 #else //read it from the shift register uint8_t newbutton=0; WRITE(SHIFT_LD,LOW); diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index 28de22972..1df3ed4b1 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -23,6 +23,9 @@ #ifdef ULTIPANEL void lcd_buttons_update(); extern volatile uint8_t buttons; //the last checked buttons in a bit array. + #ifdef KEYPAD + extern volatile uint8_t buttons_keypad; // to store the keypad shiftregister values + #endif #else FORCE_INLINE void lcd_buttons_update() {} #endif @@ -41,6 +44,21 @@ #define EN_A (1< Date: Fri, 10 May 2013 22:20:02 +0200 Subject: [PATCH 2/2] changes: - changed the variables from keypad to reprapworld_keypad - added a missing ifdef check --- Marlin/Configuration.h | 8 +++--- Marlin/pins.h | 18 ++++++------- Marlin/ultralcd.cpp | 57 +++++++++++++++++++++--------------------- Marlin/ultralcd.h | 32 ++++++++++++------------ 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 693e66a71..83944ab03 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -338,10 +338,10 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib //#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER -// The RepRapWorld Keypad v1.1 +// The RepRapWorld REPRAPWORLD_KEYPAD v1.1 // http://reprapworld.com/?products_details&products_id=202&cPath=1591_1626 -//#define KEYPAD -//#define KEYPAD_MOVE_STEP 10.0 // how much should be moved when a key is pressed, eg 10.0 means 10mm per click +//#define REPRAPWORLD_KEYPAD +//#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 // how much should be moved when a key is pressed, eg 10.0 means 10mm per click //automatic expansion #if defined (REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) @@ -355,7 +355,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define NEWPANEL #endif -#if defined(KEYPAD) +#if defined(REPRAPWORLD_KEYPAD) #define NEWPANEL #define ULTIPANEL #endif diff --git a/Marlin/pins.h b/Marlin/pins.h index 53932dc20..952fa7a9a 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -416,7 +416,7 @@ #define BEEPER 33 // Beeper on AUX-4 //buttons are directly attached using AUX-2 - #ifdef KEYPAD + #ifdef REPRAPWORLD_KEYPAD #define BTN_EN1 64 // encoder #define BTN_EN2 59 // encoder #define BTN_ENC 63 // enter button @@ -424,14 +424,14 @@ #define SHIFT_CLK 44 // shift register #define SHIFT_LD 42 // shift register // define register bit values, don't change it - #define BLEN_KEYPAD_F3 0 - #define BLEN_KEYPAD_F2 1 - #define BLEN_KEYPAD_F1 2 - #define BLEN_KEYPAD_UP 3 - #define BLEN_KEYPAD_RIGHT 4 - #define BLEN_KEYPAD_MIDDLE 5 - #define BLEN_KEYPAD_DOWN 6 - #define BLEN_KEYPAD_LEFT 7 + #define BLEN_REPRAPWORLD_KEYPAD_F3 0 + #define BLEN_REPRAPWORLD_KEYPAD_F2 1 + #define BLEN_REPRAPWORLD_KEYPAD_F1 2 + #define BLEN_REPRAPWORLD_KEYPAD_UP 3 + #define BLEN_REPRAPWORLD_KEYPAD_RIGHT 4 + #define BLEN_REPRAPWORLD_KEYPAD_MIDDLE 5 + #define BLEN_REPRAPWORLD_KEYPAD_DOWN 6 + #define BLEN_REPRAPWORLD_KEYPAD_LEFT 7 #else #define BTN_EN1 37 #define BTN_EN2 35 diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 1d2a97e7d..3f74e2743 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -113,7 +113,7 @@ static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned l /** Used variables to keep track of the menu */ volatile uint8_t buttons;//Contains the bits of the currently pressed buttons. -volatile uint8_t buttons_keypad; // to store the keypad shiftregister values +volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shiftregister values uint8_t currentMenuViewOffset; /* scroll offset in the current menu */ uint32_t blocking_enc; @@ -688,19 +688,18 @@ menu_edit_type(float, float51, ftostr51, 10) menu_edit_type(float, float52, ftostr52, 100) menu_edit_type(unsigned long, long5, ftostr5, 0.01) -#ifdef KEYPAD - static void keypad_move_y_down() { - SERIAL_ECHO("keypad_move_y_down"); +#ifdef REPRAPWORLD_KEYPAD + static void reprapworld_keypad_move_y_down() { encoderPosition = 1; - move_menu_scale = KEYPAD_MOVE_STEP; + move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP; lcd_move_y(); } - static void keypad_move_y_up() { + static void reprapworld_keypad_move_y_up() { encoderPosition = -1; - move_menu_scale = KEYPAD_MOVE_STEP; + move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP; lcd_move_y(); } - static void keypad_move_home() { + static void reprapworld_keypad_move_home() { //enquecommand_P((PSTR("G28"))); // move all axis home // TODO gregor: move all axis home, i have currently only one axis on my prusa i3 enquecommand_P((PSTR("G28 Y"))); @@ -770,7 +769,7 @@ void lcd_init() WRITE(BTN_EN1,HIGH); WRITE(BTN_EN2,HIGH); WRITE(BTN_ENC,HIGH); - #ifdef KEYPAD + #ifdef REPRAPWORLD_KEYPAD pinMode(SHIFT_CLK,OUTPUT); pinMode(SHIFT_LD,OUTPUT); pinMode(SHIFT_OUT,INPUT); @@ -823,15 +822,15 @@ void lcd_update() if (lcd_next_update_millis < millis()) { #ifdef ULTIPANEL - #ifdef KEYPAD - if (KEYPAD_MOVE_Y_DOWN) { - keypad_move_y_down(); + #ifdef REPRAPWORLD_KEYPAD + if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) { + reprapworld_keypad_move_y_down(); } - if (KEYPAD_MOVE_Y_UP) { - keypad_move_y_up(); + if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) { + reprapworld_keypad_move_y_up(); } - if (KEYPAD_MOVE_HOME) { - keypad_move_home(); + if (REPRAPWORLD_KEYPAD_MOVE_HOME) { + reprapworld_keypad_move_home(); } #endif if (encoderDiff) @@ -914,18 +913,20 @@ void lcd_buttons_update() if((blocking_enc>1; - if(READ(SHIFT_OUT)) - newbutton_keypad|=(1<<7); - WRITE(SHIFT_CLK,HIGH); - WRITE(SHIFT_CLK,LOW); - } - buttons_keypad=~newbutton_keypad; //invert it, because a pressed switch produces a logical 0 + #ifdef REPRAPWORLD_KEYPAD + // for the reprapworld_keypad + uint8_t newbutton_reprapworld_keypad=0; + WRITE(SHIFT_LD,LOW); + WRITE(SHIFT_LD,HIGH); + for(int8_t i=0;i<8;i++) { + newbutton_reprapworld_keypad = newbutton_reprapworld_keypad>>1; + if(READ(SHIFT_OUT)) + newbutton_reprapworld_keypad|=(1<<7); + WRITE(SHIFT_CLK,HIGH); + WRITE(SHIFT_CLK,LOW); + } + buttons_reprapworld_keypad=~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0 + #endif #else //read it from the shift register uint8_t newbutton=0; WRITE(SHIFT_LD,LOW); diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index 1df3ed4b1..03f2fe186 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -23,8 +23,8 @@ #ifdef ULTIPANEL void lcd_buttons_update(); extern volatile uint8_t buttons; //the last checked buttons in a bit array. - #ifdef KEYPAD - extern volatile uint8_t buttons_keypad; // to store the keypad shiftregister values + #ifdef REPRAPWORLD_KEYPAD + extern volatile uint8_t buttons_reprapworld_keypad; // to store the keypad shiftregister values #endif #else FORCE_INLINE void lcd_buttons_update() {} @@ -44,21 +44,21 @@ #define EN_A (1<