Skip to content

Commit e556fdd

Browse files
committed
conditional use of pgm_read_byte_near
1 parent d907159 commit e556fdd

File tree

3 files changed

+74
-24
lines changed

3 files changed

+74
-24
lines changed

README.md

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ AVR generic menu/interactivity system
1616
- Attachable functions to menu enter (experimental).
1717
- Customizable (colors and cursors).
1818
- Able to work over Serial stream for regular or debug mode.
19+
- modularity, support for different devices in separate include files.
1920

2021
[![IMAGE ALT TEXT](https://img.youtube.com/vi/wHv5sU-HXVI/2.jpg)](https://youtu.be/wHv5sU-HXVI "Arduino menu 2.0 fields video") [![IMAGE ALT TEXT](https://img.youtube.com/vi/W-TRCziF67g/2.jpg)](https://youtu.be/W-TRCziF67g "Arduino menu basic features video")
2122

@@ -42,14 +43,24 @@ https://github.com/olikraus/U8glib_Arduino
4243

4344
Serial https://www.arduino.cc/en/Reference/Serial
4445

45-
Generic encoder using PCINT - quadEncoder
46+
quadEncoder - Generic encoder using PCINT
47+
48+
Buttons - simple digital keyboard
4649

4750
Generic keyboard (no PCINT) - configurable for digital or analog keyboards
4851

49-
ClickEncoder
50-
https://github.com/0xPIT/encoder
52+
ClickEncoder https://github.com/0xPIT/encoder
53+
54+
## Saving memory
55+
Some menu data can be stored on avr programming memory (flash) to save ram for your project.
56+
57+
to activate memory saving put
58+
```c++
59+
#define USEPGM
60+
```
61+
on top of your code before any menu includes.
5162

52-
more details on wiki and issues discussions
63+
this is conditional because some non-avr devices might not supoprt it.
5364

5465
## Menu definition example
5566
example of menu definition (c++ macros)
@@ -136,7 +147,7 @@ the value
136147

137148
#### Field value
138149
```c++
139-
VALUE(text,value)
150+
VALUE(text,value [,action] )
140151
```
141152
142153
holding possible FIELD values
@@ -145,13 +156,15 @@ holding possible FIELD values
145156
146157
**value**: to be passed when selected
147158
159+
**action**: optional function to be called on activation
160+
148161
#### Toggle field value
149162
```c++
150-
TOGGLE(variable,id,name,
151-
VALUE(...),
152-
...,
153-
VALUE(...)
154-
)
163+
TOGGLE(variable,id,name,
164+
VALUE(...),
165+
...,
166+
VALUE(...)
167+
)
155168
```
156169

157170
Holding a value and a list of possible values to toggle on click. This is ideal for On/Off Yes/No and other small list of values
@@ -165,10 +178,10 @@ Holding a value and a list of possible values to toggle on click. This is ideal
165178
#### Select field value
166179
```c++
167180
SELECT(variable,id,name,
168-
VALUE(...),
169-
...,
170-
VALUE(...)
171-
)
181+
VALUE(...),
182+
...,
183+
VALUE(...)
184+
)
172185
```
173186

174187
define a value from a list of possibilities
@@ -185,9 +198,9 @@ click to exit edit mode
185198
#### Choose field value
186199
```c++
187200
CHOOSE(variable,id,name,
188-
VALUE(...),
189-
...,
190-
VALUE(...)
201+
VALUE(...),
202+
...,
203+
VALUE(...)
191204
)
192205
```
193206

@@ -225,23 +238,56 @@ define menu structure
225238

226239
**name**: menu name to use as submenu title
227240

241+
## Include files
242+
243+
**chainStream.h** - join multiple input stream to be used as one
244+
245+
**ClickEncoderStream.h** - using encoder https://github.com/0xPIT/encoder
246+
247+
**genericKeyboard.h** - use a custom keyboard by providing a reader function.
248+
249+
**keyStream.h** - simple digital keyboard driver doing digitalRead of pins. this driver can miss clicks on heavy load.
250+
251+
**macros.h** - macro definitions to help building complex menu structure (included by menu.h)
252+
253+
**menuFields.h** - allows the menu system to alter/monitor your variables, this file defines the behavior of FIELD, TOGGLE, SELECT and CHOOSE.
254+
255+
**menuGFX.h** - use an Adafruit-GFX-Library compatible screen https://learn.adafruit.com/adafruit-gfx-graphics-library
256+
257+
**menu.h** - basic menu functionality
258+
259+
**menuLCD.h** - use the standard arduino LiquidCrystal screen https://www.arduino.cc/en/Tutorial/HelloWorld
260+
261+
**menuLCDs.h** - use alternative LCD`s https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!hardware-configurations-and-initialization
262+
263+
**menuPrint.h** - output to Serial stream numbering options for quick access
264+
265+
**menuU8G.h** - use a U8Glib compatible screen https://github.com/olikraus/u8glib/wiki/device
266+
267+
**menuUTFT.h** - use UTFT compatible screen http://www.rinkydinkelectronics.com/library.php?id=51
268+
269+
**menuUTouch.h** - touch screen input http://henningkarlsen.com/electronics/library.php?id=56
270+
271+
quadEncoder.h - basic quad-encoder driver using pin change interrupt. Button should be added as a keyboard.
272+
228273
## History
229274

230275
### 2.4
231276
- new field type SELECT
232277
- reflexivity, field reflect external changes to values
233-
- field string to progmem
234-
- PROGMEM usage is condicional, #define USEPGM
278+
- store field strings to progmem
279+
- PROGMEM usage is optional, #define USEPGM
235280

236281
### 2.3
237282

238-
- actions functions need to return bool now (only affects menus)
283+
- action functions now need to return bool (only affects menus)
239284

240-
false = continue menu
241-
true = exit menu
285+
>**false** = continue menu
286+
>
287+
>**true** = exit menu
242288
243289
- Support for U8GLib screens
244-
- alternative use of ClickEncoder
290+
- alternative use ClickEncoder
245291
- using flash memory to store menu strings and lists (PROGMEM)
246292

247293
### 2.0

src/macros.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11

22
#ifdef USEPGM
3+
//storing some values into avr flash memory (saving ram space)
34
#include <avr/pgmspace.h>
45
#define MEMMODE PROGMEM
56
#define pgmPtrNear(addr) pgm_read_ptr_near(addr)
7+
#define pgmByteNear(addr) pgm_read_byte_near(addr)
68
#else
9+
//use ram for non-avr devices
710
#define MEMMODE
811
#define pgmPtrNear(addr) (addr)
12+
#define pgmByteNear(addr) (*((byte*)addr))
913
#endif
1014

1115
class prompt;

src/menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ menuNode* menuNode::activeNode=NULL;
3030
void print_P(menuOut& s,const char* at) {
3131
int len=strlen_P(at);
3232
for(;len;len--,at++)
33-
s.write(pgm_read_byte_near(at));
33+
s.write(pgmByteNear(at));
3434
}
3535

3636
bool menuOut::needRedraw(menu& m,int i) {

0 commit comments

Comments
 (0)