[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

Dialog Box - Having issues calling function RSS feed
Forum Index » tcMenu Arduinio library
Author Message
jonboy545


Joined: Mar 28, 2020
Messages: 12
Offline
Hi Dave, thanks in advance for any assistance you can provide.

I have an action item, that I'd like to present a "Are you Sure" kind of dialog box. I'm having issues following the documentation. I know it's something simple I'm missing, and I have an idea of what is missing, but not how to actually execute it.
Going by the compile error, I think it's not calling the onDialogFinished function because of the missing parameters (ButtonType btnPressed, void* /*userdata*/) ??
Compile error is 'onDialogFinished' was not declared in this scope
More specifically, I'm almost positive it's "void* /*userdata*/" that is the error, but I'm not sure what is *supposed* to be there.

Thank you.

void CALLBACK_FUNCTION restoreDefaults(int id) {
  String pgmHeaderText = "TEST DIALOG TEXT";
  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("Hello");
}

void onDialogFinished(ButtonType btnPressed, void* /*userdata*/) {        
    if(btnPressed != BTNTYPE_OK) {
      renderer.takeOverDisplay(restoreFactoryDefaults);
    }
}


void restoreFactoryDefaults() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("--------------------"));
lcd.setCursor(0, 1);
  lcd.print(F("| RESTORING FACTORY|"));
  lcd.setCursor(0, 2);
  lcd.print(F("| DEFAULTS - WAIT! |"));
  lcd.setCursor(0, 3);
  lcd.print(F("--------------------"));
  Serial.println(F("Wiping EEPROM settings and setting back to default."));
  Serial.println(F("WAIT UNTIL COMPLETED!"));
  /*  Test EEPROM write - commented out for testing
  EEPROM.write(2, 100); // LCD Brightness to 100%
  */
  delay(5000);
  Serial.println(F("Factory Reset Complete"));
  lcd.clear();
  renderer.giveBackDisplay();
}
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
I think you need to "declare" the function, because you're using it before it's fully "implemented". The fix for this is usually to declare the function before it's defined, see below.

Can you try putting the following line before the usage of onDialogFinished (IE near the top of the file, just after includes):

void onDialogFinished(ButtonType btnPressed, void* /*userdata*/);
jonboy545


Joined: Mar 28, 2020
Messages: 12
Offline
Hi Dave!

That worked! I needed to remove the variable declarations as it was giving an error as posted.
One small issue. For some reason (see pics below) the text "LED Brightness" is being displayed on the LCD instead of the String text expected "Test Dialog Text". The only place "LED Brightness" is in my sketch is way down in a seperate function, and it's part of a Serial.println command. I've confirmed it's "taking" that text from that location by changing the text, and it reflects on the LCD.
The working truncated code is below:

// Near the top, right after includes
void onDialogFinished(ButtonType btnPressed, void* /*userdata*/);



void CALLBACK_FUNCTION restoreDefaults(int id) {
  BaseDialog* dlg = renderer.getDialog();
  dlg->setButtons(BTNTYPE_OK, BTNTYPE_CANCEL, 1);
  dlg->show("Test Dialog Text", true, onDialogFinished); // true = shows on remote sessions.
  dlg->copyIntoBuffer("Factory Defaults?");
}
void onDialogFinished(ButtonType btnPressed, void* /*userdata*/) {        
    if(btnPressed != BTNTYPE_OK) {
      renderer.takeOverDisplay(restoreFactoryDefaults);
    }
}
void restoreFactoryDefaults() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("--------------------"));
  lcd.setCursor(0, 1);
  lcd.print(F("| RESTORING FACTORY|"));
  lcd.setCursor(0, 2);
  lcd.print(F("| DEFAULTS - WAIT! |"));
  lcd.setCursor(0, 3);
  lcd.print(F("--------------------"));
  Serial.println(F("Wiping EEPROM settings and setting back to default."));
  Serial.println(F("WAIT UNTIL COMPLETED!"));
  EEPROM.write(2, 100); // LCD Brightness to 100%
  EEPROM.write(4, 50); // LCD Contrast to 50%
  EEPROM.write(6, 0); // Serial Output Disabled
  EEPROM.write(7, 2); // Serial Output Speed to 2
  EEPROM.write(9, 3); // LED Display to 100%
  EEPROM.write(11, 0); // Preinfuse Time ????
  EEPROM.write(13, 0); // Preinfuse Disabled
  EEPROM.write(14, 5); // Service Boiler Temperature Calibration Value
  EEPROM.write(16, 80); // Service Boiler Set Temp F
  EEPROM.write(18, 1); // Enable LED Display
  EEPROM.write(20, 5); // Coffee Boiler/Group Temperature Calibration Value
  EEPROM.write(22, 80); // Coffee Boiler/Group Set Temp F
  EEPROM.write(24, 0); // Dose 1 Impulses
  EEPROM.write(26, 0); // Dose 2 Impulses
  EEPROM.write(28, 0); // Service Boiler Set Pressure
  delay(5000);
  Serial.println(F("Factory Reset Complete"));
  lcd.clear();
  renderer.giveBackDisplay();
}


image


image

jonboy545


Joined: Mar 28, 2020
Messages: 12
Offline
Just to prove that changing that Serial.print text actually changes the "header text" on the menu.
What's odd, is if I use Visual Studio with PlatformIO to flash the arduino, the text is taken from somewhere else, not the same line...
image
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
Ah, the header string for the show function is expected to be in program memory! I'll make sure the docs make that clearer.

Just declare it as in progmem, see in the nokia 5110 example.

// declare as follows
const char warningPgm[] PROGMEM = "Warning!";

// and then use it as follow
dlg->show(warningPgm, true);


You may even get away with the Arduino F function, but I've never tried that..
 
Forum Index » tcMenu Arduinio library
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.