void disconnectedUpdate() { if(Particle.connected()) { connectionFsm.transitionTo(Online); } else if(connectionFsm.timeInCurrentState() > DISCONNECTED_TIMEOUT) { connectionFsm.transitionTo(Offline); } }
void updateSnuze() { if(-1 == clicks) { self.transitionTo(Clock); return; } if(snuzeRuntime.check()) { self.transitionTo(Alarm); return; } }
void updateAlarm() { RGB.brightness(map(abs((millis() % 2000) - 1000), 0, 1000, 0, 255)); switch(clicks) { case -1: self.transitionTo(Clock); return; case 1: self.transitionTo(Snuze); return; } }
void offlineUpdate() { digitalWrite(LIGHT_PIN, LIGHT_ON); if(Particle.connected()) { connectionFsm.transitionTo(Online); } }
void updateStart() { if(Time.now() > 10000 && millis() > 5000) { self.transitionTo(Clock); return; } }
void error(String message) { if(self.isInState(Start)) { sd.initErrorPrint(&terminal); } else { sd.errorPrint(&terminal); } terminal.flush(); errorMessage = message; self.transitionTo(Error); }
void updateClock() { uint8_t currentMinute = Time.minute(); if(currentMinute != previousMinute) { previousMinute = currentMinute; if(alarms.check()) { self.transitionTo(Alarm); return; } } }
void onlineUpdate() { digitalWrite(LIGHT_PIN, LIGHT_OFF); if(!Particle.connected()) { connectionFsm.transitionTo(Disconnected); } }
void computeKeypadInput(char key) { static uint8_t index = 0; static time_t modifiedTime; if (fsm.isInState(_waitState)) { switch (key) { case '#': lcd.clear(); fsm.transitionTo(_menuState); break; } } if (fsm.isInState(_menuState)) { switch (key) { case '#': lcd.clear(); fsm.transitionTo(_waitState); break; case '*': lcd.clear(); // We have to call an empty state or the menuState function // will not be called fsm.immediateTransitionTo(_emptyState); fsm.transitionTo(_menuState); break; case '1': lcd.clear(); fsm.transitionTo(_changeHourState); break; case '2': lcd.clear(); fsm.transitionTo(_changeStartLedState); break; case '3': lcd.clear(); fsm.transitionTo(_changeStopLedState); break; } } if (fsm.isInState(_changeHourState) or fsm.isInState(_changeStartLedState) or fsm.isInState(_changeStopLedState) or fsm.isInState(_changeFadeInState) or fsm.isInState(_changeFadeOutState)) { switch (key) { case '*': if (index != 6) { break; } index = 0; lcd.clear(); if (fsm.isInState(_changeHourState)) { RTC.set(modifiedTime); setSyncProvider(RTC.get); fsm.transitionTo(_waitState); } else if (fsm.isInState(_changeStartLedState)) { led.setStartTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_changeFadeInState); } else if (fsm.isInState(_changeStopLedState)) { led.setStopTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_changeFadeOutState); } else if (fsm.isInState(_changeFadeInState)) { led.setFadeInTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_waitState); } else if (fsm.isInState(_changeFadeOutState)) { led.setFadeOutTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_waitState); } break; case '#': index = 0; lcd.clear(); fsm.transitionTo(_waitState); break; default: modifiedTime = computeUserInput(index, atoi(&key)); index++; break; } } }
void updateError() { if(-1 == clicks) { self.transitionTo(Clock); } }