Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library gives errors. Nextion::ack() #47

Open
paulkidd68 opened this issue Oct 26, 2021 · 3 comments
Open

Library gives errors. Nextion::ack() #47

paulkidd68 opened this issue Oct 26, 2021 · 3 comments

Comments

@paulkidd68
Copy link

paulkidd68 commented Oct 26, 2021

I get the following error when trying to use the library.
Nextion.cpp: In member function 'boolean Nextion::ack()':
Nextion.cpp:119:1: error: control reaches end of non-void function [-Werror=return-type]
119 | }//end
| ^
This only happens when using the latest ESP8266 software

@PlastiBots
Copy link

PlastiBots commented Oct 28, 2021

I'm getting the same error as well now. Was working fine but then poof, started to fail. Also using an ESP8266 and I hadn't played with this code in a while, so I suspect it's also because I updated the ESP libraries. Alternatively, it could be due to the Arduino IDE being more restrictive during compiling.... I temporarily fixed it as follows (added return true; near the end of the function in Nextion.cpp. However, I don't know if it's correct to return True or False if nothing evaluates in the function:

boolean Nextion::ack(void){
/* CODE+END*/
uint8_t bytes[4] = {0};
nextion->setTimeout(20);
if (sizeof(bytes) != nextion->readBytes((char *)bytes, sizeof(bytes))){
return 0;
}//end if
if((bytes[1]==0xFF)&&(bytes[2]==0xFF)&&(bytes[3]==0xFF)){
switch (bytes[0]) {
case 0x00:
return false; break;
//return "0"; break;
case 0x01:
return true; break;
//return "1"; break;
/case 0x03:
return "3"; break;
case 0x04:
return "4"; break;
case 0x05:
return "5"; break;
case 0x1A:
return "1A"; break;
case 0x1B:
return "1B"; break;//
/
default:
return false;
}//end switch
}//end if
return true; //Added DJA
}//end

@paulkidd68
Copy link
Author

I just downgraded the ESP8266 core to the last of version 2 and it cured it.
I hadn’t used it for years either so when I did use it ESP8266 was version 2

@Peterkn2001
Copy link

The problem is caused by the boolean Nextion::ack(void){ function which starts at line 90.
The compiler expects a Boolean value to be returned, but all of the return commands are located within if statements. If none of the if statements evaluate as true then nothing will be returned, and the compiler doesn't like this possibility.

The solution is to add an additional return command at the end of this function.
I'd also suggest changing the leftover return 0; command to a return false; like this...

boolean Nextion::ack(void){
  /* CODE+END*/
  uint8_t bytes[4] = {0};
  nextion->setTimeout(20);
  if (sizeof(bytes) != nextion->readBytes((char *)bytes, sizeof(bytes))){
    //return 0; //                                            <<< THIS LINE COMMENTED OUT
    return false; //                                          <<< THIS LINE ADDED
  }//end if
  if((bytes[1]==0xFF)&&(bytes[2]==0xFF)&&(bytes[3]==0xFF)){
    switch (bytes[0]) {
  case 0x00:
    return false; break;
    //return "0"; break;      
  case 0x01:
    return true; break;
    //return "1"; break;
    /*case 0x03:
    return "3"; break;
  case 0x04:
    return "4"; break;
  case 0x05:
    return "5"; break;
  case 0x1A:
    return "1A"; break;
  case 0x1B:
    return "1B"; break;//*/
  default: 
    return false;
    }//end switch
  }//end if
return false; //                                                  <<< ADD THIS RETURN COMMAND
}//end

This fixes the "Failed to compile for " error with the current (3.0.2) version of the ESP8266 core.

Pete,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants