Menu for Display

Thanks for the information,
I've intercept the issues ... I've change the type of variable from uint8_t to byte ...
the logical part was ok, but probably there was a "memory overlapping" between variable ... is possible ?

Thanks I'll let you know about the next steps :slight_smile:

ps it's pleasure working with your library :slight_smile:

thanks
gnux

Ciao Oliver,
during the weekend, I've thought how to use ... so I'll try to use a mixed mode to put &null element to display for disable the menu and then enable the menu again ...

So, Id like to do is also ... so now i didn't have the exit button ... and for didn't wasting memory I was thing to this:

I want that when I'm inside my menu when I click on something the menu will go on the welcome screen ...
for do that I've thing to put a "Exit" voices into the menu is possible ? Is possible also do something without didn't a sub menu ? so for example to the voice exit when I click the select but will go directly to welcome screen ...

Thanks for the information :slight_smile:

warm regards,
gnux

Hi

This should work with the "HOME" button. This means, do not use the Exit button, but instead the HOME button (M2_KEY_HOME). Assign the "home" menu with setHome(). This also could be the &null element.

Oliver

Good Morning Oliver,
And for do that I need physically another button correct ? :slight_smile: so it's very complete your menu ! Many Congratulations ... !!! :slight_smile: So I promise to you that when I'll finish the project I'll send to you a gift :slight_smile: please send to me in private if you want without you I was completely lost ...

So the final things that I want do for the moment is that ... in attachment you can see a a combo menu ... I've take this simple example from a library ... one time that i will press ok I will store the value devices and the "Is" name (only the index) inside my array ... for example like this:

array[0][13] = idx;
array[0][0] = &u8num;

Then I would like retrieve this value inside another menù:
I would like that for example when I'm inside the menu device when I click on "Dev: 01" Will appear kitchen ...
In this way I can say what Im managing ...

Could be possible for you ? make sense ? :slight_smile:

Thanks again :slight_smile:
gnux

Schermata 2013-02-20 a 07.19.48.png

I think can I use
M2_LABELFN();
:slight_smile:

looking the tutorial seems fine :slight_smile:
correct ?

regards,
gnux

Hi

You do not need another button. Replace the one for the Exit with the Home Button: Exchange EXIT with HOME...

And yes, M2_LABELFN will do the job.
A one or two pictures of your device would be the best reward that i can imagine.

Oliver

hi Oliver,
i will add another button like home button because at the moment im using only next and select pin :slight_smile:

so now after a few times that i use the tutorial it's more clear it a very good library :slight_smile:

for is there a way for calculate how many variable can i use and in which part of memory are stored ? for example u8int ?
thanks 100000 :slight_smile:

Hi

You can calculate the amount of initially occupied RAM and ROM memory.
Use "avr-size" for this task. You need to locate and find the .elf file on your file system.

Also, have a look here: avr-libc: Memory Areas and Using malloc()
Variables are usually stored in .data or .bss area. This depends on there init value.

Oliver

Great Thanks you !

So, I did you this questions because this morning i was doing the final menu and one time that I've the third menu the has stop to work ... I've tried both in serial and on lcd ... removing this menu everything was working ok ... and my sketch is only 25000 I've avaiable again 8000 byte if i not wrong ... also taking another menu from an example is the same ...

do you have any suggest for fix it ?

thanks
gnux

for sure the code seems correct ... I didn't see any big changes between the other only I've used 2 Label function ... so in 4 hour that im working on that I've tried a lot's of thing change variable type from u8int to char ... but nothing to do ... Now I go for launch because Im completely fuse ...
thanks for help me,
gnux

Also I've looked inside the tutorial for pass value to the call back procedure for M2_LABELFN I but I didn't find a way :frowning: so could be more useful :slight_smile: below you can find the code ...
if i try to pass parameter I've back a issues with the conversion for sure i wrong to pass it ...

const char *label_what(m2_rom_void_p element)
{  

  switch (array[u8dev][13]) {
    case 0: 
         label = "Bathroom";
         break;
    case 1:
          label = "Kitchen";
          break;
    case 2:
          label = "Garage";
          break;
   }    
  return  label;
}
M2_LABELFN(el_labefn2, "x10y3", label_what);

Thanks for your help,
gnux

Hi

I do not see the declaration of "label"
Did you try this?

const char *label_what(m2_rom_void_p element)
{  

  switch (array[u8dev][13]) {
    case 0: return "Bathroom";
    case 1: return "Kitchen";
    case 2: return "Garage";
   }    
  return  "";
}
M2_LABELFN(el_labefn2, "x10y3", label_what);

Oliver

Ciao Oliver :slight_smile: , so now it's ok I'm working directly on lcd ...maybe it's better ...this was the code that I've used :

const char *linebuf = "";

const char *label_cb(m2_rom_void_p element)
{  
  switch (array[u8dev][12]) {
    case 0: 
         linebuf = "TurnedOff";
         break;
    case 2:
          linebuf = "BadState";
          break;
    case 32:
          linebuf = "TurnedOn";
          break;
   }    
  return linebuf;
}

