This commit is contained in:
135
2024-07-11 00:18:17 +03:00
parent 283233cbc3
commit b9401604ea

View File

@@ -656,7 +656,6 @@ void setRTC_Date(int yyyy, byte mo, byte dd) {
void RunStateMachine() {
byte temp_buffer;
//135Serial.println("R-SM");
switch (StateMachine) {
@@ -675,7 +674,6 @@ void RunStateMachine() {
}
break; //end DEBUG case
// ------------------------------
case BOOTUP:
@@ -701,15 +699,13 @@ void RunStateMachine() {
// ------------------------------
case REG_OPS:
//135Serial.println("REG_OPS");
displayRTC(); //keep the trains running
//if (mmRTC == 40 && ssRTC == 0) { //every hour at minute 15, do a GPS_INIT check to prep for GPS-to-RTC time update
if (mmRTC != 0 && ssRTC == 0) {
GPS_INIT_t0 = millis(); //sets our timer to allow a timeout in the next state
getRTC();
serialRTC_timeOnMax(ddRTC,moRTC,yyRTC);
serialRTC_timeOnMax(hhRTC,mmRTC,ssRTC);
Serial.println(">GPS_INIT");
StateMachine = GPS_INIT; // >>>> State Change! <<<<//
break;
@@ -768,12 +764,11 @@ void RunStateMachine() {
// ------------------------------
case GPS_INIT:
Serial.println("GPS_INIT");
displayRTC(); // keeps the trains running on the display!
if (PPS_detect()) { //means PPS is detected on the GPS unit
getRTC();
serialRTC_timeOnMax(ddRTC,moRTC,yyRTC);
getRTC();
serialRTC_timeOnMax(hhRTC,mmRTC,ssRTC);
Serial.println(">GPS_PPS_SYNC");
StateMachine = GPS_PPS_SYNC; // >>>> State Change! <<<<//
clearGPSInputBuffer(); //purges old GPS data in GPS UART buffer
@@ -782,7 +777,7 @@ void RunStateMachine() {
if (millis() - GPS_INIT_t0 > 4000) { //timeout this state after 4 secs if no PPS detected
getRTC();
serialRTC_timeOnMax(ddRTC,moRTC,yyRTC);
serialRTC_timeOnMax(hhRTC,mmRTC,ssRTC);
Serial.println(">GPS_NMEA_SYNC");
StateMachine = GPS_NMEA_SYNC; // >>>> State Change! <<<<//
clearGPSInputBuffer(); //purges old GPS data in GPS UART buffer
@@ -821,7 +816,7 @@ void RunStateMachine() {
newGPS_dateAvail = false; //this completed the date and time update.
PPS_done = false;
getRTC();
serialRTC_timeOnMax(ddRTC,moRTC,yyRTC);
serialRTC_timeOnMax(hhRTC,mmRTC,ssRTC);
Serial.println(">REG_OPS");
StateMachine = REG_OPS; // >>>> State Change! <<<<//
break;
@@ -846,7 +841,7 @@ void RunStateMachine() {
if (millis() - GPS_INIT_t0 > 14000) { //timeout this state after 10 secs if no PPS detected
getRTC();
serialRTC_timeOnMax(ddRTC,moRTC,yyRTC);
serialRTC_timeOnMax(hhRTC,mmRTC,ssRTC);
Serial.println(">REG_OPS");
StateMachine = REG_OPS; // >>>> State Change! <<<<//
}
@@ -889,7 +884,7 @@ void RunStateMachine() {
if (millis() - GPS_INIT_t0 > 14000) { //timeout this state after 10 secs if no PPS detected
getRTC();
serialRTC_timeOnMax(ddRTC,moRTC,yyRTC);
serialRTC_timeOnMax(hhRTC,mmRTC,ssRTC);
Serial.println(">REG_OPS");
StateMachine = REG_OPS; // >>>> State Change! <<<<//
}
@@ -904,7 +899,7 @@ void RunStateMachine() {
void setup() {
// put your setup code here, to run once:
// 135
lcd.init(); // Инициализация дисплея
lcd.init(); // Инициализация дисплея
lcd.clear();
lcd.backlight();
@@ -918,25 +913,24 @@ void setup() {
//initializeMax7219(); //sets all startup parameters for Max7219 chip
delay(100);
//delay(100);
pinMode(RTC_SQW_Pin, INPUT_PULLUP); // SQW is open drain on DS3231, so need internal pullup enabled.
pinMode(GPS_PPS_Pin, INPUT);
pinMode(ir_pin, INPUT_PULLUP);
//pinMode(ir_pin, INPUT_PULLUP);
Wire.setClock(400000); //i2C 100kHz typical. 400kHz fast mode. DS3231 RTC supports fast mode.
delay(100); //more stabilizing
Serial.begin(9600); // for the GPS unit. Later set to Serial when debugging done.
GPS.begin(9600);
Serial.begin(115200); // for the GPS unit. Later set to Serial when debugging done.
GPS.begin(115200);
delay(100); //more stabilizing
Serial.println("setup().");
attachInterrupt (digitalPinToInterrupt(ir_pin), ISR_pulse_detected, CHANGE);
//attachInterrupt (digitalPinToInterrupt(ir_pin), ISR_pulse_detected, CHANGE);
//clearGPSInputBuffer();
StateMachine = BOOTUP; //set the initial state
}