Skip to content

Commit d548f7c

Browse files
committed
fixing examples memory allocation on AVR's
some examples that do not use macros run well on non-avr devices but have mesleading memory allocation mode
1 parent 7ee18f6 commit d548f7c

File tree

10 files changed

+24
-18
lines changed

10 files changed

+24
-18
lines changed

examples/LCDs/LiquidCrystal/LiquidCrystal/LiquidCrystal.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
153153
#define MAX_DEPTH 2
154154
/*idx_t tops[MAX_DEPTH];
155155
liquidCrystalOut outLCD(lcd,tops,pList);//output device for LCD
156-
menuOut* outputs[]={&outLCD};//list of output devices
156+
menuOut* constMEM outputs[] MEMMODE={&outLCD};//list of output devices
157157
outputsList out(outputs,1);//outputs list with 2 outputs*/
158158

159159
MENU_OUTPUTS(out, MAX_DEPTH

examples/LCDs/Malpartida/I2C/I2C/I2C.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ http://playground.arduino.cc/Code/LCD3wires
157157
panelsList pList(panels,nodes,1);
158158
idx_t tops[MAX_DEPTH];
159159
lcdOut outLCD(&lcd,tops,pList);//output device for LCD
160-
menuOut* outputs[]={&outLCD};//list of output devices
160+
menuOut* constMEM outputs[] MEMMODE={&outLCD};//list of output devices
161161
outputsList out(outputs,1);//outputs list with 2 outputs
162162
*/
163163

examples/SSD1306Ascii/SSD1306Ascii/SSD1306Ascii.ino

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <menu.h>
1111
#include <menuIO/SSD1306AsciiOut.h>
12-
#include <menuIO/serialIn.h>
12+
#include <menuIO/serialIO.h>
1313
using namespace Menu;
1414

1515
SSD1306AsciiWire oled;
@@ -73,15 +73,15 @@ class altPrompt:public prompt {
7373
public:
7474
altPrompt(constMEM promptShadow& p):prompt(p) {}
7575
Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t) override {
76-
return out.printRaw(F("special prompt!"),len);
76+
return out.printRaw(F( "special prompt!"),len);
7777
}
7878
};
7979

8080
MENU(subMenu,"Sub-Menu",showEvent,anyEvent,noStyle
8181
,OP("Sub1",showEvent,anyEvent)
8282
,OP("Sub2",showEvent,anyEvent)
8383
,OP("Sub3",showEvent,anyEvent)
84-
,altOP(altPrompt,"",showEvent,anyEvent)
84+
// ,altOP(altPrompt,"",showEvent,anyEvent)
8585
,EXIT("<Back")
8686
);
8787

@@ -104,15 +104,19 @@ MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
104104
#define fontW 5
105105
#define fontH 8
106106

107+
//define output device
108+
idx_t serialTops[MAX_DEPTH]={0};
109+
serialOut outSerial(Serial,serialTops);
110+
107111
//describing a menu output device without macros
108112
//define at least one panel for menu output
109113
constMEM panel panels[] MEMMODE={{0,0,128/fontW,64/fontH}};
110114
navNode* nodes[sizeof(panels)/sizeof(panel)];//navNodes to store navigation status
111115
panelsList pList(panels,nodes,1);//a list of panels and nodes
112116
idx_t tops[MAX_DEPTH]={0,0};//store cursor positions for each level
113117
SSD1306AsciiOut outOLED(&oled,tops,pList);//oled output device menu driver
114-
menuOut* outputs[]={&outOLED};//list of output devices
115-
outputsList out(outputs,1);//outputs list
118+
menuOut* constMEM outputs[] MEMMODE ={&outSerial,&outOLED,};//list of output devices
119+
outputsList out(outputs,sizeof(outputs)/sizeof(menuOut*));//outputs list
116120

117121
//macro to create navigation control root object (nav) using mainMenu
118122
serialIn serial(Serial);
@@ -154,8 +158,8 @@ void setup() {
154158
oled.begin(&Adafruit128x64, I2C_ADDRESS);
155159
oled.setFont(System5x7);
156160
oled.clear();
157-
oled.print("Hello world!");
158-
nav.idleTask=idle;//point a function to be used when menu is suspended
161+
oled.print("menu 4.x test");
162+
// nav.idleTask=idle;//point a function to be used when menu is suspended
159163
}
160164

