changed method for detecting sun start time brightness from time to sun position in sky

This commit is contained in:
Seth Samuel 2024-11-04 20:57:47 +13:00
parent 041c51042d
commit 21a9aeeeac
3 changed files with 9 additions and 180 deletions

View file

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <atomic>
#include <SolarCalculator.h> //for determining startup brightness
#include <TimeLib.h>
#define DISPLAY_ADDRESS 0x70 //I2C address of screen
#define GPS_WAIT_TIME 1100
#define GPS_UPDATE_FREQUENCY 10 //GPS update frequency per sec
@ -14,13 +15,6 @@
//GPS
SFE_UBLOX_GPS myGPS;
double lat = 0;
double lng = 0;
int tzOff = 12; //local TZ offset
bool centuryBit; //needed to get month from RTC
double az, elev; //for sun location in the sky
double transit, sunrise, sunset; //sun related times
double civilTransit, civilRiise, civilSet; //astro related times
//threading
std::atomic<float> speed(0);
@ -30,11 +24,6 @@ std::atomic_int gpsFixType(0);
Adafruit_AlphaNum4 disp = Adafruit_AlphaNum4();
unsigned long timeOfLastFix = 0UL;
//speed calc
//float averageSpeed = 0;
//int speedSlot = 0; //for placing the speed in the array for smoothing
//float *speedArray;
//button
volatile bool buttonPushed = false;
volatile int ScreenBrightnessUser = 15;
@ -72,19 +61,17 @@ void connectGPS() { //need to do this everytime the GPS turns back on
}
bool setStartBrightness() {
while (!(myGPS.getFixType() > 0)) {}
double GPSTime=myGPS.getHour()+(myGPS.getMinute()/60);
while (!(myGPS.getFixType() > 0)) {} //wait here untill gps gets a fix
double az, el;
setTime(myGPS.getHour(),myGPS.getMinute(),myGPS.getSecond(),myGPS.getDay(),myGPS.getMonth(),myGPS.getYear());
time_t timeUtc=now();
calcHorizontalCoordinates(timeUtc,myGPS.getLatitude(),myGPS.getLongitude(),az,el);
//get sunset time
calcSunriseSunset(myGPS.getYear(), myGPS.getMonth(), myGPS.getDay(), lat, lng, transit, sunrise, sunset);
//get civilSet time
calcCivilDawnDusk(myGPS.getYear(), myGPS.getMonth(), myGPS.getDay(), lat, lng, civilTransit, civilRiise, civilSet);
if(GPSTime<sunset){
if(el>SUNRISESET_STD_ALTITUDE){
screenBrightnessCurrent=15;
} else if ((GPSTime>sunrise)&&(GPSTime<civilSet)){
} else if ((el<SUNRISESET_STD_ALTITUDE)&&(el>CIVIL_DAWNDUSK_STD_ALTITUDE)){
screenBrightnessCurrent=MIDDLE_SCREEN_BRIGHTNESS;
} else if (GPSTime>civilSet){
} else if (el<CIVIL_DAWNDUSK_STD_ALTITUDE){
screenBrightnessCurrent=0;
}
disp.setBrightness(screenBrightnessCurrent);