2021.10.19.04

FEATURE_NEXTION_DISPLAY: more work on initialization code
This commit is contained in:
Anthony Good 2021-10-19 17:22:11 -04:00
parent 87b9bb20d4
commit b1072145cb
12 changed files with 287 additions and 107 deletions

View File

@ -1051,6 +1051,9 @@
2021.10.19.03
FEATURE_NEXTION_DISPLAY: optimization of OPTION_NEW_NEXTION_INIT_CODE
2021.10.19.04
FEATURE_NEXTION_DISPLAY: more work on initialization code
All library files should be placed in directories likes \sketchbook\libraries\library1\ , \sketchbook\libraries\library2\ , etc.
Anything rotator_*.* should be in the ino directory!
@ -1064,7 +1067,7 @@
*/
#define CODE_VERSION "2021.10.19.03"
#define CODE_VERSION "2021.10.19.04"
#include <avr/pgmspace.h>
@ -1751,6 +1754,10 @@ struct config_t {
Satellite sat;
SatDateTime sat_datetime;
#if defined(DEBUG_SATELLITE_USE_OLD_OBSERVER_OBJECT)
Observer obs("",DEFAULT_LATITUDE,DEFAULT_LONGITUDE,DEFAULT_ALTITUDE_M);
#endif
struct satellite_list{
char name[SATELLITE_NAME_LENGTH];
int azimuth;
@ -4811,8 +4818,10 @@ void service_nextion_display(){
static unsigned long last_moon_and_sun_and_sat_update = 0;
#endif
#if !defined(OPTION_NEW_NEXTION_INIT_CODE)
// OLD CODE
// initialization ---------------------------------------------------------------------------
#if defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_1)
// OLD CODE 1
if ((initialization_stage == 0) && (millis() > 100)){
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
debug.println(F("\r\nservice_nextion_display: init: 0"));
@ -4839,10 +4848,7 @@ void service_nextion_display(){
}
if (initialization_stage == 1){ // look for 'i am alive' bytes from Nextion
nextion_i_am_alive_string[0] = 255;
nextion_i_am_alive_string[1] = 255;
nextion_i_am_alive_string[2] = 255;
nextion_i_am_alive_string[3] = 0; // Null - end of string
byte nextion_i_am_alive_string[] = {255,255,255,0};
if (nexSerial.available()){
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
@ -4890,8 +4896,9 @@ void service_nextion_display(){
}
}
}
#else // OPTION_NEW_NEXTION_INIT_CODE
// NEW CODE
#else // OPTION_DEPRECATED_NEXTION_INIT_CODE_1
#if defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_2)
// OLD CODE 2
if (initialization_stage == 0){
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
debug.println(F("\r\nservice_nextion_display: init: 0"));
@ -4959,9 +4966,10 @@ void service_nextion_display(){
}
}
}
#endif // OPTION_NEW_NEXTION_INIT_CODE
#endif //OPTION_DEPRECATED_NEXTION_INIT_CODE_2
#endif // OPTION_DEPRECATED_NEXTION_INIT_CODE_1
#if (defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_1) || defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_2))
if (initialization_stage < 2){return;} // we haven't initialized yet. come back later.
// Update various things
@ -5084,10 +5092,174 @@ void service_nextion_display(){
debug.println("\r\nservice_nextion_display: done with init, init -> 3");
#endif
}
}
#endif //(defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_1) || defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_2))
#if (!defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_1) && !defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_2))
// Current initialization code
/* Nextion Initialization code from VK4GHZ
*
* VK4GHZ Nextion firmware Version 2021-10-23 or later required.
*
* This works on the understanding that the Nextion will be ready before the Arduino sends the gSC variable to it.
* Therefore 2-way handshaking is not needed.
* Resetting the Nextion is not needed.
*
* If the Nextion fails to receive gSC, then that indicates a user configuration error, or mis-wired TXD/RXD lines.
*
* Nextion 3.2" Enhanced is ready ~ 225 mS after powering up
* Nextion 3.5" Enhanced is ready ~ 390 mS after powering up
* Nextion 5.0" Enhanced is ready ~ 345 mS after powering up
* Nextion 7.0" Enhanced is ready ~ mS after powering up (VK4GHZ does not have a 7.0" to test with, but will happily accept donations!)
*
* Tests indicate nexSerial is set 363 ~ 2400 mS after Teensy 3.2 board powers up.
* This may not be the same on successive power ups.
* Dunno why?
*
* Sending of gSC can be delayed by increasing the value of NEXTION_GSC_STARTUP_DELAY in rotator_settings.h (default 0 mS)
* However, a value of 0 works with 3.5" enhanced, being the slowest HMI to become ready.
*/
if ((initialization_stage == 0) && (millis() > NEXTION_GSC_STARTUP_DELAY)){
nexSerial.begin(NEXTION_SERIAL_BAUD);
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
debug.println(F("\r\nservice_nextion_display: init: 0"));
debug.print(F("\r\nNextion serial: ")); // Debug print how long after power up Nextion serial is set
debug.print(millis());
debug.println(" mS");
#endif
output_nextion_gSC_variable(); // send gSC variable to Nextion
initialization_stage = 2; // Straight to init stage 2, init stage 1 has become redundant
last_various_things_update = millis();
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
debug.println(F("\r\nservice_nextion_display: init 0 -> 2")); // init stage 2
#endif
}
// Update various things
if (initialization_stage == 2){
temp = 0;
#if defined(LANGUAGE_ENGLISH)
temp = temp | NEXTION_API_SYSTEM_CAPABILITIES_ENGLISH;
#endif
#if defined(LANGUAGE_SPANISH)
temp = temp | NEXTION_API_SYSTEM_CAPABILITIES_SPANISH;
#endif
#if defined(LANGUAGE_CZECH)
temp = temp | NEXTION_API_SYSTEM_CAPABILITIES_CZECH;
#endif
#if defined(LANGUAGE_PORTUGUESE_BRASIL)
temp = temp | NEXTION_API_SYSTEM_CAPABILITIES_PORTUGUESE_BRASIL;
#endif
#if defined(LANGUAGE_GERMAN)
temp = temp | NEXTION_API_SYSTEM_CAPABILITIES_GERMAN;
#endif
#if defined(LANGUAGE_FRENCH)
temp = temp | NEXTION_API_SYSTEM_CAPABILITIES_FRENCH;
#endif
strcpy_P(workstring1,(const char*) F("gL="));
dtostrf(temp, 1, 0, workstring2);
strcat(workstring1,workstring2);
sendNextionCommand(workstring1);
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
if (initialization_stage == 2){
debug.print(F("\r\nservice_nextion_display: init: sent first "));
debug.print(workstring1);
debug.print(F(" mS elapsed since nextion_i_am_alive_string:"));
debug.println(int((unsigned long)millis()-(unsigned long)last_various_things_update));
}
#endif
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
if (initialization_stage == 2){
debug.print(F("\r\nservice_nextion_display: init: sent first "));
debug.print(workstring1);
debug.print(F(" mS elapsed since nextion_i_am_alive_string:"));
debug.println(int((unsigned long)millis()-(unsigned long)last_various_things_update));
}
#endif
// Rotator Controller Arduino Code Version
strcpy_P(workstring1,(const char*) F("vRCVersion.txt=\""));
strcat(workstring1,CODE_VERSION);
strcat(workstring1,"\"");
sendNextionCommand(workstring1);
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
if (initialization_stage == 2){
debug.print(F("\r\nservice_nextion_display: init: sent first "));
debug.print(workstring1);
debug.print(F(" mS elapsed since nextion_i_am_alive_string:"));
debug.println(int((unsigned long)millis()-(unsigned long)last_various_things_update));
}
#endif
// gDP - Display decimal places
dtostrf(DISPLAY_DECIMAL_PLACES, 1, 0, workstring1);
strcpy_P(workstring2,(const char*) F("gDP="));
strcat(workstring2,workstring1);
sendNextionCommand(workstring2);
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
if (initialization_stage == 2){
debug.print(F("\r\nservice_nextion_display: init: sent first "));
debug.print(workstring2);
debug.print(F(" mS elapsed since nextion_i_am_alive_string:"));
debug.println(int((unsigned long)millis()-(unsigned long)last_various_things_update));
}
#endif
#if defined(FEATURE_PARK)
strcpy_P(workstring1,(const char*) F("vPA.val="));
dtostrf(configuration.park_azimuth, 1, 0, workstring2);
strcat(workstring1,workstring2);
sendNextionCommand(workstring1);
#if defined(FEATURE_ELEVATION_CONTROL)
strcpy_P(workstring1,(const char*) F("vPE.val="));
dtostrf(configuration.park_elevation, 1, 0, workstring2);
strcat(workstring1,workstring2);
sendNextionCommand(workstring1);
#endif
#if defined(FEATURE_AUTOPARK)
strcpy_P(workstring1,(const char*) F("vAT.val="));
dtostrf(configuration.autopark_time_minutes, 1, 0, workstring2);
strcat(workstring1,workstring2);
sendNextionCommand(workstring1);
#endif
#endif //FEATURE_PARK
last_various_things_update = millis();
if (initialization_stage == 2){
initialization_stage = 3;
#if defined(DEBUG_NEXTION_DISPLAY_INIT)
debug.println("\r\nservice_nextion_display: done with init, init -> 3");
#endif
}
}
#endif // (!defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_1) && !defined(OPTION_DEPRECATED_NEXTION_INIT_CODE_2))
// end of initialization ---------------------------------------------------------------------------
// Get incoming commands
if (nexSerial.available()){
#if defined(DEBUG_NEXTION_DISPLAY_SERIAL_RECV)
@ -20282,7 +20454,10 @@ void convert_polar_to_cartesian(byte coordinate_conversion,double azimuth_in,dou
byte pull_result = 0;
Observer obs("",latitude,longitude,altitude_m);
#if !defined(DEBUG_SATELLITE_USE_OLD_OBSERVER_OBJECT)
/*static*/ Observer obs("",latitude,longitude,altitude_m); // don't do static here. it doesn't work
#endif
if (service_action == SERVICE_CALC_REPORT_STATE){return service_calc_satellite_data_service_state;}

View File

@ -80,3 +80,4 @@
// #define DEBUG_SATELLITE_POPULATE_LIST_ARRAY
// #define DEBUG_SATELLITE_LIST_EXTRA_INFO
// #define DEBUG_SATELLITE_CALC_RESET
// #define DEBUG_SATELLITE_USE_OLD_OBSERVER_OBJECT

View File

@ -189,3 +189,6 @@
// #define OPTION_CLI_VT100 // use VT100 terminal emulation
#define OPTION_GPS_USE_TINY_GPS_LIBRARY // For serial port based NMEA GPS units; serial port defined by GPS_PORT and GPS_PORT_BAUD_RATE in settings file
#define OPTION_DEPRECATED_NEXTION_INIT_CODE_1 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23
// #define OPTION_DEPRECATED_NEXTION_INIT_CODE_2 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23

View File

@ -176,3 +176,5 @@
#define OPTION_GPS_USE_TINY_GPS_LIBRARY // For serial port based NMEA GPS units; serial port defined by GPS_PORT and GPS_PORT_BAUD_RATE in settings file
#define OPTION_DEPRECATED_NEXTION_INIT_CODE_1 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23
// #define OPTION_DEPRECATED_NEXTION_INIT_CODE_2 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23

View File

@ -206,6 +206,9 @@
#define OPTION_GPS_USE_TINY_GPS_LIBRARY // For serial port based NMEA GPS units; serial port defined by GPS_PORT and GPS_PORT_BAUD_RATE in settings file
#define OPTION_GPS_USE_SPARKFUN_U_BLOX_GNSS_LIBRARY // For Sparkfun (and perhaps others) u-blox GPS units interfaced via I2C ( https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library)
#define OPTION_DEPRECATED_NEXTION_INIT_CODE_1 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23
// #define OPTION_DEPRECATED_NEXTION_INIT_CODE_2 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23
// ######## ######## ###### ########
// ## ## ## ## ##

View File

@ -190,3 +190,5 @@
#define OPTION_GPS_USE_TINY_GPS_LIBRARY // For serial port based NMEA GPS units; serial port defined by GPS_PORT and GPS_PORT_BAUD_RATE in settings file
// #define OPTION_DEPRECATED_NEXTION_INIT_CODE_1 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23
// #define OPTION_DEPRECATED_NEXTION_INIT_CODE_2 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23

View File

@ -74,7 +74,7 @@
// #define FEATURE_EL_POSITION_A2_ABSOLUTE_ENCODER
// And if you are using any display other than a 4 bit LCD, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// #define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common)
#define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common)
// #define FEATURE_ADAFRUIT_I2C_LCD
// #define FEATURE_ADAFRUIT_BUTTONS // Uncomment this to use Adafruit I2C LCD buttons for manual AZ/EL instead of normal buttons (also set this feature in rotator_k3ngdisplay.h)
// #define FEATURE_YOURDUINO_I2C_LCD
@ -193,4 +193,5 @@
#define OPTION_GPS_USE_TINY_GPS_LIBRARY // For serial port based NMEA GPS units; serial port defined by GPS_PORT and GPS_PORT_BAUD_RATE in settings file
// #define OPTION_GPS_USE_SPARKFUN_U_BLOX_GNSS_LIBRARY // For Sparkfun (and perhaps others) u-blox GPS units interfaced via I2C ( https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library)
#define OPTION_NEW_NEXTION_INIT_CODE
#define OPTION_DEPRECATED_NEXTION_INIT_CODE_1 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23
// #define OPTION_DEPRECATED_NEXTION_INIT_CODE_2 // use only with VK4GHZ Nextion firmware versions previous to 2021-10-23

View File

@ -385,4 +385,6 @@ You can tweak these, but read the online documentation!
#define SATELLITE_CALC_STAGE_2_RESOLUTION_SECS 10
#define SATELLITE_CALC_STAGE_3_RESOLUTION_SECS 1
#define NEXTION_GSC_STARTUP_DELAY 0

View File

@ -372,15 +372,6 @@ You can tweak these, but read the online documentation!
// Added in 2020.08.24.01
#define NEXTION_NUMBER_OF_NEXT_SATELLITES 6
// Added / Updated in 2020.08.26.02
// #define SATELLITE_CALC_THROTTLE_DOWN_TO_MEDIUM_RESOLUTION_MS 1000
// #define SATELLITE_CALC_THROTTLE_DOWN_TO_LOW_RESOLUTION_MS 5000
// #define SATELLITE_AOS_LOS_CALC_RESOLUTION_HIGH_SECS 10
// #define SATELLITE_AOS_LOS_CALC_RESOLUTION_MEDIUM_SECS 30
// #define SATELLITE_AOS_LOS_CALC_RESOLUTION_LOW_SECS 120
// #define SATELLITE_AOS_LOS_CALC_RESOLUTION_HIGH_TRIGGER_SECS 3600 //300 //next event is < 5 minutes
// #define SATELLITE_AOS_LOS_CALC_RESOLUTION_MEDIUM_TRIGGER_SECS 10800 //3600 //next < 1 hour
// Added / Updated in 2020.08.29.01
#define SATELLITE_CALC_TIMEOUT_MS 10000
#define SATELLITE_AOS_ELEVATION_MIN 0.0
@ -388,9 +379,6 @@ You can tweak these, but read the online documentation!
#define SATELLITE_CALC_STAGE_2_RESOLUTION_SECS 10
#define SATELLITE_CALC_STAGE_3_RESOLUTION_SECS 1
// Deprecated in 2020.08.30.01
// #define PARK_AZIMUTH 0.0 // replace the 0.0 with your park azimuth; azimuth is in raw degrees (i.e. on a 180 degree starting point rotator, 0 degrees = 360)
// #define PARK_ELEVATION 0.0 // replace the 0.0 with your park elevation
#define NEXTION_GSC_STARTUP_DELAY 0

View File

@ -395,6 +395,7 @@ You can tweak these, but read the online documentation!
#define SATELLITE_CALC_STAGE_2_RESOLUTION_SECS 10
#define SATELLITE_CALC_STAGE_3_RESOLUTION_SECS 1
#define NEXTION_GSC_STARTUP_DELAY 0
// ######## ######## ###### ########

View File

@ -385,4 +385,5 @@ You can tweak these, but read the online documentation!
#define SATELLITE_CALC_STAGE_2_RESOLUTION_SECS 10
#define SATELLITE_CALC_STAGE_3_RESOLUTION_SECS 1
#define NEXTION_GSC_STARTUP_DELAY 0

View File

@ -192,10 +192,10 @@ You can tweak these, but read the online documentation!
#define SERIAL_LED_TIME_MS 250
#define DEFAULT_LATITUDE 1.0
#define DEFAULT_LONGITUDE -2.0
// #define DEFAULT_LATITUDE 40.889958
// #define DEFAULT_LONGITUDE -75.585972
// #define DEFAULT_LATITUDE 1.0
// #define DEFAULT_LONGITUDE -2.0
#define DEFAULT_LATITUDE 40.889958
#define DEFAULT_LONGITUDE -75.585972
#define MOON_TRACKING_CHECK_INTERVAL 5000 // This is only written to the configuration upon first boot of the code or when EEPROM_MAGIC_NUMBER is changed in rotator.h
#define MOON_AOS_AZIMUTH_MIN 0
@ -387,4 +387,5 @@ You can tweak these, but read the online documentation!
#define SATELLITE_CALC_STAGE_2_RESOLUTION_SECS 10
#define SATELLITE_CALC_STAGE_3_RESOLUTION_SECS 1
#define NEXTION_GSC_STARTUP_DELAY 0