Skip to content

Commit 939044b

Browse files
committed
field format example
1 parent 8ba9615 commit 939044b

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed

examples/fieldFormat/.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/fieldFormat/.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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <Arduino.h>
2+
3+
#include <menu.h>
4+
#include <menuIO/serialOut.h>
5+
// #include <Streaming.h>
6+
7+
using namespace Menu;
8+
9+
int test=55;
10+
11+
//custom field print
12+
//implementing a customized menu component
13+
//this numeric field prints formatted number with leading zeros
14+
template<typename T>
15+
class leadsField:public menuField<T> {
16+
public:
17+
leadsField(const menuFieldShadow<T>& shadow):menuField<T>(shadow) {}
18+
idx_t printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len) {
19+
menuField<T>::reflex=menuField<T>::target();
20+
prompt::printTo(root,sel,out,idx,len);
21+
bool ed=this==root.navFocus;
22+
out.print((root.navFocus==this&&sel)?(menuField<T>::tunning?'>':':'):' ');
23+
out.setColor(valColor,sel,menuField<T>::enabled,ed);
24+
char buffer[]=" ";
25+
sprintf(buffer, "%03d", menuField<T>::reflex);
26+
out.print(buffer);
27+
out.setColor(unitColor,sel,menuField<T>::enabled,ed);
28+
print_P(out,menuField<T>::units(),len);
29+
return len;
30+
}
31+
};
32+
33+
//a menu using a customized components
34+
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
35+
,altFIELD(leadsField,test,"Custom edit","%",0,100,10,1,doNothing,enterEvent,wrapStyle)
36+
,FIELD(test,"Original edit","%",0,100,10,1,doNothing,noEvent,wrapStyle)
37+
);
38+
39+
#define MAX_DEPTH 1
40+
41+
MENU_OUTPUTS(out,MAX_DEPTH
42+
,SERIAL_OUT(Serial)
43+
,NONE//must have 2 items at least
44+
);
45+
46+
NAVROOT(nav,mainMenu,MAX_DEPTH,Serial,out);
47+
48+
void setup() {
49+
Serial.begin(115200);
50+
while(!Serial);
51+
Serial.println("menu 4.x testing custom fields");
52+
Serial.flush();
53+
}
54+
55+
void loop() {
56+
nav.poll();
57+
delay(100);//simulate a delay when other tasks are done
58+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
[platformio]
12+
src_dir=fieldFormat
13+
lib_dir=~/Arduino/Libraries
14+
15+
[env:esp12e]
16+
platform = espressif8266
17+
board = esp12e
18+
framework = arduino
19+
upload_speed=921600
20+
build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -lstdc++ -DDEBUG -DNOTRACE
21+
22+
; [env:nanoatmega328]
23+
; platform=atmelavr
24+
; board=nanoatmega328
25+
; framework=arduino
26+
; upload_port=/dev/ttyUSB*
27+
; upload_flags=-V
28+
; build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -DDEBUG -DMENU_USERAM
29+
30+
; [env:teensy31]
31+
; platform = teensy
32+
; board = teensy31
33+
; framework = arduino
34+
; build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -DDEBUG
35+
36+
; [env:due]
37+
; platform = atmelsam
38+
; board = due
39+
; framework = arduino
40+
; build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -DDEBUG
41+
42+
; [env:esp01_1m]
43+
; platform = espressif8266
44+
; board = esp01_1m
45+
; framework = arduino
46+
; build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -DDEBUG

0 commit comments

Comments
 (0)