M2_LABELFN(el_labefn2, "x10y3", label_what);

So, now I'd like to re-use the procedure above and pass like parameter "linebuf" is there a way to pass parameter ? I've tried but without success ...
I think it's possible, I've tried in several way but I've issues in "M2_LABELFN(el_labefn2, "x10y3", label_what);"

Thanks for the support,
have nice week end,
Gnux

Hi

You can not change the prototype for the callback procedure. So, you can not pass additional arguments. You need to use global variables.

Sure, this is not a good programming style...

Oliver

No problem :slight_smile: was just investigating for optimize at the top my code ... right now I'm using 28.200 byte on 32000 available ... :slight_smile: I need to look your link that you have sent to me in order to understand how to put the global variable in SRAM in order to use all Flash Memory for the program :slight_smile: I think that after that i will manage correctly my at328pu ... make sense for you ?

So, in a previous post you was mentioning this :
"You can calculate the amount of initially occupied RAM and ROM memory.
Use "avr-size" for this task. You need to locate and find the .elf file on your file system."

I've found .elf file for my sketch now is there a software to download for see how are located the variable ?

because looking the documentation it's a little bit difficult to understand sorry... i need to be little bit confident with it like did for display library :slight_smile: ... anyway i will try to read again ...

Thanks :slight_smile:
Gnux

Hi

avr-size should be part of the Arduino Distribution:
./hardware/tools/avr/bin/avr-size

Oliver

Ciao Oliver in attachment the result :slight_smile:

I need to understand now this data ... are express in byte ?

Which is the maximum limit that I've have ? So I would like to understand if I've use correctly the space for the program memory and the space for the variable ...

thanks for the information,
Gnux

Schermata 2013-02-23 a 17.49.15.png

Hi

text data bss dec hex filename
27502 698 1078 29278 1da5 spacetrash.elf

Flash-ROM (PROGMEM) size: 27502 + 698 : This must be lower than 2^15
Required RAM: 698 + 1078 + stack : This must be lower than 2048

The problem is the required stack size. It can not be calculated, but i guess it is around 200 Bytes or more.

Oliver

Hi Oliver thanks for this first explanation very useful ...

looking my avr-size result if I not understood bad kindly correct me if i wrong :-):

text data bss dec hex filename
27502 698 1078 29278 725e FinalRinse.cpp.elf

a) .text: is said the Software Code without Variable (function, case, loop,setup, cicles etc etc) - Maximum
size - 32.000 byte

b) .data: is said the space for variable (SRAM) that the maximum size is ?

c) .bss: is said the space for variable (SRAM) that the maximum size is ?

SRAM for Atmega328 is 2000 bytes --> correct ?

d) .dex: is the sum of a + b + c in decimal

e) .hex: is d in hex

Then:

Flash-ROM(PROGMEM) size = text + bss = 27502 + 698 = 28.200 bytes must be < 2^15 = 28.200 < 32.000 --> it's ok

Required SRAM: (.data + .bss + stack) < 2048 = 698 + 1078 + 200 = 1976 < 2048 --> I'm at the limit of Ram used.

Is there a way for see which variable are into .data memory and which into .bss zone and in my case moving the variable that are into .data zones into the .bss zone I could use the space for the code correct ?

Sorry if I have specified point to point but I think is better way to understand, so then you are very good teacher :slight_smile: thanks you again,
gnux

Hi

We are leaving the area of menu programming, my knowledge is not that good here, but i do my best to answer this question.

a) .text: is said the Software Code without Variable (function, case, loop,setup, cicles etc etc) - Maximum
size - 32.000 byte

Flash-ROM is the code size including variables which have none-zero init values.
.text is the value for the the pure code

b) .data: is said the space for variable (SRAM) that the maximum size is ?

.data is the size of the variables which have none-zero default value such as "int x = 4;"
This value counts against flash-rom AND ram (SRAM) area size.

c) .bss: is said the space for variable (SRAM) that the maximum size is ?

This is the size of those variables, which have a zero default value, such as "int y = 0;"

The stack size is not listed here, because it grows during runtime.
Conclusion for overall memory consumption:
Flash-Rom = .text + .data
SRAM = .data + .bss + stack

SRAM for Atmega328 is 2000 bytes --> correct ?

Well yes, the datasheet will be a more reliable source, but if i remember correctly then it is 2048.

Flash-ROM(PROGMEM) size = text + bss = 27502 + 698 = 28.200 bytes must be < 2^15 = 28.200 < 32.000 --> it's ok

You took the right numbers, but your text is wrong: "size = text + data"

Required SRAM: (.data + .bss + stack) < 2048 = 698 + 1078 + 200 = 1976 < 2048 --> I'm at the limit of Ram used.

Yes, i think so too. Especially i do not know if stack needs 100, 200 or 300 bytes.
If you need a precise answer, you will need tools like this: StackAnalyzer: Stack Usage Analysis

You can also do a runtime analysis by your own. I found the following threads also:

This is a nice idea for fully automatic runtime calculation:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=52249

This also has several links and lot of information:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=78518

Have fun,
Oliver