Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » Dialog Box - having issues with Header text

Author: WattsAmps
05/12/2020 12:07:20
Hi Dave

I am using the dialog box to prompt before saving settings to EEPROM.
I used this topic for guidance and example:
https://www.thecoderscorner.com/jforum/posts/list/45.page

I have it all working well with the exception of the header text where I am using the variable pgmHeaderText

Firstly my compiler throws an error saying it needs to be const char* headerPgm instead of a String.
If I change to const char* then if set to "TEST" I get odd text in the header like:
3'5&3
The buffer string works fine.

My code is:
void CALLBACK_FUNCTION exitAndSaveSettings(int id) {
    // TODO - your menu change code

  const char* pgmHeaderText = "TEST";
  bool remoteAllowed = true;
  BaseDialog* dlg = renderer.getDialog();
  dlg->setButtons(BTNTYPE_OK, BTNTYPE_CANCEL, 1);
  dlg->show(pgmHeaderText, remoteAllowed, onDialogFinished); // true = shows on remote sessions.
  dlg->copyIntoBuffer("Click OK to save");     
}

void onDialogFinished(ButtonType btnPressed, void* /*userdata*/) {        
    if(btnPressed == BTNTYPE_OK) {
      //  menuMgr.save(IntEeprom);
      renderer.takeOverDisplay(exitMenu);
    }
}


If I just enter text directly as per this:
dlg->show("TEST", remoteAllowed, onDialogFinished)
I still get the strange text.
Any idea what I am not understanding?

Author: davetcc
06/12/2020 12:18:19
I'm not sure what board you're on, but if you are using ESP* or AVR, then the text for the header must reside in progmem at the moment. can you try adding PROGMEM to the text. For example:

const char pgmProceedText[] PROGMEM = "Proceed";


We can probably create another constructor that does not use progmem in the future..

Author: WattsAmps
06/12/2020 16:14:01
Hi Dave thanks for prompt response.

You are right I am using a Mega2560.
And reading that post more carefully I now see your comment regarding PROGMEM at the end.

However if I do that I get no text just the title background - the buffer works fine.
So it is usable but lacking the header.

thanks

Marcus

Author: davetcc
06/12/2020 22:36:50
That is rather strange as I've not seen that fail before if the text is stored in program memory, I'm wondering if there is some kind of issue here.

What size is your sketch when you upload it (flash size)? Is it over 64K? I'm wondering if there's something wrong with the near addressing. Easily fixed if it is that.


Author: WattsAmps
07/12/2020 11:10:24
Hi Dave

Yes it is just under 90k = approx 35%

Marcus

Author: davetcc
07/12/2020 12:04:37
The compiler for AVR on Arduino is supposed to move all progmem definitions into the lower 64K so I doubt it's that to be honest, many well-known libraries also assume progmem data to be in the lower 64K. So I assume the compiler does that automatically.

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

The common error is that the constant string referred to is not defined globally, make sure you define it outside of any function.

In fact in the gnu guide, they make it even clearer in the note about 30% of the way down the page, the progmem string manipulation functions only work on the lower 64K. So I assume the compiler arranges the constant data segments first in memory. It's the problem with having > 64K bus on an 8-bit device!

Author: davetcc
07/12/2020 12:26:41
BTW, we'll make a version of the function that works with strings in RAM instead in the next patch.

https://github.com/davetcc/tcMenuLib/issues/79

Author: WattsAmps
07/12/2020 12:33:40
Brilliant - moving it into global did the trick - many thanks again for your prompt replies - really appreciated

Author: tikard
24/01/2021 20:21:21
I have the same issue on same hardware.

What was the fix to put it in global?

Author: WattsAmps
24/01/2021 22:15:47
Just declare the variable towards the top of the sketch before set up.
So in my case I declared it after my library includes thus:
const char pgmProceedText [] PROGMEM = "SAVE SETTINGS";
around line 15
This seems to ensure the compiler includes it in the lower 64k

Author: tikard
24/01/2021 22:56:24
Thanks. I tried everything too.




Register / Login  |  Desktop view  |  Jump to top of page