Skip to content

Commit b1cec59

Browse files
committed
macro set validtor length
recycles ok
1 parent 3388a1c commit b1cec59

5 files changed

Lines changed: 36 additions & 22 deletions

File tree

‎examples/TextField/platformio.ini‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@
1212
src_dir=TextField
1313
lib_dir=~/Arduino/Libraries
1414

15-
[env:nanoatmega328]
15+
; [env:nanoatmega328]
16+
; platform=atmelavr
17+
; board=nanoatmega328
18+
; framework=arduino
19+
; upload_port=/dev/ttyUSB0
20+
21+
[env:atmega328_8]
1622
platform=atmelavr
17-
board=nanoatmega328
23+
board=pro8MHzatmega328
1824
framework=arduino
19-
upload_port=/dev/ttyUSB0
25+
upload_protocol = usbasp
26+
upload_flags = -Pusb
27+
build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -lstdc++ -DDEBUG
2028

2129
; [env:teensy31]
2230
; platform = teensy

‎examples/plugins/platformio.ini‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ board=pro8MHzatmega328
3030
framework=arduino
3131
upload_protocol = usbasp
3232
upload_flags = -Pusb
33+
build_flags = -Wno-comment -Wno-reorder -Wno-strict-aliasing -Wno-builtin-macro-redefined -Wno-strict-aliasing -DDEBUG
3334

3435
; [env:teensy31]
3536
; platform = teensy

‎examples/plugins/plugins/plugins.ino‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ ITEM macro, like OP but do allow custom system styles and extra arguments at end
2929
#include <Arduino.h>
3030

3131
#include <menu.h>
32+
#ifdef DEBUG
33+
#include <Dump.h>
34+
#endif
3235

3336
//inputs
3437
#include <menuIO/encoderIn.h>
@@ -74,28 +77,18 @@ softKeyIn<1> encButton(encBtn_map);//1 is the number of keys
7477
Stream* inputsList[]={&encStream,&encButton,&Serial};
7578
chainStream<3> in(inputsList);//3 is the number of inputs
7679

77-
void dot() {Serial.print("+");}
78-
79-
char* const hexChars PROGMEM="0123456789ABCDEF";
80-
char* constMEM validData[] PROGMEM={hexChars,hexChars};//individual character validators
81-
82-
constMEM char op1Text[] PROGMEM="Name";//field name
83-
constMEM textFieldShadowRaw op1InfoRaw PROGMEM={(callback)doNothing,(Menu::systemStyles)(_noStyle|_canNav|_parentDraw),op1Text,enterEvent,noStyle,2,validData};//PROGMEM static stuff
84-
constMEM textFieldShadow& op1Info=*(textFieldShadow*)&op1InfoRaw;//hacking c++ to use progmem (hugly)
85-
textField op1("AA",op1Info);//text length not enforced to match validators length yet
80+
char* const hexDigit PROGMEM="0123456789ABCDEF";
81+
char* const hexNr[] PROGMEM={"0","x",hexDigit,hexDigit};
82+
char buf1[]="0x11";
8683

8784
//a menu using a plugin field
8885
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
86+
,BARFIELD(test,"Bar field","%",0,100,10,1,doNothing,noEvent,wrapStyle)//numeric field with a bar
8987
,FIELD(test,"Original","%",0,100,10,1,doNothing,noEvent,wrapStyle)//normal numeric field (2 edit levels)
9088
,FIELD(test,"O. Simple","%",0,100,1,0,doNothing,noEvent,wrapStyle)//normal numeric field (1 edit level)
9189
,altFIELD(cancelField,test,"Cancelable","%",0,100,10,1,doNothing,enterEvent,wrapStyle)//cancelable field (2 edit levels)
9290
,altFIELD(cancelField,test,"C. Simple","%",0,100,1,0,doNothing,enterEvent,wrapStyle)//cancelable field (1 edit level)
93-
// ,EDIT(barField,test,"Bar field","%",0,100,10,1,doNothing,noEvent,wrapStyle)//numeric field with a bar
94-
//,altFIELD(barField,test,"Bar field","%",0,100,10,1,doNothing,noEvent,wrapStyle)//numeric field with a bar
95-
,BARFIELD(test,"Bar field","%",0,100,10,1,doNothing,noEvent,wrapStyle)//numeric field with a bar
96-
//,ITEM(textEdit,"Text",doNothing,noEvent,_canNav,name)
97-
,OBJ(op1)
98-
,OP("Empty 0",dot,enterEvent)//just an empty regular option
91+
,EDIT("Hex",buf1,hexNr,doNothing,noEvent,noStyle)
9992
,EXIT("<Exit")
10093
);
10194

@@ -116,7 +109,7 @@ void setup() {
116109
encoder.begin();
117110
lcd.begin(16,2);
118111
lcd.setCursor(0, 0);
119-
lcd.print("Menu 3.0 LCD");
112+
lcd.print("Menu 3.x LCD");
120113
lcd.setCursor(0, 1);
121114
lcd.print("r-site.net");
122115
options->numValueInput=false;//numeric keys in fields used as accelerators instead
@@ -126,9 +119,12 @@ void setup() {
126119
//barFieldOptions::empty="░";//if not stick with the defaults
127120
cancelFieldOptions::quitOnEsc=true;
128121
cancelFieldOptions::accelSendEsc=true;//normal is enter
122+
#ifdef DEBUG
123+
dumpPgm(Serial,(textFieldShadowRaw*)mainMenu[5].shadow,sizeof(textFieldShadowRaw));
124+
#endif
129125
}
130126

131127
void loop() {
132128
nav.poll();
133-
delay(100);//simulate a delay when other tasks are done
129+
delay(100);//simulate other tasks delay
134130
}

‎src/macros.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Menu::outputsList id(id##_outPtrs,sizeof(id##_outPtrs)/sizeof(Menu::menuOut*));
252252
style,\
253253
buf,\
254254
valid,\
255-
sizeof(buf)-1\
255+
sizeof(valid)/sizeof(char*)\
256256
};\
257257
constMEM Menu::textFieldShadow& _fieldShadow##cnt=*(Menu::textFieldShadow*)&textFieldShadowRaw##cnt;\
258258
objType _textField##cnt(_fieldShadow##cnt);

‎src/menu.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,16 @@ for correcting unsigned values validation
126126
textField(constMEM textFieldShadow& shadow):navTarget(shadow) {}
127127
inline char* buffer() const {return ((textFieldShadow*)shadow)->_buffer();}
128128
inline idx_t sz() const {return ((textFieldShadow*)shadow)->_sz();}
129-
const char* validator(int i) {return ((textFieldShadow*)shadow)->operator[](i%sz());}
129+
const char* validator(int i) {
130+
Serial.println();
131+
Serial.print("validator idx:");
132+
Serial.print(i);
133+
Serial.print("validators sz:");
134+
Serial.print(sz());
135+
Serial.print("sel validator:");
136+
Serial.println(i%sz());
137+
return ((textFieldShadow*)shadow)->operator[](i%sz());
138+
}
130139
void doNav(navNode& nav,navCmd cmd) override;
131140
idx_t printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len) override;
132141
};

0 commit comments

Comments
 (0)