Skip to content

Commit dafc591

Browse files
committed
added Confirm example
and exit option with confirmation and menu lock
1 parent 35cefb3 commit dafc591

File tree

7 files changed

+184
-62
lines changed

7 files changed

+184
-62
lines changed

examples/Confirm/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.pioenvs
2+
.piolibdeps
3+
.clang_complete
4+
.gcc-flags.json

examples/Confirm/.travis.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Continuous Integration (CI) is the practice, in software
2+
# engineering, of merging all developer working copies with a shared mainline
3+
# several times a day < http://docs.platformio.org/page/ci/index.html >
4+
#
5+
# Documentation:
6+
#
7+
# * Travis CI Embedded Builds with PlatformIO
8+
# < https://docs.travis-ci.com/user/integration/platformio/ >
9+
#
10+
# * PlatformIO integration with Travis CI
11+
# < http://docs.platformio.org/page/ci/travis.html >
12+
#
13+
# * User Guide for `platformio ci` command
14+
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
15+
#
16+
#
17+
# Please choice one of the following templates (proposed below) and uncomment
18+
# it (remove "# " before each line) or use own configuration according to the
19+
# Travis CI documentation (see above).
20+
#
21+
22+
23+
#
24+
# Template #1: General project. Test it using existing `platformio.ini`.
25+
#
26+
27+
# language: python
28+
# python:
29+
# - "2.7"
30+
#
31+
# sudo: false
32+
# cache:
33+
# directories:
34+
# - "~/.platformio"
35+
#
36+
# install:
37+
# - pip install -U platformio
38+
#
39+
# script:
40+
# - platformio run
41+
42+
43+
#
44+
# Template #2: The project is intended to by used as a library with examples
45+
#
46+
47+
# language: python
48+
# python:
49+
# - "2.7"
50+
#
51+
# sudo: false
52+
# cache:
53+
# directories:
54+
# - "~/.platformio"
55+
#
56+
# env:
57+
# - PLATFORMIO_CI_SRC=path/to/test/file.c
58+
# - PLATFORMIO_CI_SRC=examples/file.ino
59+
# - PLATFORMIO_CI_SRC=path/to/test/directory
60+
#
61+
# install:
62+
# - pip install -U platformio
63+
#
64+
# script:
65+
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
3+
Custom sub-menu prompt used as exit confirmation
4+
the Exit option on this example presents only the "Exit" text
5+
but the submenu really as an "Exit?" text for confirmation
6+
choosing "yes" will suspend the menu and possibly do other stuff
7+
while "no" will just return to previous menu
8+
9+
*/
10+
11+
#include <menu.h>
12+
#include <menuIO/serialOut.h>
13+
14+
using namespace Menu;
15+
16+
//customizing a menu prompt look
17+
class confirmExit:public menu {
18+
public:
19+
confirmExit(const menuNodeShadow& shadow):menu(shadow) {}
20+
idx_t printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len) override {
21+
return out.printRaw("Exit",len);
22+
}
23+
};
24+
25+
// this function is defined below because we need to refer
26+
// to the navigation system (suspending the menu)
27+
result systemExit();
28+
29+
//using the customized menu class
30+
//note that first parameter is the class name
31+
altMENU(confirmExit,subMenu,"Exit?",doNothing,anyEvent,noStyle
32+
,OP("Yes",systemExit,enterEvent)
33+
,EXIT("Cancel")
34+
);
35+
36+
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
37+
,OP("Op1",doNothing,noEvent)
38+
,SUBMENU(subMenu)
39+
);
40+
41+
#define MAX_DEPTH 2
42+
43+
MENU_OUTPUTS(out,MAX_DEPTH
44+
,SERIAL_OUT(Serial)
45+
,NONE//must have 2 items at least
46+
);
47+
48+
NAVROOT(nav,mainMenu,MAX_DEPTH,Serial,out);
49+
50+
bool running=true;//lock menu if false
51+
52+
result systemExit() {
53+
Serial.println();
54+
Serial.println("Terminating...");
55+
//do some termiination stuff here
56+
running=false;//prevents the menu from running again!
57+
Serial.println("done.");
58+
nav.idleOn();//suspend the menu system
59+
return quit;
60+
}
61+
62+
void setup() {
63+
Serial.begin(9600);
64+
while(!Serial);
65+
Serial.println("menu 3.x custom sub-menu prompt example");Serial.flush();
66+
}
67+
68+
void loop() {
69+
if (running) nav.poll();
70+
delay(100);//simulate a delay when other tasks are done
71+
}

examples/Serial/ansiSerial/lib/readme.txt renamed to examples/Confirm/lib/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ PlatformIO will find your libraries automatically, configure preprocessor's
3333
include paths and build them.
3434

3535
More information about PlatformIO Library Dependency Finder
36-
- http://docs.platformio.org/en/stable/librarymanager/ldf.html
36+
- http://docs.platformio.org/page/librarymanager/ldf.html

examples/Confirm/platformio.ini

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; http://docs.platformio.org/page/projectconf.html
10+
11+
[env:nanoatmega328]
12+
platform=atmelavr
13+
board=nanoatmega328
14+
framework=arduino
15+
16+
[platformio]
17+
src_dir=Confirm
18+
lib_dir=~/Arduino/Libraries

examples/Serial/serialio/lib/readme.txt

Lines changed: 0 additions & 36 deletions
This file was deleted.

platformio.ini

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
lib_dir =~/Arduino/libraries
1010
#,/usr/include/c++/5.4.0
1111

12-
;[env:nanoatmega328]
13-
;platform = atmelavr
14-
;board = nanoatmega328
15-
;framework = arduino
12+
[env:nanoatmega328]
13+
platform = atmelavr
14+
board = nanoatmega328
15+
framework = arduino
1616

1717
;[env:teensy31]
1818
;platform = teensy
1919
;board = teensy31
2020
;framework = arduino
2121

22-
[env:nanoatmega328]
23-
platform=atmelavr
24-
board=nanoatmega328
25-
framework=arduino
26-
; build_flags = -Wno-comment -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -DDEBUG
27-
28-
[env:due]
29-
platform = atmelsam
30-
board = due
31-
framework = arduino
32-
; build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing
33-
34-
[env:esp12e]
35-
platform = espressif8266
36-
board = esp12e
37-
framework = arduino
38-
39-
[env:uno]
40-
platform = atmelavr
41-
board = uno
42-
framework = arduino
22+
; [env:nanoatmega328]
23+
; platform=atmelavr
24+
; board=nanoatmega328
25+
; framework=arduino
26+
; ; build_flags = -Wno-comment -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -DDEBUG
27+
;
28+
; [env:due]
29+
; platform = atmelsam
30+
; board = due
31+
; framework = arduino
32+
; ; build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing
33+
;
34+
; [env:esp12e]
35+
; platform = espressif8266
36+
; board = esp12e
37+
; framework = arduino
38+
;
39+
; [env:uno]
40+
; platform = atmelavr
41+
; board = uno
42+
; framework = arduino

0 commit comments

Comments
 (0)