Pages: 1 [2]   Go Down
Author Topic: Compare progmem string  (Read 2034 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks, I will do as you say.

I'm starting to make a menu, could you tell me if this make any sense.
I will use "parent_id" to relate sub-menus with menus and "action" to choose what function to call

#include <avr/pgmspace.h>
prog_char txt_0[] PROGMEM = "Menu 1";     prog_char parent_id_0[] PROGMEM = "0";  prog_char action_0[] PROGMEM = "ActionMenu1";
prog_char txt_1[] PROGMEM = "Menu 2";     prog_char parent_id_1[] PROGMEM = "0";  prog_char action_1[] PROGMEM = "";
prog_char txt_2[] PROGMEM = "Menu 2.1";  prog_char parent_id_2[] PROGMEM = "1";  prog_char action_2[] PROGMEM = "ActionMenu2.1";
prog_char txt_3[] PROGMEM = "Menu 2.2";  prog_char parent_id_3[] PROGMEM = "1";  prog_char action_3[] PROGMEM = "ActionMenu2.2";
prog_char txt_4[] PROGMEM = "Go Back";    prog_char parent_id_4[] PROGMEM = "1";  prog_char action_4[] PROGMEM = "Back";
prog_char txt_5[] PROGMEM = "Menu 3";     prog_char parent_id_5[] PROGMEM = "0";  prog_char action_5[] PROGMEM = "ActionMenu3";



PROGMEM const char *txt_table[] ={ txt_0, txt_1, txt_2, txt_3, txt_4, txt_5 };
PROGMEM const char *parent_id_table[] ={ parent_id_0, parent_id_1, parent_id_2, parent_id_3, parent_id_4, parent_id_5 };
PROGMEM const char *actions_table[] ={ action_0, action_1, action_2, action_3, action_4, action_5 };

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could probably save yourself some typing by defining a "struct" for those items, assuming they are all associated.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could probably save yourself some typing by defining a "struct" for those items, assuming they are all associated.

Forgive my ignorance, but what do you mean by defining a "struct" ?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A "struct" is a useful way of grouping related items of different types:
http://en.wikipedia.org/wiki/Struct_%28C_programming_language%29
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can I use a struct with PROGMEM ?
The only benefict will be save me some typing?

Can you give me an example of a struct for my menu, or is it too much to ask?

Thank you for all.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, the other benefits include potentially easier debugging and simpler function definitions.

I don't know the structure of your menu, but yes, you can put "struct"s into flash memory.
If you look at the Playground, you should find some examples, I think.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will do the search...

Each ítem on my menu have only 4 vars

ID and Position on the menu: I use is position on the array
txt: the text displayed
action: if is empty I list all the elements on the array that have parent_id equal to actual menu id, if as something I will call the function with that name
parent_id: contains the id of is father. with this var I can have a multi-level menu. I first list all the elements that parent_id=0 then I list all the elements that the parent_id= Id of the selected menu, and so on ...

prog_char txt_0[] PROGMEM = "Menu 1";         prog_char parent_id_0[] PROGMEM = "0";      prog_char action_0[] PROGMEM = "";
   prog_char txt_1[] PROGMEM = "Menu 1.1";        prog_char parent_id_1[] PROGMEM = "1";    prog_char action_1[] PROGMEM = "Action1.1";
   prog_char txt_2[] PROGMEM = "Menu 1.2";        prog_char parent_id_2[] PROGMEM = "1";    prog_char action_2[] PROGMEM = "";
      prog_char txt_3[] PROGMEM = "Menu 1.2.1";     prog_char parent_id_3[] PROGMEM = "2";     prog_char action_3[] PROGMEM = "Action1.2.1";
      prog_char txt_4[] PROGMEM = "Go Back";         prog_char parent_id_4[] PROGMEM = "2";      prog_char action_4[] PROGMEM = "Back";
   prog_char txt_5[] PROGMEM = "Menu 1.3";        prog_char parent_id_5[] PROGMEM = "1";    prog_char action_5[] PROGMEM = "Action1.3";
   prog_char txt_6[] PROGMEM = "Go Back";         prog_char parent_id_6[] PROGMEM = "1";     prog_char action_6[] PROGMEM = "Back";
prog_char txt_7[] PROGMEM = "Menu 2";         prog_char parent_id_7[] PROGMEM = "0";      prog_char action_7[] PROGMEM = "Action2";
...

Logged

Pages: 1 [2]   Go Up
Jump to: