mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-12-27 04:29:00 +00:00
235 lines
11 KiB
Plaintext
235 lines
11 KiB
Plaintext
/*
|
|
|
|
Menu.pde
|
|
|
|
Simple Menu Selection
|
|
|
|
>>> Before compiling: Please remove comment from the constructor of the
|
|
>>> connected graphics display (see below).
|
|
|
|
Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
|
|
|
|
Copyright (c) 2012, olikraus@gmail.com
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this list
|
|
of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
list of conditions and the following disclaimer in the documentation and/or other
|
|
materials provided with the distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
*/
|
|
|
|
|
|
#include "U8glib.h"
|
|
|
|
// setup u8g object, please remove comment from one of the following constructor calls
|
|
// IMPORTANT NOTE: The complete list of supported devices is here: http://code.google.com/p/u8glib/wiki/device
|
|
|
|
//U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_NHD31OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_NHD31OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_NHD31OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_NHD31OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_DOGS102 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_DOGM132 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_DOGM128 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_ST7920_128X64_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
|
//U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
|
//U8GLIB_ST7920_128X64_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
|
//U8GLIB_ST7920_128X64_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
|
//U8GLIB_ST7920_192X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
|
//U8GLIB_ST7920_192X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
|
//U8GLIB_ST7920_192X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
|
//U8GLIB_ST7920_192X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
|
//U8GLIB_ST7920_192X32_1X u8g(13, 11, 10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10
|
|
//U8GLIB_ST7920_192X32_4X u8g(10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
|
|
//U8GLIB_ST7920_202X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
|
//U8GLIB_ST7920_202X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
|
//U8GLIB_ST7920_202X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
|
//U8GLIB_ST7920_202X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
|
//U8GLIB_LM6059 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_LM6063 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_DOGXL160_BW u8g(10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
|
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
|
//U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
|
|
//U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
|
//U8GLIB_LC7981_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
|
//U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
|
//U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 ); // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
|
|
//U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
|
|
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
|
//U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_SSD1306_128X32 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
|
//U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
|
//U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
|
//U8GLIB_SSD1327_96X96_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
|
//U8GLIB_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
|
//U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
|
//U8GLIB_NHD_C12832 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
|
//U8GLIB_T6963_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
|
//U8GLIB_T6963_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
|
//U8GLIB_T6963_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
|
|
|
|
|
#define KEY_NONE 0
|
|
#define KEY_PREV 1
|
|
#define KEY_NEXT 2
|
|
#define KEY_SELECT 3
|
|
#define KEY_BACK 4
|
|
|
|
// DOGS102 shield configuration values
|
|
//uint8_t uiKeyPrev = 2;
|
|
//uint8_t uiKeyNext = 4;
|
|
//uint8_t uiKeySelect = 5;
|
|
//uint8_t uiKeyBack = 3;
|
|
|
|
// DOGM128-Shield configuration values
|
|
// DOGXL60-Shield configuration values
|
|
uint8_t uiKeyPrev = 7;
|
|
uint8_t uiKeyNext = 3;
|
|
uint8_t uiKeySelect = 2;
|
|
uint8_t uiKeyBack = 8;
|
|
|
|
uint8_t uiKeyCodeFirst = KEY_NONE;
|
|
uint8_t uiKeyCodeSecond = KEY_NONE;
|
|
uint8_t uiKeyCode = KEY_NONE;
|
|
|
|
|
|
void uiSetup(void) {
|
|
// configure input keys
|
|
|
|
pinMode(uiKeyPrev, INPUT); // set pin to input
|
|
digitalWrite(uiKeyPrev, HIGH); // turn on pullup resistors
|
|
pinMode(uiKeyNext, INPUT); // set pin to input
|
|
digitalWrite(uiKeyNext, HIGH); // turn on pullup resistors
|
|
pinMode(uiKeySelect, INPUT); // set pin to input
|
|
digitalWrite(uiKeySelect, HIGH); // turn on pullup resistors
|
|
pinMode(uiKeyBack, INPUT); // set pin to input
|
|
digitalWrite(uiKeyBack, HIGH); // turn on pullup resistors
|
|
}
|
|
|
|
void uiStep(void) {
|
|
uiKeyCodeSecond = uiKeyCodeFirst;
|
|
if ( digitalRead(uiKeyPrev) == LOW )
|
|
uiKeyCodeFirst = KEY_PREV;
|
|
else if ( digitalRead(uiKeyNext) == LOW )
|
|
uiKeyCodeFirst = KEY_NEXT;
|
|
else if ( digitalRead(uiKeySelect) == LOW )
|
|
uiKeyCodeFirst = KEY_SELECT;
|
|
else if ( digitalRead(uiKeyBack) == LOW )
|
|
uiKeyCodeFirst = KEY_BACK;
|
|
else
|
|
uiKeyCodeFirst = KEY_NONE;
|
|
|
|
if ( uiKeyCodeSecond == uiKeyCodeFirst )
|
|
uiKeyCode = uiKeyCodeFirst;
|
|
else
|
|
uiKeyCode = KEY_NONE;
|
|
}
|
|
|
|
|
|
#define MENU_ITEMS 4
|
|
char *menu_strings[MENU_ITEMS] = { "First Line", "Second Item", "3333333", "abcdefg" };
|
|
|
|
uint8_t menu_current = 0;
|
|
uint8_t menu_redraw_required = 0;
|
|
uint8_t last_key_code = KEY_NONE;
|
|
|
|
|
|
void drawMenu(void) {
|
|
uint8_t i, h;
|
|
u8g_uint_t w, d;
|
|
|
|
u8g.setFont(u8g_font_6x13);
|
|
u8g.setFontRefHeightText();
|
|
u8g.setFontPosTop();
|
|
|
|
h = u8g.getFontAscent()-u8g.getFontDescent();
|
|
w = u8g.getWidth();
|
|
for( i = 0; i < MENU_ITEMS; i++ ) {
|
|
d = (w-u8g.getStrWidth(menu_strings[i]))/2;
|
|
u8g.setDefaultForegroundColor();
|
|
if ( i == menu_current ) {
|
|
u8g.drawBox(0, i*h+1, w, h);
|
|
u8g.setDefaultBackgroundColor();
|
|
}
|
|
u8g.drawStr(d, i*h, menu_strings[i]);
|
|
}
|
|
}
|
|
|
|
void updateMenu(void) {
|
|
if ( uiKeyCode != KEY_NONE && last_key_code == uiKeyCode ) {
|
|
return;
|
|
}
|
|
last_key_code = uiKeyCode;
|
|
|
|
switch ( uiKeyCode ) {
|
|
case KEY_NEXT:
|
|
menu_current++;
|
|
if ( menu_current >= MENU_ITEMS )
|
|
menu_current = 0;
|
|
menu_redraw_required = 1;
|
|
break;
|
|
case KEY_PREV:
|
|
if ( menu_current == 0 )
|
|
menu_current = MENU_ITEMS;
|
|
menu_current--;
|
|
menu_redraw_required = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void setup() {
|
|
// rotate screen, if required
|
|
// u8g.setRot180();
|
|
|
|
uiSetup(); // setup key detection and debounce algorithm
|
|
menu_redraw_required = 1; // force initial redraw
|
|
}
|
|
|
|
void loop() {
|
|
|
|
uiStep(); // check for key press
|
|
|
|
if ( menu_redraw_required != 0 ) {
|
|
u8g.firstPage();
|
|
do {
|
|
drawMenu();
|
|
} while( u8g.nextPage() );
|
|
menu_redraw_required = 0;
|
|
}
|
|
|
|
updateMenu(); // update menu bar
|
|
|
|
}
|