Skip to content

Commit 6b67f76

Browse files
committed
fixing ram mode (teensy)
#40
1 parent 5816ea5 commit 6b67f76

File tree

12 files changed

+72
-26
lines changed

12 files changed

+72
-26
lines changed

lib/readme.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
This directory is intended for the project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link to executable file.
4+
5+
The source code of each library should be placed in separate directory, like
6+
"lib/private_lib/[here are source files]".
7+
8+
For example, see how can be organized `Foo` and `Bar` libraries:
9+
10+
|--lib
11+
| |--Bar
12+
| | |--docs
13+
| | |--examples
14+
| | |--src
15+
| | |- Bar.c
16+
| | |- Bar.h
17+
| |--Foo
18+
| | |- Foo.c
19+
| | |- Foo.h
20+
| |- readme.txt --> THIS FILE
21+
|- platformio.ini
22+
|--src
23+
|- main.c
24+
25+
Then in `src/main.c` you should use:
26+
27+
#include <Foo.h>
28+
#include <Bar.h>
29+
30+
// rest H/C/CPP code
31+
32+
PlatformIO will find your libraries automatically, configure preprocessor's
33+
include paths and build them.
34+
35+
See additional options for PlatformIO Library Dependency Finder `lib_*`:
36+
37+
http://docs.platformio.org/en/stable/projectconf.html#lib-install
38+

platformio.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# PlatformIO Project Configuration File
3+
#
4+
# Please make sure to read documentation with examples first
5+
# http://docs.platformio.org/en/stable/projectconf.html
6+
#
7+
[env:nanoatmega328]
8+
platform = atmelavr
9+
framework = arduino
10+
board = nanoatmega328

src/macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#ifdef pgm_read_ptr_near
44
//storing some values into avr flash memory (saving ram space)
55
#define MEMMODE PROGMEM
6-
#define pgmPtrNear(addr) pgm_read_ptr_near(addr)
6+
#define pgmPtrNear(addr) pgm_read_ptr_near(&(addr))
77
#define pgmByteNear(addr) (pgm_read_byte_near(addr))
88
#else
99
//use ram for non-avr devices
1010
#define MEMMODE
1111
#define pgmPtrNear(addr) (addr)
12-
#define pgmByteNear(addr) (*addr)
12+
#define pgmByteNear(addr) (*(addr))
1313
#endif
1414

1515
class prompt;

src/menu.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@ menuNode* menuNode::activeNode=NULL;
3636

3737
//PROGMEM AUX PRINT
3838
void print_P(menuOut& s,const char* at) {
39-
int len=strlen_P(at);
40-
for(;len;len--,at++)
41-
s.write(pgmByteNear(at));
39+
while(uint8_t ch=pgmByteNear(at++)) s.write(ch);
4240
}
4341

4442
bool menuOut::needRedraw(menu& m,int i) {
4543
return
4644
(drawn!=&m)//menu changed
4745
||(top!=lastTop)//screen scrolled
4846
||(m.sel!=lastSel&&((i==m.sel)||(i==lastSel)))//selection changed
49-
||((prompt*)pgmPtrNear(&m.data[i]))->needRedraw(*this,i==m.sel);//reflexivity, value changed
47+
||((prompt*)pgmPtrNear(m.data[i]))->needRedraw(*this,i==m.sel);//reflexivity, value changed
5048
}
5149

