Compare commits
3 commits
21a9aeeeac
...
48cdfdf2f8
| Author | SHA1 | Date | |
|---|---|---|---|
| 48cdfdf2f8 | |||
| b6ffac1372 | |||
| 34b785471b |
1 changed files with 58 additions and 15 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
#define GPS_UPDATE_FREQUENCY 10 //GPS update frequency per sec
|
#define GPS_UPDATE_FREQUENCY 10 //GPS update frequency per sec
|
||||||
#define DEBOUNCE_DELAY 250 //time in ms
|
#define DEBOUNCE_DELAY 250 //time in ms
|
||||||
#define MIDDLE_SCREEN_BRIGHTNESS 5
|
#define MIDDLE_SCREEN_BRIGHTNESS 5
|
||||||
|
//#define PROFILE true
|
||||||
|
|
||||||
//GPS
|
//GPS
|
||||||
SFE_UBLOX_GPS myGPS;
|
SFE_UBLOX_GPS myGPS;
|
||||||
|
|
@ -23,31 +24,40 @@ std::atomic_int gpsFixType(0);
|
||||||
//screen
|
//screen
|
||||||
Adafruit_AlphaNum4 disp = Adafruit_AlphaNum4();
|
Adafruit_AlphaNum4 disp = Adafruit_AlphaNum4();
|
||||||
unsigned long timeOfLastFix = 0UL;
|
unsigned long timeOfLastFix = 0UL;
|
||||||
|
unsigned long timer = millis();
|
||||||
|
bool setInitBrightness = false;
|
||||||
|
unsigned long brightnessTimer = millis();
|
||||||
|
|
||||||
//button
|
//button
|
||||||
volatile bool buttonPushed = false;
|
volatile bool buttonPushed = false;
|
||||||
volatile int ScreenBrightnessUser = 15;
|
volatile int ScreenBrightnessUser = 15;
|
||||||
volatile int screenBrightnessCurrent = ScreenBrightnessUser;
|
volatile int screenBrightnessCurrent = ScreenBrightnessUser;
|
||||||
volatile unsigned long lastButtonPush = 0UL;
|
volatile unsigned long lastButtonPush = 0UL;
|
||||||
|
volatile bool manualBrightness = false;
|
||||||
|
|
||||||
|
//profiler
|
||||||
|
int runCounter = 0;
|
||||||
|
unsigned long profileTimer = millis();
|
||||||
|
|
||||||
|
|
||||||
void chageBrightness() {
|
void chageBrightness() {
|
||||||
if (millis() - lastButtonPush > DEBOUNCE_DELAY) {
|
if (millis() - lastButtonPush > DEBOUNCE_DELAY) {
|
||||||
buttonPushed = true;
|
buttonPushed = true;
|
||||||
lastButtonPush = millis();
|
lastButtonPush = millis();
|
||||||
|
manualBrightness = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void connectGPS() { //need to do this everytime the GPS turns back on
|
void connectGPS() { //need to do this everytime the GPS turns back on
|
||||||
do { //set gps to 115200 baudrate code comes from sparkfun examples
|
do { //set gps to 115200 baudrate code comes from sparkfun examples
|
||||||
// Serial.println("GNSS: trying 115200 baud");
|
// Serial.println("GNSS: trying 115200 baud");
|
||||||
Serial1.begin(115200);
|
Serial1.begin(115200);
|
||||||
if (myGPS.begin(Serial1) == true) break;
|
if (myGPS.begin(Serial1) == true) break;
|
||||||
delay(100);
|
delay(100);
|
||||||
//Serial.println("GNSS: trying 9600 baud");
|
//Serial.println("GNSS: trying 9600 baud");
|
||||||
Serial1.begin(9600);
|
Serial1.begin(9600);
|
||||||
if (myGPS.begin(Serial1) == true) {
|
if (myGPS.begin(Serial1) == true) {
|
||||||
// Serial.println("GNSS: connected at 9600 baud, switching to 115200");
|
//Serial.println("GNSS: connected at 9600 baud, switching to 115200");
|
||||||
myGPS.setSerialRate(115200);
|
myGPS.setSerialRate(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -57,23 +67,36 @@ void connectGPS() { //need to do this everytime the GPS turns back on
|
||||||
myGPS.setAutoPVT(true);
|
myGPS.setAutoPVT(true);
|
||||||
myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART1 port to output UBX only (turn off NMEA noise)
|
myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART1 port to output UBX only (turn off NMEA noise)
|
||||||
myGPS.setNavigationFrequency(GPS_UPDATE_FREQUENCY); //set frequency of updates to 10/sec
|
myGPS.setNavigationFrequency(GPS_UPDATE_FREQUENCY); //set frequency of updates to 10/sec
|
||||||
myGPS.setDynamicModel(DYN_MODEL_AUTOMOTIVE); //set dynamic model of GPS to automotive to more accutate results
|
//myGPS.setDynamicModel(DYN_MODEL_AUTOMOTIVE); //set dynamic model of GPS to automotive to more accutate results
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setStartBrightness() {
|
bool setStartBrightness() {
|
||||||
while (!(myGPS.getFixType() > 0)) {} //wait here untill gps gets a fix
|
double az = 0;
|
||||||
double az, el;
|
double el = 0;
|
||||||
setTime(myGPS.getHour(),myGPS.getMinute(),myGPS.getSecond(),myGPS.getDay(),myGPS.getMonth(),myGPS.getYear());
|
int hour = myGPS.getHour();
|
||||||
time_t timeUtc=now();
|
int min = myGPS.getMinute();
|
||||||
calcHorizontalCoordinates(timeUtc,myGPS.getLatitude(),myGPS.getLongitude(),az,el);
|
int sec = myGPS.getSecond();
|
||||||
|
int day = myGPS.getDay();
|
||||||
|
int month = myGPS.getMonth();
|
||||||
|
int year = myGPS.getYear();
|
||||||
|
setTime(hour, min, sec, day, month, year);
|
||||||
|
time_t timeUtc = now();
|
||||||
|
double lat = myGPS.getLatitude();
|
||||||
|
lat = lat / 10000000;
|
||||||
|
double lng = myGPS.getLongitude();
|
||||||
|
lng = lng / 10000000;
|
||||||
|
calcHorizontalCoordinates(timeUtc, lat, lng, az, el);
|
||||||
|
|
||||||
if(el>SUNRISESET_STD_ALTITUDE){
|
//el = el - 180;
|
||||||
screenBrightnessCurrent=15;
|
|
||||||
} else if ((el<SUNRISESET_STD_ALTITUDE)&&(el>CIVIL_DAWNDUSK_STD_ALTITUDE)){
|
if (el > SUNRISESET_STD_ALTITUDE) {
|
||||||
screenBrightnessCurrent=MIDDLE_SCREEN_BRIGHTNESS;
|
screenBrightnessCurrent = 15;
|
||||||
} else if (el<CIVIL_DAWNDUSK_STD_ALTITUDE){
|
} else if ((el < SUNRISESET_STD_ALTITUDE) && (el > CIVIL_DAWNDUSK_STD_ALTITUDE)) {
|
||||||
screenBrightnessCurrent=0;
|
screenBrightnessCurrent = MIDDLE_SCREEN_BRIGHTNESS;
|
||||||
|
} else if (el < CIVIL_DAWNDUSK_STD_ALTITUDE) {
|
||||||
|
screenBrightnessCurrent = 0;
|
||||||
}
|
}
|
||||||
|
ScreenBrightnessUser = screenBrightnessCurrent;
|
||||||
disp.setBrightness(screenBrightnessCurrent);
|
disp.setBrightness(screenBrightnessCurrent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -97,10 +120,17 @@ void setup1() {
|
||||||
Serial1.setRX(1);
|
Serial1.setRX(1);
|
||||||
Serial1.setTX(0);
|
Serial1.setTX(0);
|
||||||
connectGPS();
|
connectGPS();
|
||||||
setStartBrightness();
|
//setStartBrightness();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
//set init brightness
|
||||||
|
if ((!setInitBrightness && gpsFixType.load() > 0) || ((!manualBrightness && millis() > brightnessTimer + 6000) && gpsFixType.load() > 0)) { //fire every minute
|
||||||
|
setStartBrightness();
|
||||||
|
setInitBrightness = true;
|
||||||
|
brightnessTimer = millis();
|
||||||
|
}
|
||||||
|
|
||||||
//change brightness
|
//change brightness
|
||||||
if (buttonPushed == true) {
|
if (buttonPushed == true) {
|
||||||
if (ScreenBrightnessUser == 15) {
|
if (ScreenBrightnessUser == 15) {
|
||||||
|
|
@ -159,8 +189,21 @@ void loop() {
|
||||||
}
|
}
|
||||||
disp.writeDisplay();
|
disp.writeDisplay();
|
||||||
rp2040.wdt_reset(); //rest watchdog timer
|
rp2040.wdt_reset(); //rest watchdog timer
|
||||||
|
|
||||||
|
#if PROFILE
|
||||||
|
//profiling
|
||||||
|
runCounter++;
|
||||||
|
|
||||||
|
if(millis() > profileTimer + 1000){
|
||||||
|
Serial.println(runCounter);
|
||||||
|
runCounter=0;
|
||||||
|
profileTimer=millis();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop1() {
|
void loop1() {
|
||||||
//myGPS.getPVT(GPS_WAIT_TIME);
|
//myGPS.getPVT(GPS_WAIT_TIME);
|
||||||
speed.store(myGPS.getGroundSpeed() * 0.0036); //get speed in mm/s and convert to Km/h
|
speed.store(myGPS.getGroundSpeed() * 0.0036); //get speed in mm/s and convert to Km/h
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue