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

tcMenu Arduinio library » Dialog Box - Having issues calling function

Author: jonboy545
06/04/2020 20:17:54
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();
}

Author: davetcc
07/04/2020 10:27:30
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*/);

Author: jonboy545
07/04/2020 13:41:56
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


Author: jonboy545
07/04/2020 13:56:17
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

Author: davetcc
07/04/2020 14:27:24
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..




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