5250
//menu navigation engine
@@ -116,7 +114,7 @@ promptFeedback menu::activate(menuOut& p,Stream& c,bool canExit) {
116114
op=menuKeys(p,c,canExit);
117115
if (op>=0&&op<sz) {
118116
sel=op;
119-
prompt* cp=(prompt*)pgmPtrNear(&data[op]);
117+
prompt* cp=(prompt*)pgmPtrNear(data[op]);
120118
if (cp->enabled) {
121119
printMenu(p,canExit);//clearing old selection
122120
if (cp->activate(p,c,true)) {

src/menu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ v2.1 - Add full support of SetPosition(x,y) to move the menu inside the screen (
169169
bool canExit;//store last canExit value for inner reference
170170
menu(const char * text,int sz,prompt* const data[]):menuNode(text),sz(sz),data(data),canExit(false) {}
171171

172-
inline prompt& operator[](int i) {return *(prompt*)pgmPtrNear(&data[i]);}
172+
inline prompt& operator[](int i) {return *(prompt*)pgmPtrNear(data[i]);}
173173
inline void setPosition(int x,int y) {ox=x;oy=y;}
174174
int menuKeys(menuOut &p,Stream& c,bool drawExit);
175175
inline void printMenu(menuOut& p,bool drawExit=false) {

src/menuFields.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,22 @@ v2.0 - Calling action on every elements
135135
menuVariant(T& target,const char *text,unsigned int sz,menuValue<T>* const data[]):
136136
menu(text,sz,(prompt**)data),target(target) {sync();}
137137
virtual bool needRedraw(menuOut&p,bool selected) {
138-
bool nr=((menuValue<T>*)pgmPtrNear(&data[sel]))->value!=target;//||p.lastSel!=sel;
139-
//T v=((menuValue<T>*)pgmPtrNear(&data[sel]))->value;
138+
bool nr=((menuValue<T>*)pgmPtrNear(data[sel]))->value!=target;//||p.lastSel!=sel;
139+
//T v=((menuValue<T>*)pgmPtrNear(data[sel]))->value;
140140
//if (nr) Serial<<"Variant need redraw:"<<*this<<endl<<"value:"<<v<<" target:"<<target<<" sel:"<<sel<<" lastSel:"<<p.lastSel<<endl;;
141141
return nr;
142142
}
143143
void sync() {//if possible make selection match the target value
144144
sel=0;
145145
for(int n=0;n<sz;n++)
146-
if (((menuValue<T>*)pgmPtrNear(&data[n]))->value==target)
146+
if (((menuValue<T>*)pgmPtrNear(data[n]))->value==target)
147147
sel=n;
148148
}
149149
virtual void printTo(menuOut& p) {
150150
menuVariant<T>::sync();
151151
print_P(p,text);
152-
((prompt*)pgmPtrNear(&data[sel]))->printTo(p);
153-
//print_P(p,((menuValue<T>*)pgmPtrNear(&data[sel]))->text);
152+
((prompt*)pgmPtrNear(data[sel]))->printTo(p);
153+
//print_P(p,((menuValue<T>*)pgmPtrNear(data[sel]))->text);
154154
}
155155
};
156156

@@ -164,8 +164,8 @@ v2.0 - Calling action on every elements
164164
menuVariant<T>(target,text,sz,data) {menuVariant<T>::sync();}
165165
virtual bool needRedraw(menuOut&p,bool selected) {
166166
if (selected) {
167-
bool nr=lastDrawnOp!=menu::sel;//||((menuValue<T>*)pgmPtrNear(&menu::data[menu::sel]))->value==menuVariant<T>::target;
168-
//T v=((menuValue<T>*)pgmPtrNear(&menu::data[menu::sel]))->value;
167+
bool nr=lastDrawnOp!=menu::sel;//||((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value==menuVariant<T>::target;
168+
//T v=((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value;
169169
//if (nr) Serial<<"Variant need redraw:"<<*this<<endl
170170
/*Serial
171171
<<" value:"<<v<<endl
@@ -178,13 +178,13 @@ v2.0 - Calling action on every elements
178178
lastDrawnOp=menu::sel;
179179
return nr;
180180
}
181-
return ((menuValue<T>*)pgmPtrNear(&menu::data[menu::sel]))->value!=menuVariant<T>::target;
181+
return ((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value!=menuVariant<T>::target;
182182
}
183183
virtual void printTo(menuOut& p) {
184184
//Serial<<"drawing menuSelect"<<endl;
185185
print_P(p,menu::text);
186186
p.print(menu::activeNode==this?':':' ');
187-
((prompt*)pgmPtrNear(&menu::data[menu::sel]))->printTo(p);
187+
((prompt*)pgmPtrNear(menu::data[menu::sel]))->printTo(p);
188188
}
189189
promptFeedback activate(menuOut& p,Stream& c,bool) {
190190
if (menu::activeNode!=this) {
@@ -203,7 +203,7 @@ v2.0 - Calling action on every elements
203203
if (op>=0&&op<this->menu::sz) {
204204
//Serial<<"Selecting op:"<<op<<endl;
205205
this->menu::sel=op;
206-
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(&this->menu::data[op]);
206+
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(this->menu::data[op]);
207207
if (cp->enabled) {
208208
this->menuVariant<T>::target=cp->value;
209209
cp->activate(p,c,true);
@@ -240,7 +240,7 @@ v2.0 - Calling action on every elements
240240
op=menu::menuKeys(p,c,false);
241241
if (op>=0&&op<this->menu::sz) {
242242
this->menu::sel=op;
243-
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(&this->menu::data[op]);
243+
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(this->menu::data[op]);
244244
if (cp->enabled) {
245245
this->menuVariant<T>::target=cp->value;
246246
cp->activate(p,c,true);
@@ -264,7 +264,7 @@ v2.0 - Calling action on every elements
264264
this->menu::sel++;
265265
if (this->menu::sel>=this->menu::sz) this->menu::sel=0;
266266
p.lastSel=-1;//redraw only affected option
267-
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(&this->menu::data[menu::sel]);
267+
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(this->menu::data[menu::sel]);
268268
this->menuVariant<T>::target=cp->value;
269269
cp->activate(p,c,true);
270270
return 0;

src/menuGFX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ www.r-site.net
7979
int i=top;for(;i<m.sz;i++) {
8080
if(i-top>=maxY) break;
8181
if (needRedraw(m,i)) {
82-
printPrompt(*(prompt*)pgmPtrNear(&m.data[i]),i==m.sel,i+1,0,i-top,m.width);
82+
printPrompt(*(prompt*)pgmPtrNear(m.data[i]),i==m.sel,i+1,0,i-top,m.width);
8383
}
8484
}
8585
if (drawExit&&i-top<maxY&&needRedraw(m,i))

src/menuLCD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ www.r-site.net
4444
int i=0;for(;i<m.sz;i++) {
4545
if ((i>=top)&&((i-top)<maxY)) {
4646
if (needRedraw(m,i)) {
47-
printPrompt(*(prompt*)pgmPtrNear(&m.data[i]),i==m.sel,i+1,0,i-top,m.width);
47+
printPrompt(*(prompt*)pgmPtrNear(m.data[i]),i==m.sel,i+1,0,i-top,m.width);
4848
}
4949
}
5050
}

src/menuLCDs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ www.r-site.net
4444
int i=top;for(;i<m.sz;i++) {
4545
if(i-top>=maxY) break;
4646
if (needRedraw(m,i))
47-
printPrompt(*(prompt*)pgmPtrNear(&m.data[i]),i==m.sel,i+1,i-top,m.width);
47+
printPrompt(*(prompt*)pgmPtrNear(m.data[i]),i==m.sel,i+1,i-top,m.width);
4848
}
4949
if (drawExit&&i-top<maxY&&needRedraw(m,i))
5050
printPrompt(menu::exitOption,m.sel==m.sz,0,i-top,m.width);

src/menuPrint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ www.r-site.net
3535
clear();
3636
int i=0;
3737
for(;i<m.sz;i++)
38-
printPrompt(*(prompt*)pgmPtrNear(&m.data[i]),i==m.sel,i+1,i-top,0,m.width);
38+
printPrompt(*(prompt*)pgmPtrNear(m.data[i]),i==m.sel,i+1,i-top,0,m.width);
3939
if (drawExit) printPrompt(menu::exitOption,m.sel==m.sz,i,0,i-top,m.width);
4040
lastTop=top;
4141
lastSel=m.sel;

0 commit comments

Comments
 (0)