|
| 1 | +/******************** |
| 2 | +Arduino generic menu system |
| 3 | +
|
| 4 | +Rui Azevedo - ruihfazevedo(@rrob@)gmail.com |
| 5 | +
|
| 6 | +output: Serial |
| 7 | +input: Serial |
| 8 | +*/ |
| 9 | + |
| 10 | +#include <Arduino.h> |
| 11 | + |
| 12 | +#include <menu.h> |
| 13 | +#include <menuIO/serialOut.h> |
| 14 | +#include <menuIO/chainStream.h> |
| 15 | +#include <menuIO/serialIn.h> |
| 16 | +#include <menuIO/uartOut.h> |
| 17 | +#include <SoftwareSerial.h> |
| 18 | + |
| 19 | +using namespace Menu; |
| 20 | + |
| 21 | +#define LEDPIN LED_BUILTIN |
| 22 | + |
| 23 | +SoftwareSerial ss(11, 10); |
| 24 | + |
| 25 | + |
| 26 | +#define MAX_DEPTH 2 |
| 27 | + |
| 28 | +// define menu colors -------------------------------------------------------- |
| 29 | +#define C_BLACK 0 |
| 30 | +#define C_BLUE 3 |
| 31 | +#define C_GRAY 7 |
| 32 | +#define C_WHITE 15 |
| 33 | +#define C_YELLOW 31 |
| 34 | +#define C_RED 1 |
| 35 | +#define C_GREEN 2 |
| 36 | +//each color is in the format: |
| 37 | +// {{disabled normal,disabled selected},{enabled normal,enabled selected, enabled editing}} |
| 38 | +const colorDef<uint8_t> colors[] MEMMODE={ |
| 39 | + {{C_BLACK,C_BLACK}, {C_BLACK,C_BLUE,C_BLUE}},//bgColor |
| 40 | + {{C_GRAY,C_GRAY}, {C_WHITE,C_WHITE,C_WHITE}},//fgColor |
| 41 | + {{C_WHITE,C_BLACK}, {C_YELLOW,C_YELLOW,C_RED}},//valColor |
| 42 | + {{C_WHITE,C_BLACK}, {C_WHITE,C_YELLOW,C_YELLOW}},//unitColor |
| 43 | + {{C_WHITE,C_GRAY}, {C_BLACK,C_BLUE,C_WHITE}},//cursorColor |
| 44 | + {{C_WHITE,C_YELLOW},{C_GREEN,C_WHITE,C_WHITE}},//titleColor |
| 45 | +}; |
| 46 | + |
| 47 | + |
| 48 | +#define offsetX 0 |
| 49 | +#define offsetY 0 |
| 50 | +#define U8_Width 240 |
| 51 | +#define U8_Height 320 |
| 52 | + |
| 53 | +#define LEDPIN LED_BUILTIN |
| 54 | + |
| 55 | + |
| 56 | +int timeOn=10; |
| 57 | +int timeOff=90; |
| 58 | + |
| 59 | +MENU(mainMenu, "Settings menu", Menu::doNothing, Menu::noEvent, Menu::wrapStyle |
| 60 | + ,FIELD(timeOn,"On","ms",0,100,10,1, Menu::doNothing, Menu::noEvent, Menu::noStyle) |
| 61 | + ,FIELD(timeOff,"Off","ms",0,100,10,1,Menu::doNothing, Menu::noEvent, Menu::noStyle) |
| 62 | + ,EXIT("<Back") |
| 63 | +); |
| 64 | + |
| 65 | +serialIn serial(Serial); |
| 66 | + |
| 67 | +MENU_INPUTS(in,&serial); |
| 68 | + |
| 69 | +MENU_OUTPUTS(out,MAX_DEPTH |
| 70 | + ,UART_OUT(ss,colors,uartOut::systemFont::font24,offsetX,offsetY,{0,0,U8_Width/uartOut::systemFont::font24*2,U8_Height/uartOut::systemFont::font24}) |
| 71 | + ,SERIAL_OUT(Serial) |
| 72 | +); |
| 73 | + |
| 74 | +NAVROOT(nav,mainMenu,MAX_DEPTH,in,out); |
| 75 | + |
| 76 | +void setup() { |
| 77 | + pinMode(LEDPIN, OUTPUT); |
| 78 | + Serial.begin(115200); |
| 79 | + ss.begin(115200); |
| 80 | + while(!Serial); |
| 81 | + Serial.println("Menu 4.x"); |
| 82 | + Serial.println("Use keys + - * /"); |
| 83 | + Serial.println("to control the menu navigation"); |
| 84 | +} |
| 85 | + |
| 86 | +void loop() { |
| 87 | + nav.doInput(); |
| 88 | + if (nav.changed(0)) { |
| 89 | + //only draw if menu changed for gfx device |
| 90 | + nav.doOutput(); |
| 91 | + } |
| 92 | + digitalWrite(LEDPIN, HIGH); |
| 93 | + delay(timeOn); |
| 94 | + digitalWrite(LEDPIN, LOW); |
| 95 | + delay(timeOff); |
| 96 | +} |
| 97 | + |
0 commit comments