|
| 1 | +/******************** |
| 2 | +Arduino generic menu system |
| 3 | +Serial menu example |
| 4 | +http://www.r-site.net/?at=//op%5B%40id=%273090%27%5D |
| 5 | +
|
| 6 | +Sept.2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com |
| 7 | +creative commons license 3.0: Attribution-ShareAlike CC BY-SA |
| 8 | +This software is furnished "as is", without technical support, and with no |
| 9 | +warranty, express or implied, as to its usefulness for any purpose. |
| 10 | +
|
| 11 | +Thread Safe: No |
| 12 | +Extensible: Yes |
| 13 | +*/ |
| 14 | +#include <menu.h>//menu macros and objects |
| 15 | +#include <menuFields.h> |
| 16 | +#include <menuPrint.h> |
| 17 | +//#include <streamFlow.h> |
| 18 | + |
| 19 | +struct Timer { |
| 20 | + bool use=false; |
| 21 | + enum {alarm,countDown} type=alarm; |
| 22 | + int h=0,m=0,s=0; |
| 23 | +}; |
| 24 | + |
| 25 | +Timer tmp; |
| 26 | +Timer alarms[3]; |
| 27 | + |
| 28 | +promptFeedback cancel() {return true;} |
| 29 | +promptFeedback setCurAlarm(); |
| 30 | +promptFeedback setupAlarm(); |
| 31 | + |
| 32 | +///////////////////////////////////////////////////////////////////////// |
| 33 | +// MENU DEFINITION |
| 34 | + |
| 35 | +// menu for setup an alarm, we will reuse this for all alarms |
| 36 | +TOGGLE(tmp.use,setUse,"Use",VALUE("Yes",true),VALUE("No",false)); |
| 37 | +SELECT(tmp.type,setType,"Type" |
| 38 | + ,VALUE("Alarm",Timer::alarm) |
| 39 | + ,VALUE("Countdown",Timer::countDown) |
| 40 | +); |
| 41 | +MENU(alarmDef,"Alarm def" |
| 42 | + ,SUBMENU(setUse) |
| 43 | + ,SUBMENU(setType) |
| 44 | + ,FIELD(tmp.h,"Hour","",0,24,1,0) |
| 45 | + ,FIELD(tmp.m,"Minuts","",0,60,5,1) |
| 46 | + ,FIELD(tmp.s,"Seconds","",0,60,5,1) |
| 47 | + ,OP("Ok",setupAlarm) |
| 48 | +); |
| 49 | + |
| 50 | +//menu with list of alarms |
| 51 | +MENU(mainMenu,"Alarms" |
| 52 | + ,OP("Alarm 1",setCurAlarm) |
| 53 | + ,OP("Alarm 2",setCurAlarm) |
| 54 | + ,OP("Alarm 3",setCurAlarm) |
| 55 | +); |
| 56 | + |
| 57 | +//when click ok on alarm |
| 58 | +promptFeedback setCurAlarm() { |
| 59 | + tmp=alarms[mainMenu.sel]; |
| 60 | + menuNode::activeNode=&alarmDef; |
| 61 | + return false; |
| 62 | +} |
| 63 | + |
| 64 | +//when an alarm is selected |
| 65 | +promptFeedback setupAlarm() { |
| 66 | + Serial.println("Ok"); |
| 67 | + alarms[mainMenu.sel]=tmp; |
| 68 | + return cancel(); |
| 69 | +} |
| 70 | + |
| 71 | +menuPrint menu_out(Serial);//describe output device |
| 72 | + |
| 73 | +void setup() { |
| 74 | + Serial.begin(115200); |
| 75 | + while(!Serial); |
| 76 | + Serial.println("menu system test"); |
| 77 | + delay(1000); |
| 78 | +} |
| 79 | + |
| 80 | +void loop() { |
| 81 | + mainMenu.poll(menu_out,Serial); |
| 82 | + delay(100); |
| 83 | +} |
0 commit comments