2020.07.25.02

FEATURE_NEXTION_DISPLAY: Added vConResult string API variable which returns the results of backslash commands from the Nextion display
This commit is contained in:
Anthony Good 2020-07-25 21:41:01 -04:00
parent c61e51afec
commit 1374ac4ff1

View File

@ -612,6 +612,9 @@
Setting LCD_MOON_OR_SUN_TRACKING_CONDITIONAL_ROW changed to LCD_MOON_OR_SUN_OR_SAT_TRACKING_CONDITIONAL_ROW Setting LCD_MOON_OR_SUN_TRACKING_CONDITIONAL_ROW changed to LCD_MOON_OR_SUN_OR_SAT_TRACKING_CONDITIONAL_ROW
Under construction documentation https://github.com/k3ng/k3ng_rotator_controller/wiki/707-Satellite-Tracking Under construction documentation https://github.com/k3ng/k3ng_rotator_controller/wiki/707-Satellite-Tracking
2020.07.25.02
FEATURE_NEXTION_DISPLAY: Added vConResult string API variable which returns the results of backslash commands from the Nextion display
All library files should be placed in directories likes \sketchbook\libraries\library1\ , \sketchbook\libraries\library2\ , etc. All library files should be placed in directories likes \sketchbook\libraries\library1\ , \sketchbook\libraries\library2\ , etc.
Anything rotator_*.* should be in the ino directory! Anything rotator_*.* should be in the ino directory!
@ -623,7 +626,7 @@
*/ */
#define CODE_VERSION "2020.07.25.01" #define CODE_VERSION "2020.07.25.02"
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <EEPROM.h> #include <EEPROM.h>
@ -4066,523 +4069,8 @@ char * azimuth_direction(int azimuth_in){
} /* azimuth_direction */ } /* azimuth_direction */
#endif /* ifdef FEATURE_LCD_DISPLAY */ #endif /* ifdef FEATURE_LCD_DISPLAY */
// --------------------------------------------------------------
#if defined(FEATURE_NEXTION_DISPLAY_OLD)
void service_nextion_display(){
#ifdef DEBUG_LOOP
control_port->println("service_nextion_display_old()");
control_port->flush();
#endif // DEBUG_LOOP
char workstring1[32] = "";
char workstring2[32] = "";
static int last_azimuth = 0;
static unsigned long last_az_update = 0;
static byte last_nextion_current_screen = NEXTION_PAGE_MAIN_ID;
static byte unloaded_splash_screen = 0;
#if defined(FEATURE_ELEVATION_CONTROL)
static int last_elevation = 0;
static unsigned long last_el_update = 0;
#endif
#if defined(FEATURE_CLOCK)
static int last_clock_seconds = 0;
#endif
#if defined(FEATURE_GPS) && defined(FEATURE_CLOCK)
static byte last_clock_status = clock_status;
static byte last_gps_sats = 0;
#endif
static byte last_az_state = IDLE;
#if defined(FEATURE_ELEVATION_CONTROL)
static byte last_el_state = IDLE;
#endif
#if defined(FEATURE_GPS) && defined(NEXTION_OBJNAME_GRID) && defined(NEXTION_OBJID_GRID)
static unsigned long last_grid_update = 0;
#endif
#if defined(FEATURE_GPS) && defined(NEXTION_OBJNAME_COORDINATES) && defined(NEXTION_OBJID_COORDINATES)
static unsigned long last_coord_update = 0;
unsigned long gps_fix_age_temp = 0;
float gps_lat_temp = 0;
float gps_long_temp = 0;
#endif
#if defined(ANALOG_AZ_OVERLAP_DEGREES)
static byte last_overlap_indicator = 0;
byte overlap_indicator = 0;;
#endif
#if defined(FEATURE_PARK)
static byte last_park_status = NOT_PARKED;
#endif
#if defined(ANALOG_AZ_OVERLAP_DEGREES)
static unsigned long last_status3_update = 0;
#endif
if ((!unloaded_splash_screen) && (millis()>3000)){
NextionPageRefresh(NEXTION_PAGE_MAIN_ID,NEXTION_UNDEFINED);
unloaded_splash_screen = 1;
}
nexLoop(nex_listen_list);
// Main Page
if (nextion_current_screen == NEXTION_PAGE_MAIN_ID){
// Azimuth
if (((azimuth != last_azimuth) && ((millis() - last_az_update) > NEXTION_DISPLAY_UPDATE_MS)) || (last_nextion_current_screen != nextion_current_screen)){
dtostrf(azimuth , 1, DISPLAY_DECIMAL_PLACES, workstring1);
strcat(workstring1,NEXTION_DISPLAY_DEGREES_STRING); // haven't figured out how the hell to get degrees symbol to display
tAzValue.setText(workstring1);
last_azimuth = azimuth;
last_az_update = millis();
}
// Elevation
#if defined(FEATURE_ELEVATION_CONTROL)
if (((elevation != last_elevation) && ((millis() - last_el_update) > NEXTION_DISPLAY_UPDATE_MS)) || (last_nextion_current_screen != nextion_current_screen)){
dtostrf(elevation , 1, DISPLAY_DECIMAL_PLACES, workstring1);
strcat(workstring1,NEXTION_DISPLAY_DEGREES_STRING);
tElValue.setText(workstring1);
last_elevation = elevation;
last_el_update = millis();
}
#endif
// Clock
#if defined(FEATURE_CLOCK) && defined(NEXTION_OBJNAME_CLOCK) && defined(NEXTION_OBJID_CLOCK)
update_time();
if ((local_clock_seconds != last_clock_seconds) || (last_nextion_current_screen != nextion_current_screen)){
last_clock_seconds = clock_seconds;
#ifdef OPTION_CLOCK_ALWAYS_HAVE_HOUR_LEADING_ZERO
if (local_clock_hours < 10) {
strcpy(workstring1, "0");
dtostrf(local_clock_hours, 0, 0, workstring2);
strcat(workstring1,workstring2);
} else {
dtostrf(local_clock_hours, 0, 0, workstring2);
strcpy(workstring1,workstring2);
}
#else
dtostrf(local_clock_hours, 0, 0, workstring2);
strcpy(workstring1,workstring2);
#endif //OPTION_CLOCK_ALWAYS_HAVE_HOUR_LEADING_ZERO
strcat(workstring1,":");
if (local_clock_minutes < 10) {
strcat(workstring1, "0");
}
dtostrf(local_clock_minutes, 0, 0, workstring2);
strcat(workstring1,workstring2);
strcat(workstring1,":");
if (local_clock_seconds < 10) {
strcat(workstring1, "0");
}
dtostrf(local_clock_seconds, 0, 0, workstring2);
strcat(workstring1,workstring2);
tClock.setText(workstring1);
}
#endif //FEATURE_CLOCK
// GPS
#if defined(FEATURE_GPS) && defined(FEATURE_CLOCK) && defined(NEXTION_OBJNAME_GPS) && defined(NEXTION_OBJID_GPS)
if (((last_clock_status != clock_status) || (last_gps_sats != gps.satellites())) || (last_nextion_current_screen != nextion_current_screen)){
if ((clock_status == GPS_SYNC) || (clock_status == SLAVE_SYNC_GPS)) {
strcpy(workstring1,GPS_STRING);
strcat(workstring1," ");
dtostrf(gps.satellites(),0,0,workstring2);
strcat(workstring1,workstring2);
strcat(workstring1," Sats");
tGPS.setText(workstring1);
last_gps_sats = gps.satellites();
} else {
tGPS.setText("");
}
last_clock_status = clock_status;
}
#endif //defined(FEATURE_GPS)
//GRID
#if defined(FEATURE_GPS) && defined(NEXTION_OBJNAME_GRID) && defined(NEXTION_OBJID_GRID)
if (((millis() - last_grid_update) > 5000) || (last_nextion_current_screen != nextion_current_screen)){
tGrid.setText(coordinates_to_maidenhead(latitude,longitude));
last_grid_update = millis();
}
#endif
//COORDINATES
#if defined(FEATURE_GPS) && defined(NEXTION_OBJNAME_COORDINATES) && defined(NEXTION_OBJID_COORDINATES)
if (((millis() - last_coord_update) > 5100) || (last_nextion_current_screen != nextion_current_screen)){
if ((clock_status == GPS_SYNC) || (clock_status == SLAVE_SYNC_GPS)) {
gps.f_get_position(&gps_lat_temp,&gps_long_temp,&gps_fix_age_temp);
dtostrf(gps_lat_temp,4,4,workstring1);
strcat(workstring1," ");
dtostrf(gps_long_temp,4,4,workstring2);
strcat(workstring1,workstring2);
strcat(workstring1," ");
dtostrf(gps.altitude()/100,0,0,workstring2);
strcat(workstring1,workstring2);
strcat(workstring1,"m");
tCoordinates.setText(workstring1);
} else {
tCoordinates.setText("");
}
last_coord_update = millis();
}
#endif
// STATUS3
#if defined(ANALOG_AZ_OVERLAP_DEGREES) || defined(FEATURE_PARK)
strcpy(workstring1,"");
#if defined(ANALOG_AZ_OVERLAP_DEGREES)
if (raw_azimuth > ANALOG_AZ_OVERLAP_DEGREES){
overlap_indicator = 1;
strcat(workstring1,TOUCH_DISPLAY_OVERLAP_STRING);
strcat(workstring1,"\r\n");
} else {
overlap_indicator = 0;
}
#endif
#if defined(FEATURE_PARK)
if (park_status == PARKED){
strcat(workstring1,TOUCH_DISPLAY_PARKED_STRING);
}
#endif
// output STATUS3
#if defined(FEATURE_PARK)
if ((park_status != last_park_status) || (last_nextion_current_screen != nextion_current_screen) || (((millis() - last_status3_update) > (NEXTION_DISPLAY_OVERLAP_UPDATE_MS)) && ((overlap_indicator != last_overlap_indicator) ))){
tStatus3.setText(workstring1);
last_overlap_indicator = overlap_indicator;
last_status3_update = millis();
}
#else
if ((last_nextion_current_screen != nextion_current_screen) || (((millis() - last_status3_update) > (NEXTION_DISPLAY_OVERLAP_UPDATE_MS)) && ((overlap_indicator != last_overlap_indicator)))){
tStatus3.setText(workstring1);
last_overlap_indicator = overlap_indicator;
last_status3_update = millis();
}
#endif
#endif
// STATUS
strcpy(workstring1,"");
#if !defined(FEATURE_ELEVATION_CONTROL) // ---------------- az only ----------------------------------------------
if ((az_state != last_az_state) || (last_nextion_current_screen != nextion_current_screen)) {
if (az_request_queue_state == IN_PROGRESS_TO_TARGET) {
if (current_az_state() == ROTATING_CW) {
strcpy(workstring1,CW_STRING);
} else {
if (current_az_state() == ROTATING_CCW){
strcpy(workstring1,CCW_STRING);
}
}
strcat(workstring1," ");
switch(configuration.azimuth_display_mode){
case AZ_DISPLAY_MODE_NORMAL:
case AZ_DISPLAY_MODE_OVERLAP_PLUS:
dtostrf(target_azimuth, 1, DISPLAY_DECIMAL_PLACES, workstring2);
break;
case AZ_DISPLAY_MODE_RAW:
dtostrf(target_raw_azimuth, 1, DISPLAY_DECIMAL_PLACES, workstring2);
break;
}
if ((configuration.azimuth_display_mode == AZ_DISPLAY_MODE_OVERLAP_PLUS) && (raw_azimuth > ANALOG_AZ_OVERLAP_DEGREES)){
strcat(workstring1,"+");
}
strcat(workstring1,workstring2);
strcat(workstring1,LCD_DISPLAY_DEGREES_STRING);
} else {
if (current_az_state() == ROTATING_CW) {
strcpy(workstring1,CW_STRING);
} else {
if (current_az_state() == ROTATING_CCW){
strcpy(workstring1,CCW_STRING);
}
}
}
//tStatus.setText(workstring1);
//last_az_state = az_state;
}
#else // az & el ----------------------------------------------------------------------------
if (az_state != IDLE){
if (az_request_queue_state == IN_PROGRESS_TO_TARGET) {
if (current_az_state() == ROTATING_CW) {
strcat(workstring1,CW_STRING);
} else {
if (current_az_state() == ROTATING_CCW) {
strcat(workstring1,CCW_STRING);
}
}
strcat(workstring1," ");
switch(configuration.azimuth_display_mode){
case AZ_DISPLAY_MODE_NORMAL:
case AZ_DISPLAY_MODE_OVERLAP_PLUS:
dtostrf(target_azimuth, 1, DISPLAY_DECIMAL_PLACES, workstring2);
break;
case AZ_DISPLAY_MODE_RAW:
dtostrf(target_raw_azimuth, 1, DISPLAY_DECIMAL_PLACES, workstring2);
break;
}
if ((configuration.azimuth_display_mode == AZ_DISPLAY_MODE_OVERLAP_PLUS) && (raw_azimuth > ANALOG_AZ_OVERLAP_DEGREES)){
strcat(workstring1,"+");
}
strcat(workstring1,workstring2);
strcat(workstring1,LCD_DISPLAY_DEGREES_STRING);
} else {
if (current_az_state() == ROTATING_CW) {
strcpy(workstring1,CW_STRING);
} else {
if (current_az_state() == ROTATING_CCW) {
strcpy(workstring1,CCW_STRING);
}
}
}
}
if (el_state != IDLE){
if (az_state != IDLE){
strcat(workstring1," ");
}
if (el_request_queue_state == IN_PROGRESS_TO_TARGET) {
if (current_el_state() == ROTATING_UP) {
strcat(workstring1,UP_STRING);
} else {
if (current_el_state() == ROTATING_DOWN) {
strcat(workstring1,DOWN_STRING);
}
}
strcat(workstring1," ");
dtostrf(target_elevation, 1, DISPLAY_DECIMAL_PLACES, workstring2);
strcat(workstring1,workstring2);
strcat(workstring1,LCD_DISPLAY_DEGREES_STRING);
} else {
if (current_el_state() == ROTATING_UP) {
strcat(workstring1,UP_STRING);
} else {
if (current_el_state() == ROTATING_DOWN) {
strcat(workstring1,DOWN_STRING);
}
}
}
}
#endif //!defined(FEATURE_ELEVATION_CONTROL)
// output STATUS
#if defined(FEATURE_ELEVATION_CONTROL)
if ((az_state != last_az_state) || (el_state != last_el_state) || (last_nextion_current_screen != nextion_current_screen)){
tStatus.setText(workstring1);
last_az_state = az_state;
last_el_state = el_state;
}
#else //defined(FEATURE_ELEVATION_CONTROL)
if ((az_state != last_az_state) || (last_nextion_current_screen != nextion_current_screen)){
tStatus.setText(workstring1);
last_az_state = az_state;
}
#endif //defined(FEATURE_ELEVATION_CONTROL)
// STATUS2
strcpy(workstring1,"");
#if defined(FEATURE_PARK)
if (park_status == PARK_INITIATED){
strcat(workstring1,TOUCH_DISPLAY_PARKING_STRING);
}
if ((park_status != last_park_status) || (last_nextion_current_screen != nextion_current_screen)){
tStatus2.setText(workstring1);
}
#endif
#if defined(FEATURE_PARK)
last_park_status = park_status;
#endif
} //if (nextion_current_screen == NEXTION_PAGE_MAIN_ID)
last_nextion_current_screen = nextion_current_screen;
// #ifdef FEATURE_MOON_TRACKING
// static unsigned long last_moon_tracking_check_time = 0;
// #endif
// #ifdef FEATURE_SUN_TRACKING
// static unsigned long last_sun_tracking_check_time = 0;
// #endif
// // OPTION_DISPLAY_DIRECTION_STATUS - azimuth direction display ***********************************************************************************
// #if defined(OPTION_DISPLAY_DIRECTION_STATUS)
// strcpy(workstring,azimuth_direction(azimuth)); // TODO - add left/right/center
// k3ngdisplay.print_center_fixed_field_size(workstring,LCD_DIRECTION_ROW-1,LCD_STATUS_FIELD_SIZE);
// #endif //defined(OPTION_DISPLAY_DIRECTION_STATUS)
// // OPTION_DISPLAY_MOON_TRACKING_CONTINUOUSLY *************************************************************
// #if defined(OPTION_DISPLAY_MOON_TRACKING_CONTINUOUSLY) && defined(FEATURE_MOON_TRACKING)
// // static unsigned long last_moon_tracking_check_time = 0;
// if (!row_override[LCD_MOON_TRACKING_ROW]){
// if (((millis()-last_moon_tracking_check_time) > LCD_MOON_TRACKING_UPDATE_INTERVAL)) {
// update_moon_position();
// last_moon_tracking_check_time = millis();
// }
// strcpy(workstring,"");
// if (moon_tracking_active){
// if (moon_visible){
// strcat(workstring,TRACKING_ACTIVE_CHAR);
// } else {
// strcat(workstring,TRACKING_INACTIVE_CHAR);
// }
// }
// strcat(workstring,MOON_STRING);
// dtostrf(moon_azimuth,0,DISPLAY_DECIMAL_PLACES,workstring2);
// strcat(workstring,workstring2);
// if ((LCD_COLUMNS>16) && ((moon_azimuth < 100) || (abs(moon_elevation)<100))) {strcat(workstring,LCD_DISPLAY_DEGREES_STRING);}
// strcat(workstring," ");
// dtostrf(moon_elevation,0,DISPLAY_DECIMAL_PLACES,workstring2);
// strcat(workstring,workstring2);
// if ((LCD_COLUMNS>16) && ((moon_azimuth < 100) || (abs(moon_elevation)<100))) {strcat(workstring,LCD_DISPLAY_DEGREES_STRING);}
// if (moon_tracking_active){
// if (moon_visible){
// strcat(workstring,TRACKING_ACTIVE_CHAR);
// } else {
// strcat(workstring,TRACKING_INACTIVE_CHAR);
// }
// }
// k3ngdisplay.print_center_fixed_field_size(workstring,LCD_MOON_TRACKING_ROW-1,LCD_COLUMNS);
// } else {
// #if defined(DEBUG_DISPLAY)
// debug.println(F("update_lcd_display: OPTION_DISPLAY_MOON_TRACKING_CONTINUOUSLY row override"));
// #endif
// }
// #endif //defined(OPTION_DISPLAY_MOON_TRACKING_CONTINUOUSLY) && defined(FEATURE_MOON_TRACKING)
// // OPTION_DISPLAY_SUN_TRACKING_CONTINUOUSLY **********************************************************
// #if defined(OPTION_DISPLAY_SUN_TRACKING_CONTINUOUSLY) && defined(FEATURE_SUN_TRACKING)
// // static unsigned long last_sun_tracking_check_time = 0;
// if (!row_override[LCD_SUN_TRACKING_ROW]){
// if ((millis()-last_sun_tracking_check_time) > LCD_SUN_TRACKING_UPDATE_INTERVAL) {
// update_sun_position();
// last_sun_tracking_check_time = millis();
// }
// strcpy(workstring,"");
// if (sun_tracking_active){
// if (sun_visible){
// strcat(workstring,TRACKING_ACTIVE_CHAR);
// } else {
// strcat(workstring,TRACKING_INACTIVE_CHAR);
// }
// }
// strcat(workstring,SUN_STRING);
// dtostrf(sun_azimuth,0,DISPLAY_DECIMAL_PLACES,workstring2);
// strcat(workstring,workstring2);
// if ((LCD_COLUMNS>16) && ((sun_azimuth < 100) || (abs(sun_elevation)<100))) {strcat(workstring,LCD_DISPLAY_DEGREES_STRING);}
// strcat(workstring," ");
// dtostrf(sun_elevation,0,DISPLAY_DECIMAL_PLACES,workstring2);
// strcat(workstring,workstring2);
// if ((LCD_COLUMNS>16) && ((sun_azimuth < 100) || (abs(sun_elevation)<100))) {strcat(workstring,LCD_DISPLAY_DEGREES_STRING);}
// if (sun_tracking_active){
// if (sun_visible){
// strcat(workstring,TRACKING_ACTIVE_CHAR);
// } else {
// strcat(workstring,TRACKING_INACTIVE_CHAR);
// }
// }
// k3ngdisplay.print_center_fixed_field_size(workstring,LCD_SUN_TRACKING_ROW-1,LCD_COLUMNS);
// } else {
// #if defined(DEBUG_DISPLAY)
// debug.println(F("update_lcd_display: OPTION_DISPLAY_SUN_TRACKING_CONTINUOUSLY row override"));
// #endif
// }
// #endif //defined(OPTION_DISPLAY_SUN_TRACKING_CONTINUOUSLY) && defined(FEATURE_SUN_TRACKING)
}
#endif // defined(FEATURE_NEXTION_DISPLAY_OLD)
// --------------------------------------------------------------
// #if defined(FEATURE_NEXTION_DISPLAY)
// uint16_t recvNextionRetString(char *buffer, uint16_t len, uint32_t timeout){
// uint16_t ret = 0;
// bool received_start_byte = false;
// uint8_t counter_0xff_bytes = 0;
// String temp = String("");
// uint8_t serial_byte = 0;
// unsigned long start;
// #if defined(DEBUG_NEXTION_DISPLAY_SERIAL_RECV)
// debug.print("\r\nrecvNextionRetString: rcv:");
// #endif
// start = millis();
// while ((millis() - start) <= timeout){
// while (nexSerial.available()){
// serial_byte = nexSerial.read();
// #if defined(DEBUG_NEXTION_DISPLAY_SERIAL_RECV)
// debug.write(serial_byte);
// #endif
// if (received_start_byte){
// if (serial_byte == 0xFF){
// counter_0xff_bytes++;
// if (counter_0xff_bytes >= 3){
// break;
// }
// } else {
// temp += (char)serial_byte;
// }
// } else if (serial_byte == 0x70){ //0x70 is starting byte that is discarded
// received_start_byte = true;
// }
// }
// if (counter_0xff_bytes >= 3){
// break;
// }
// }
// #if defined(DEBUG_NEXTION_DISPLAY_SERIAL_RECV)
// debug.println("$");
// if (millis() - start > timeout){
// debug.println("\r\nrecvNextionRetString: timeout");
// }
// #endif
// ret = temp.length();
// if (ret > len){
// ret = len;
// }
// strncpy(buffer, temp.c_str(), ret);
// return ret;
// }
// #endif //FEATURE_NEXTION_DISPLAY
// -------------------------------------------------------------- // --------------------------------------------------------------
#if defined(FEATURE_NEXTION_DISPLAY) #if defined(FEATURE_NEXTION_DISPLAY)
@ -4713,7 +4201,10 @@ void service_nextion_display(){
nextion_port_buffer_index = 0; nextion_port_buffer_index = 0;
received_backslash = 0; received_backslash = 0;
last_serial_receive_time = 0; last_serial_receive_time = 0;
strcpy(workstring2,"vConResult.txt=\"");
strcat(workstring2,return_string);
strcat(workstring2,"\"");
sendNextionCommand(workstring2);
#if defined(DEBUG_NEXTION_DISPLAY_SERIAL_RECV) #if defined(DEBUG_NEXTION_DISPLAY_SERIAL_RECV)
debug.print("\r\nservice_nextion_display: recv: return_string:"); debug.print("\r\nservice_nextion_display: recv: return_string:");
debug.println(return_string); debug.println(return_string);