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