sunset/sunrise + backlight

This commit is contained in:
Geronius 2022-04-02 00:27:56 +02:00
parent 40b7daad16
commit 1ba65d784c
7 changed files with 33 additions and 59 deletions

View File

@ -233,13 +233,14 @@ SensorData calcSunsetSunrise(double time, double date, double latitude, double l
int intminSR = 0; int intminSR = 0;
int inthrSS = 0; int inthrSS = 0;
int intminSS = 0; int intminSS = 0;
bool sunDown = true;
// Calculate local time
time_t t = (date * secPerYear) + (time + int(timezone * secPerHour));
// api->getLogger()->logDebug(GwLog::DEBUG,"... PageClock: Lat %f, Lon %f, at: %d, next SR: %d (%s), next SS: %d (%s)", latitude, longitude, t, sunR, sSunR, sunS, sSunS); // api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: Lat %f, Lon %f, at: %d, next SR: %d (%s), next SS: %d (%s)", latitude, longitude, t, sunR, sSunR, sunS, sSunS);
if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) { if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) {
// Calculate local time
time_t t = (date * secPerYear) + (time + int(timezone * secPerHour));
sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH
// Sunrise // Sunrise
if (sr.hasRise) { if (sr.hasRise) {
@ -253,48 +254,20 @@ SensorData calcSunsetSunrise(double time, double date, double latitude, double l
inthrSS = int (sunS / secPerHour); inthrSS = int (sunS / secPerHour);
intminSS = int((sunS - inthrSS * secPerHour)/60); intminSS = int((sunS - inthrSS * secPerHour)/60);
} }
// Sun control (return value by sun on sky = false, sun down = true)
if ((t >= (sr.riseTime + int(timezone * secPerHour))) && (t <= (sr.setTime + int(timezone * secPerHour))))
sunDown = false;
else sunDown = true;
} }
// Return values // Return values
returnset.sunsetHour = inthrSS; returnset.sunsetHour = inthrSS;
returnset.sunsetMinute = intminSS; returnset.sunsetMinute = intminSS;
returnset.sunriseHour = inthrSR; returnset.sunriseHour = inthrSR;
returnset.sunriseMinute = intminSR; returnset.sunriseMinute = intminSR;
returnset.sunDown = sunDown;
// api->getLogger()->logDebug(GwLog::DEBUG,"... PageClock: at t: %d, hasRise: %d, next SR: %d '%s', hasSet: %d, next SS: %d '%s'\n", t, sr.hasRise, sr.riseTime, sSunR, sr.hasSet, sr.setTime, sSunS); // api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: at t: %d, hasRise: %d, next SR: %d '%s', hasSet: %d, next SS: %d '%s'\n", t, sr.hasRise, sr.riseTime, sSunR, sr.hasSet, sr.setTime, sSunS);
return returnset; return returnset;
} }
// Sun control (return valu by sun on sky = false, sun down = true)
bool sunControl(double time, double date, double latitude, double longitude, double timezone){
SunRise sr;
int secPerHour = 3600;
int secPerYear = 86400;
sr.hasRise = false;
sr.hasSet = false;
time_t sunR = 0;
time_t sunS = 0;
// Calculate local time
time_t t = (date * secPerYear) + (time + int(timezone * secPerHour));
if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) {
sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH
// Sunrise
if (sr.hasRise) {
sunR = (sr.riseTime + int(timezone * secPerHour) + 30); // add 30 seconds: round to minutes
}
// Sunset
if (sr.hasSet) {
sunS = (sr.setTime + int(timezone * secPerHour) + 30); // add 30 seconds: round to minutes
}
}
// Return values (sun on sky = false, sun down = true)
if(t > sunR && t < sunS){
return false;
}
else{
return true;
}
}
#endif #endif

View File

@ -43,6 +43,6 @@ void displayTrendLow(int16_t x, int16_t y, uint16_t size, uint16_t color);
void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatValue *time); // Draw display header void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatValue *time); // Draw display header
SensorData calcSunsetSunrise(double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise SensorData calcSunsetSunrise(double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise
bool sunControl(double time, double date, double latitude, double longitude, double timezone); // Control bit for sun //bool sunControl(double time, double date, double latitude, double longitude, double timezone); // Control bit for sun
#endif #endif

View File

@ -14,7 +14,9 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
static int dayoffset = 0; static int dayoffset = 0;
// Load configuration values // Load configuration values
int timeZone = commondata.config->getInt(commondata.config->timeZone); // [UTC -12...+14]
String stimeZone = commondata.config->getString(commondata.config->timeZone); // [UTC -14.00...+12.00]
double timeZone = stimeZone.toDouble();
String lengthFormat = commondata.config->getString(commondata.config->lengthFormat); // [m|ft] String lengthFormat = commondata.config->getString(commondata.config->lengthFormat); // [m|ft]
String distanceFormat = commondata.config->getString(commondata.config->distanceFormat); // [m|km|nm] String distanceFormat = commondata.config->getString(commondata.config->distanceFormat); // [m|km|nm]
String speedFormat = commondata.config->getString(commondata.config->speedFormat); // [m/s|km/h|kn] String speedFormat = commondata.config->getString(commondata.config->speedFormat); // [m/s|km/h|kn]
@ -28,6 +30,8 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
result.svalue = "---"; result.svalue = "---";
return result; return result;
} }
LOG_DEBUG(GwLog::DEBUG,"formatValue init: getFormat: %s date->value: %f time->value: %f", value->getFormat(), commondata.date->value, commondata.time->value);
static const int bsize = 30; static const int bsize = 30;
char buffer[bsize+1]; char buffer[bsize+1];
buffer[0]=0; buffer[0]=0;

View File

@ -147,13 +147,11 @@ public:
} }
// Show values sunrise // Show values sunrise
String sunrise = ""; String sunrise = "---";
if(valid1 == true && valid2 == true){ if(valid1 == true && valid2 == true){
sunrise = String(commonData.data.sunriseHour) + ":" + String(commonData.data.sunriseMinute); sunrise = String(commonData.data.sunriseHour) + ":" + String(commonData.data.sunriseMinute + 100).substring(1);
}
else{
sunrise = "---";
} }
display.setTextColor(textcolor); display.setTextColor(textcolor);
display.setFont(&Ubuntu_Bold8pt7b); display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(335, 65); display.setCursor(335, 65);
@ -166,13 +164,13 @@ public:
display.fillRect(340, 149, 80, 3, pixelcolor); display.fillRect(340, 149, 80, 3, pixelcolor);
// Show values sunset // Show values sunset
String sunset = ""; String sunset = "---";
if(valid1 == true && valid2 == true){ if(valid1 == true && valid2 == true){
sunset= String(commonData.data.sunsetHour) + ":" + String(commonData.data.sunsetMinute); sunset = String(commonData.data.sunsetHour) + ":" + String(commonData.data.sunsetMinute + 100).substring(1);
}
else{
sunset = "---";
} }
LOG_DEBUG(GwLog::LOG,"sunrise: .%s., sunset: .%s.", String(commonData.data.sunriseMinute + 100), String(commonData.data.sunsetMinute + 100));
display.setTextColor(textcolor); display.setTextColor(textcolor);
display.setFont(&Ubuntu_Bold8pt7b); display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(335, 250); display.setCursor(335, 250);

View File

@ -47,6 +47,7 @@ typedef struct{
int sunsetMinute = 0; int sunsetMinute = 0;
int sunriseHour = 0; int sunriseHour = 0;
int sunriseMinute = 0; int sunriseMinute = 0;
bool sunDown = true;
} SensorData; } SensorData;
typedef struct{ typedef struct{

View File

@ -391,13 +391,13 @@ void OBP60Task(GwApi *api){
setPortPin(OBP_FLASH_LED, true); setPortPin(OBP_FLASH_LED, true);
} }
// Back light with sun control // Back light with sun control: turn on if no valid data for safety reasons
if(String(backlight) == "Control by Sun"){ if(String(backlight) == "Control by Sun"){
if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){ if(time->valid == false || date->valid == false || lat->valid == false || lon->valid == false){
setPortPin(OBP_BACKLIGHT_LED, sunControl(time->value, date->value, lat->value, lon->value, tz.toDouble())); setPortPin(OBP_BACKLIGHT_LED, true);
} }
} }
// Check the keyboard message // Check the keyboard message
int keyboardMessage=0; int keyboardMessage=0;
while (xQueueReceive(allParameters.queue,&keyboardMessage,0)){ while (xQueueReceive(allParameters.queue,&keyboardMessage,0)){
@ -454,10 +454,8 @@ void OBP60Task(GwApi *api){
if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){ if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){
commonData.data = calcSunsetSunrise(time->value , date->value, lat->value, lon->value, tz.toDouble()); commonData.data = calcSunsetSunrise(time->value , date->value, lat->value, lon->value, tz.toDouble());
// Backlight with sun control // Backlight with sun control
if(String(backlight) == "Control by Sun"){ if(String(backlight) == "Control by Sun"){
if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){ setPortPin(OBP_BACKLIGHT_LED, commonData.data.sunDown);
setPortPin(OBP_BACKLIGHT_LED, sunControl(time->value, date->value, lat->value, lon->value, tz.toDouble()));
}
} }
} }
} }

View File

@ -22,6 +22,6 @@ lib_deps =
build_flags= build_flags=
-D BOARD_NODEMCU32S_OBP60 -D BOARD_NODEMCU32S_OBP60
${env.build_flags} ${env.build_flags}
upload_port = COM3 upload_port = COM6
upload_protocol = esptool upload_protocol = esptool
monitor_speed = 115200 monitor_speed = 115200