Implementation of sunrise and sunset
This commit is contained in:
parent
eaec09a29c
commit
dca9d96957
|
@ -1,9 +1,10 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "SunRise.h" // Lib for sunrise and sunset calculation
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60Hardware.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
// Please dont forget to declarate the fonts in OBP60ExtensionPort.h
|
||||
#include "Ubuntu_Bold8pt7b.h"
|
||||
|
@ -121,6 +122,7 @@ void displayTrendLow(int16_t x, int16_t y, uint16_t size, uint16_t color){
|
|||
display.fillTriangle(x, y, x+size*2, y, x+size, y+size*2, color);
|
||||
}
|
||||
|
||||
// Show header informations
|
||||
void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatValue *time){
|
||||
|
||||
static bool heartbeat = false;
|
||||
|
@ -217,4 +219,49 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa
|
|||
}
|
||||
}
|
||||
|
||||
// Sunset und sunrise calculation
|
||||
SensorData calcSunsetSunrise(double time, double date, double latitude, double longitude, double timezone){
|
||||
SensorData returnset;
|
||||
SunRise sr;
|
||||
int secPerHour = 3600;
|
||||
int secPerYear = 86400;
|
||||
sr.hasRise = false;
|
||||
sr.hasSet = false;
|
||||
time_t sunR = 0;
|
||||
time_t sunS = 0;
|
||||
int inthrSR = 0;
|
||||
int intminSR = 0;
|
||||
int inthrSS = 0;
|
||||
int intminSS = 0;
|
||||
|
||||
// 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);
|
||||
|
||||
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) % secPerYear; // add 30 seconds: round to minutes
|
||||
inthrSR = int (sunR / secPerHour);
|
||||
intminSR = int((sunR - inthrSR * secPerHour)/60);
|
||||
}
|
||||
// Sunset
|
||||
if (sr.hasSet) {
|
||||
sunS = (sr.setTime + int(timezone * secPerHour) + 30) % secPerYear; // add 30 seconds: round to minutes
|
||||
inthrSS = int (sunS / secPerHour);
|
||||
intminSS = int((sunS - inthrSS * secPerHour)/60);
|
||||
}
|
||||
}
|
||||
// Return values
|
||||
returnset.sunsetHour = inthrSS;
|
||||
returnset.sunsetMinute = intminSS;
|
||||
returnset.sunriseHour = inthrSR;
|
||||
returnset.sunriseMinute = intminSR;
|
||||
|
||||
// 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);
|
||||
return returnset;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -42,4 +42,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
|
||||
|
||||
SensorData calcSunsetSunrise(double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise
|
||||
|
||||
#endif
|
|
@ -12,9 +12,8 @@
|
|||
#include "N2kMessages.h"
|
||||
#include "NMEA0183.h"
|
||||
#include "ObpNmea0183.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
#include "movingAvg.h" // Lib for moving average building
|
||||
#include "SunRise.h" // Lib for sunrise and sunset calculation
|
||||
|
||||
// Timer Interrupts for hardware functions
|
||||
void underVoltageDetection();
|
||||
|
@ -53,50 +52,6 @@ void underVoltageDetection(){
|
|||
undervoltage = false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
SensorData calcSunsetSunrise(double time, double date, double latitude, double longitude, int timezone){
|
||||
SensorData returnset;
|
||||
SunRise sr;
|
||||
int secPerHour = 3600;
|
||||
int secPerYear = 86400;
|
||||
sr.hasRise = false;
|
||||
sr.hasSet = false;
|
||||
time_t sunR = 0;
|
||||
time_t sunS = 0;
|
||||
int inthrSR = 0;
|
||||
int intminSR = 0;
|
||||
int inthrSS = 0;
|
||||
int intminSS = 0;
|
||||
|
||||
// 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);
|
||||
|
||||
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) % secPerYear; // add 30 seconds: round to minutes
|
||||
inthrSR = int (sunR / secPerHour);
|
||||
intminSR = int((sunR - inthrSR * secPerHour)/60);
|
||||
}
|
||||
// Sunset
|
||||
if (sr.hasSet) {
|
||||
sunS = (sr.setTime + int(timezone * secPerHour) + 30) % secPerYear; // add 30 seconds: round to minutes
|
||||
inthrSS = int (sunS / secPerHour);
|
||||
intminSS = int((sunS - inthrSS * secPerHour)/60);
|
||||
}
|
||||
}
|
||||
// Return values
|
||||
returnset.sunsetHour = inthrSS;
|
||||
returnset.sunsetMinute = intminSS;
|
||||
returnset.sunriseHour = inthrSR;
|
||||
returnset.sunriseMinute = intminSR;
|
||||
// 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);
|
||||
return returnset;
|
||||
}
|
||||
*/
|
||||
|
||||
// Initialization for all sensors (RS232, I2C, 1Wire, IOs)
|
||||
//####################################################################################
|
||||
|
@ -140,17 +95,7 @@ void sensorTask(void *param){
|
|||
Timer1.start(); // Start Timer1 for undervoltage detection
|
||||
}
|
||||
Timer2.start(); // Start Timer2 for blinking LED
|
||||
/*
|
||||
// Calculate sunset and sunrise at start time
|
||||
double actTime = 0;
|
||||
double actDate = 0;
|
||||
double actLatitude = 53.23;
|
||||
double actLongitude = 9.16;
|
||||
int actTimeZone = api->getConfig()->getConfigItem(api->getConfig()->timeZone, true)->asInt();
|
||||
// GwApi::BoatValue *date = boatValues.findValueOrCreate("GPSD"); // Load GpsDate
|
||||
// GwApi::BoatValue *time = boatValues.findValueOrCreate("GPST"); // Load GpsTime
|
||||
sensors = calcSunsetSunrise(actTime, actDate, actLatitude, actLongitude, actTimeZone); // copy sunrise and sunset to sensor data
|
||||
*/
|
||||
|
||||
// Settings for NMEA0183
|
||||
String nmea0183Mode = api->getConfig()->getConfigItem(api->getConfig()->serialDirection, true)->asString();
|
||||
api->getLogger()->logDebug(GwLog::LOG, "NMEA0183 Mode is: %s", nmea0183Mode);
|
||||
|
@ -285,7 +230,7 @@ void sensorTask(void *param){
|
|||
else{
|
||||
api->getLogger()->logDebug(GwLog::LOG,"Modul 1 INA226 found");
|
||||
shuntResistor = SHUNT_VOLTAGE / float(shunt1.toInt()); // Calculate shunt resisitor for max. shunt voltage 75mV
|
||||
maxCurrent = float(shunt1.toInt());
|
||||
maxCurrent = shunt1.toFloat();
|
||||
api->getLogger()->logDebug(GwLog::LOG,"Calibation INA226, Imax:%3.0fA Rs:%7.5fOhm Us:%5.3f", maxCurrent, shuntResistor, SHUNT_VOLTAGE);
|
||||
// ina226_1.setMaxCurrentShunt(maxCurrent, shuntResistor);
|
||||
ina226_1.setMaxCurrentShunt(10, 0.01); // Calibration with fix values (because the original values outer range)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageApparentWind : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageBME280 : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageBattery : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageBattery2 : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageClock : public Page
|
||||
{
|
||||
|
@ -147,45 +147,39 @@ public:
|
|||
}
|
||||
|
||||
// Show values sunrise
|
||||
display.setTextColor(textcolor);
|
||||
if(holdvalues == false){
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
display.setCursor(335, 65);
|
||||
display.print("06:32"); // Value
|
||||
display.setFont(&Ubuntu_Bold12pt7b);
|
||||
display.setCursor(335, 95);
|
||||
display.print("SunR"); // Name
|
||||
String sunrise = "";
|
||||
if(valid1 == true && valid2 == true){
|
||||
sunrise = String(commonData.data.sunriseHour) + ":" + String(commonData.data.sunriseMinute);
|
||||
}
|
||||
else{
|
||||
sunrise = "---";
|
||||
}
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
display.setCursor(335, 65);
|
||||
display.print("06:32"); // Value
|
||||
display.print(sunrise); // Value
|
||||
display.setFont(&Ubuntu_Bold12pt7b);
|
||||
display.setCursor(335, 95);
|
||||
display.print("SunR"); // Name
|
||||
}
|
||||
|
||||
// Horizintal separator right
|
||||
display.fillRect(340, 149, 80, 3, pixelcolor);
|
||||
|
||||
// Show values sunset
|
||||
display.setTextColor(textcolor);
|
||||
if(holdvalues == false){
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
display.setCursor(335, 250);
|
||||
display.print("18:22"); // Value
|
||||
display.setFont(&Ubuntu_Bold12pt7b);
|
||||
display.setCursor(335, 220);
|
||||
display.print("SunS"); // Name
|
||||
String sunset = "";
|
||||
if(valid1 == true && valid2 == true){
|
||||
sunset= String(commonData.data.sunsetHour) + ":" + String(commonData.data.sunsetMinute);
|
||||
}
|
||||
else{
|
||||
sunset = "---";
|
||||
}
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
display.setCursor(335, 250);
|
||||
display.print("18:22"); // Value
|
||||
display.print(sunset); // Value
|
||||
display.setFont(&Ubuntu_Bold12pt7b);
|
||||
display.setCursor(335, 220);
|
||||
display.print("SunS"); // Name
|
||||
}
|
||||
|
||||
//*******************************************************************************************
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageDST810 : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageFourValues : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageFourValues2 : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageKeelPosition : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageOneValue : public Page{
|
||||
bool keylock = false; // Keylock
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageRudderPosition : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageThreeValues : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageTwoValues : public Page
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
#include "movingAvg.h" // Lib for moving average building
|
||||
|
||||
class PageVoltage : public Page
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageWhite : public Page{
|
||||
bool keylock = false; // Keylock
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef BOARD_NODEMCU32S_OBP60
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
#include "OBP60Extensions.h"
|
||||
|
||||
class PageWindRose : public Page
|
||||
{
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
"name": "timeZone",
|
||||
"label": "Time Zone",
|
||||
"type": "number",
|
||||
"default": "0",
|
||||
"default": "0.00",
|
||||
"check": "checkMinMax",
|
||||
"min": -12,
|
||||
"max": 14,
|
||||
"min": -12.00,
|
||||
"max": 14.00,
|
||||
"description": "Time zone [UTC -12...+14]",
|
||||
"category": "OBP60 Settings",
|
||||
"capabilities": {
|
||||
|
@ -17,10 +17,10 @@
|
|||
"name": "draft",
|
||||
"label": "Boat Draft [m]",
|
||||
"type": "number",
|
||||
"default": "0",
|
||||
"default": "0.00",
|
||||
"check": "checkMinMax",
|
||||
"min": 0,
|
||||
"max": 10,
|
||||
"min": 0.00,
|
||||
"max": 10.00,
|
||||
"description": "The draft of the boat [0...10m]",
|
||||
"category": "OBP60 Settings",
|
||||
"capabilities": {
|
||||
|
@ -45,10 +45,10 @@
|
|||
"name": "fuelConsumption",
|
||||
"label": "Fuel Consuption [l/h]",
|
||||
"type": "number",
|
||||
"default": "0",
|
||||
"default": "0.00",
|
||||
"check": "checkMinMax",
|
||||
"min": 0,
|
||||
"max": 1000,
|
||||
"min": 0.00,
|
||||
"max": 1000.00,
|
||||
"description": "Medium fuel consumption [0...1000l/h]",
|
||||
"category": "OBP60 Settings",
|
||||
"capabilities": {
|
||||
|
@ -119,10 +119,10 @@
|
|||
"name": "batteryCapacity",
|
||||
"label": "Battery Capacity [Ah]",
|
||||
"type": "number",
|
||||
"default": "0",
|
||||
"default": "0.0",
|
||||
"check": "checkMinMax",
|
||||
"min": 0,
|
||||
"max": 10000,
|
||||
"min": 0.0,
|
||||
"max": 10000.0,
|
||||
"description": "Battery capacity [0...10000Ah]",
|
||||
"category": "OBP60 Settings",
|
||||
"capabilities": {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <NMEA0183Msg.h>
|
||||
#include <NMEA0183Messages.h>
|
||||
#include <GxEPD.h> // GxEPD lib for E-Ink displays
|
||||
#include "OBP60ExtensionPort.h" // Functions lib for extension board
|
||||
#include "OBP60Extensions.h" // Functions lib for extension board
|
||||
#include "OBP60Keypad.h" // Functions for keypad
|
||||
|
||||
// True type character sets includes
|
||||
|
@ -63,6 +63,7 @@ void OBP60Init(GwApi *api){
|
|||
if(String(ledMode) == "Off"){
|
||||
setBlinkingLED(false);
|
||||
}
|
||||
|
||||
// Marker for init complete
|
||||
// Used in OBP60Task()
|
||||
initComplete = true;
|
||||
|
@ -338,6 +339,8 @@ void OBP60Task(GwApi *api){
|
|||
// Configuration values for main loop
|
||||
String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
|
||||
String backlight = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString();
|
||||
String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
|
||||
String tz = api->getConfig()->getConfigItem(api->getConfig()->timeZone,true)->asString();
|
||||
|
||||
// refreshmode defined in init section
|
||||
// displaycolor defined in init section
|
||||
|
@ -346,9 +349,10 @@ void OBP60Task(GwApi *api){
|
|||
// bgcolor defined in init section
|
||||
|
||||
// Boat values for main loop
|
||||
GwApi::BoatValue *hdop = boatValues.findValueOrCreate("HDOP"); // Load HDOP
|
||||
GwApi::BoatValue *date = boatValues.findValueOrCreate("GPSD"); // Load GpsDate
|
||||
GwApi::BoatValue *time = boatValues.findValueOrCreate("GPST"); // Load GpsTime
|
||||
GwApi::BoatValue *lat = boatValues.findValueOrCreate("LAT"); // Load GpsLatitude
|
||||
GwApi::BoatValue *lon = boatValues.findValueOrCreate("LON"); // Load GpsLongitude
|
||||
|
||||
LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop");
|
||||
int pageNumber=0;
|
||||
|
@ -363,6 +367,7 @@ void OBP60Task(GwApi *api){
|
|||
long starttime2 = millis(); // Full display refresh after 5 min
|
||||
long starttime3 = millis(); // Display update all 1s
|
||||
long starttime4 = millis(); // Delayed display update after 4s when select a new page
|
||||
long starttime5 = millis(); // Calculate sunrise and sunset all 1s
|
||||
|
||||
|
||||
// Main loop runs with 100ms
|
||||
|
@ -436,6 +441,14 @@ void OBP60Task(GwApi *api){
|
|||
LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber);
|
||||
}
|
||||
|
||||
// Calculate sunrise and sunset all 1s
|
||||
if(millis() > starttime5 + 1000){
|
||||
starttime5 = millis();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
// Full display update afer a new selected page and 4s wait time
|
||||
if(millis() > starttime4 + 4000 && delayedDisplayUpdate == true){
|
||||
display.update(); // Full update
|
||||
|
|
Loading…
Reference in New Issue