161165
void loop() {

examples/SSD1306Ascii/platformio.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ platform = atmelavr
1616
board = nanoatmega328
1717
framework = arduino
1818
upload_port=/dev/ttyUSB*
19-
upload_flags=-V
19+
; upload_flags=-V
2020
upload_speed=57600
21-
build_flags = -DNODEBUG
21+
build_flags = -DMENU_DEBUG
22+
src_build_flags = !echo "-Wno-write-strings -Wno-reorder -DLOC="$PLATFORMIO_LOC
2223

2324
; [env:teensy31]
2425
; platform = teensy

examples/Serial/ansiSerial/ansiSerial/ansiSerial.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const colorDef<uint8_t> colors[] MEMMODE={
5454
// panelsList pList(panels,nodes,sizeof(panels)/sizeof(panel));
5555
// idx_t ansi_tops[MAX_DEPTH];
5656
// ansiSerialOut ansi(Serial,colors,ansi_tops,pList);//the output device, ansi-terminal Cols x Rows
57-
// menuOut* outputs[]={&ansi};
57+
// menuOut* constMEM outputs[] MEMMODE={&ansi};
5858
// outputsList out(outputs,1);
5959

6060
MENU_OUTPUTS(out,MAX_DEPTH

examples/clickEncoder/clickEncoder/clickEncoder.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
143143

144144
#define MAX_DEPTH 2
145145

146-
/*const panel panels[] MEMMODE={{0,0,16,2}};
146+
/*constMEM panel panels[] MEMMODE={{0,0,16,2}};
147147
navNode* nodes[sizeof(panels)/sizeof(panel)];
148148
panelsList pList(panels,nodes,1);
149149
idx_t tops[MAX_DEPTH];
150150
lcdOut outLCD(&lcd,tops,pList);//output device for LCD
151-
menuOut* outputs[]={&outLCD};//list of output devices
151+
menuOut* constMEM outputs[] MEMMODE={&outLCD};//list of output devices
152152
outputsList out(outputs,1);//outputs list with 2 outputs
153153
*/
154154

examples/dynamic/dynamic/dynamic.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ idx_t tops[MAX_DEPTH];
131131
serialOut out(Serial,tops);
132132

133133
//outputs -------------------------------------
134-
menuOut* outList[]={&out};
134+
menuOut* constMEM outList[] MEMMODE={&out};
135135
outputsList outs(outList,sizeof(outList)/sizeof(menuOut*));
136136

137137
//navigation control -------------------------------------

src/items.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Used prompt::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,id
3838
// out.fmtStart(*this,menuOut::fmtBody,root.node(),idx);
3939
// #endif
4040
if (root.node().target==this) {
41-
trace(MENU_DEBUG_OUT<<"printMenu"<<endl);
41+
trace(MENU_DEBUG_OUT<<"calling printMenu"<<endl);
4242
out.printMenu(root.node(), panelNr);
4343
} else {
4444
trace(MENU_DEBUG_OUT<<"previewMenu"<<endl);

src/menuIo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ idx_t gfxOut::editCursor(navRoot& root,idx_t x,idx_t y,bool editing,bool charEdi
137137
}
138138

139139
Used outputsList::printMenu(navNode& nav) const {
140-
trace(MENU_DEBUG_OUT<<"outputsList::printMenu"<<endl);
140+
trace(MENU_DEBUG_OUT<<"outputsList::printMenu"<<endl;MENU_DEBUG_OUT.flush());
141141
for(int n=0;n<cnt;n++) {
142142
menuOut& o=*((menuOut*)memPtr(outs[n]));
143143
if (nav.changed(o)||(o.style&(menuOut::rasterDraw))||(o.style&(menuOut::redraw)))

src/nav.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void navRoot::useMenu(menuNode &menu) {
132132
}
133133

134134
Used navRoot::printMenu() const {
135-
trace(MENU_DEBUG_OUT<<"navRoot::printMenu"<<endl);
135+
trace(MENU_DEBUG_OUT<<"printMenu()"<<endl);
136136
if ((active().sysStyles()&_parentDraw)&&level)
137137
return out.printMenu(path[level-1]);
138138
else return out.printMenu(node());
@@ -155,6 +155,7 @@ void navRoot::doInput(menuIn& in) {
155155
}
156156

157157
void navRoot::doOutput() {
158+
trace(Serial<<"navRoot::doOutput "<<(int)sleepTask<<endl);
158159
if (!sleepTask) printMenu();
159160
else {
160161
bool c=idleChanged;

0 commit comments

Comments
 (0)