WIP
прошивка по записи RTC для старых часов rally
This commit is contained in:
35
GPS_com.cpp
35
GPS_com.cpp
@@ -11,10 +11,11 @@
|
||||
#include "GPS_com.h"
|
||||
#include "RTC_com.h" // to set the RTC
|
||||
#include "Serial_AdjustBaud.h" // for adjust serial port baudrate
|
||||
#include "LocalDateTime.h"
|
||||
|
||||
#define cfg_pin_GPS_PPS 2
|
||||
#define cfg_pin_GPS_Rx 8
|
||||
//#define cfg_pin_GPS_Tx 9;
|
||||
#define cfg_pin_GPS_Tx 9
|
||||
|
||||
// add the static modifier to limit visibility of these variables to just this file
|
||||
static byte GPS_PPS_PIN = cfg_pin_GPS_PPS; // Pin 2 = NANO INT0, GPS PPS interrupt signal on this Pin
|
||||
@@ -23,10 +24,11 @@ static int pulse_count = 0;
|
||||
static time_t gps_seconds_t = 0; // GPS time
|
||||
static byte gps_sats = 0;
|
||||
volatile bool GPS_sec = false; // flag for GPS-PPS
|
||||
unsigned long GPSMillis;
|
||||
|
||||
// set interrupt flag
|
||||
void gps_interrupt() {
|
||||
//Serial.print("DEBUG[INT] GPS interrupt "); Serial.println(micros());
|
||||
GPSMillis = micros();
|
||||
GPS_sec = true;
|
||||
}
|
||||
|
||||
@@ -76,12 +78,10 @@ const char RMC_off [] PROGMEM = "PUBX,40,RMC,0,0,0,0";
|
||||
const char ZDA_off [] PROGMEM = "PUBX,40,ZDA,0,0,0,0";
|
||||
const char RMC_on [] PROGMEM = "PUBX,40,RMC,0,1,0,0";
|
||||
const char ZDA_on [] PROGMEM = "PUBX,40,ZDA,0,1,0,0";
|
||||
bool GPS_PPS_LCD;
|
||||
|
||||
void GPS_setup() {
|
||||
DEBUG_PORT.begin(38400);
|
||||
DEBUG_PORT.println(F("DEBUG[GPS_setup()] start"));
|
||||
pinMode(GPS_PPS_PIN, INPUT_PULLUP); // enable pullup on interrupt pin
|
||||
attachInterrupt(digitalPinToInterrupt(GPS_PPS_PIN), gps_interrupt, RISING); // 100ms HIGH at start of second
|
||||
GPS_sec = false;
|
||||
if (detRate(cfg_pin_GPS_Rx) != 38400) {
|
||||
DEBUG_PORT.println(F("DEBUG[GPS_setup()] baudrate not 38400"));
|
||||
@@ -113,25 +113,46 @@ void GPS_setup() {
|
||||
delay(100);
|
||||
gps.send_P(&gpsPort, (const __FlashStringHelper *) ZDA_on);
|
||||
delay(100);
|
||||
|
||||
pinMode(GPS_PPS_PIN, INPUT_PULLUP); // enable pullup on interrupt pin
|
||||
attachInterrupt(digitalPinToInterrupt(GPS_PPS_PIN), gps_interrupt, RISING); // 100ms HIGH at start of second
|
||||
GPS_ON();
|
||||
}
|
||||
|
||||
void GPS_loop() {
|
||||
|
||||
if (GPS_sec) { // do after GPS PPS interrupt
|
||||
GPS_sec = false; // clear flag
|
||||
|
||||
lcd.setCursor(2, 0); GPS_PPS_LCD = !GPS_PPS_LCD;
|
||||
lcd.print((GPS_PPS_LCD) ? " " : ":");
|
||||
GPS_PPS();
|
||||
}
|
||||
GPS_read_seconds(); // continue reading buffer
|
||||
}
|
||||
|
||||
void GPS_PPS() { // do something on the flip of the GPS second
|
||||
int32_t drift = (RTCMillis - GPSMillis); // % (4294967295UL);
|
||||
|
||||
//DEBUG_PORT.println("DEBUG[GPS_PPS()] Start");
|
||||
if (drift > 900000)
|
||||
drift -= 1000000;
|
||||
else if (drift < -900000)
|
||||
drift += 1000000;
|
||||
|
||||
//DEBUG_PORT.println("DEBUG[GPS_loop()] drift: " + String(drift));
|
||||
|
||||
lcd.setCursor((16 - sizeof(String(drift))), 1);
|
||||
lcd.print(drift);
|
||||
|
||||
if (drift > 5000 && !gps_on) GPS_ON();
|
||||
if (gps_on) { // do only when needed
|
||||
pulse_count += 1;
|
||||
if (pulse_count > 2) { // skip first PPS-Pulses, to make shure time is from satellite
|
||||
if (gps_seconds_t != 0) { // do only if value is set
|
||||
// gps_seconds_t += offset_28y; // debug & testing only!
|
||||
// gps_seconds_t += offset_26w; // debug & testing only!
|
||||
SetRTC(gps_seconds_t); // sync RTC with GPS
|
||||
SetRTC(TZ_Sec(gps_seconds_t)); // sync RTC with GPS
|
||||
GPS_OFF();
|
||||
}
|
||||
}
|
||||
@@ -152,10 +173,10 @@ void GPS_read_seconds() {
|
||||
}
|
||||
|
||||
void GPS_ON() {
|
||||
DEBUG_PORT.println("DEBUG[GPS_ON()] Start");
|
||||
gps_on = true;
|
||||
gps_seconds_t = 0; // make shure GPS serial is alive before setting
|
||||
pulse_count = 0;
|
||||
//Serial.println("GPS: ON"); // debug
|
||||
}
|
||||
|
||||
void GPS_OFF() {
|
||||
|
||||
Reference in New Issue
Block a user