void S_TimedRelay::beSmart(const String &str) { String s = str.substring(str.indexOf(' ') + 1); if (st::Device::debug) { Serial.print(F("S_TimedRelay::beSmart s = ")); Serial.println(s); } if ((s == F("on")) && (m_bCurrentState == LOW)) { m_bCurrentState = HIGH; //Save time turned on m_lTimeChanged = millis(); //Increment number of active timers if (!m_bTimerPending) { st::Everything::bTimersPending++; m_bTimerPending = true; } //Queue the relay status update the ST Cloud Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off"))); //Set the initial count to zero m_iCurrentCount = 0; //update the digital output writeStateToPin(); } else if ((s == F("off")) && (m_bCurrentState == HIGH)) { m_bCurrentState = LOW; //Decrement number of active timers if (st::Everything::bTimersPending > 0) st::Everything::bTimersPending--; m_bTimerPending = false; //Queue the relay status update the ST Cloud Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off"))); //Reset the count to the number of required cycles to prevent Update() routine from running if someone sends an OFF command m_iCurrentCount = m_iNumCycles; //update the digital output writeStateToPin(); } }
void EX_Alarm::setPin(byte pin) { //m_nPin = pin; digitalWrite(pin, m_bInvertLogic ? HIGH : LOW); pinMode(pin, OUTPUT); writeStateToPin(); }
//SmartThings Shield data handler (receives command to turn "both" or "off" the Alarm (digital output) void EX_Alarm::beSmart(const String &str) { String s = str.substring(str.indexOf(' ') + 1); if (debug) { Serial.print(F("EX_Alarm::beSmart s = ")); Serial.println(s); } //if (m_bUseStrobe) { if (s == F("both")) { if (m_bUseStrobe) { m_nCurrentAlarmState = both; } else { m_nCurrentAlarmState = siren; if (debug) { Serial.println(F("EX_Alarm::beSmart - Strobe Pin not defined. Defaulting to Siren!")); } } } else if(s == F("siren")) { m_nCurrentAlarmState = siren; } else if(s == F("strobe")) { if (m_bUseStrobe) { m_nCurrentAlarmState = strobe; } else { m_nCurrentAlarmState = siren; if (debug) { Serial.println(F("EX_Alarm::beSmart - Strobe Pin not defined. Defaulting to Siren!")); } } } else if(s == F("off")) { m_nCurrentAlarmState = off; } //} //else { // if (s == F("both") { // m_nCurrentAlarmState = both; // } // else if(s == F("siren")) { // m_nCurrentAlarmState = siren; // } // else if(s == F("strobe")) { // m_nCurrentAlarmState = siren; // } // else if(s == F("off")) { // m_nCurrentAlarmState = off; // } //} writeStateToPin(); refresh(); }
//update function void S_TimedRelay::update() { if (m_iCurrentCount < m_iNumCycles) { //Turn off digital output if timer has expired if ((m_bCurrentState == HIGH) && (millis() - m_lTimeChanged >= m_lOnTime)) { m_bCurrentState = LOW; writeStateToPin(); m_lTimeChanged = millis(); } else if ((m_bCurrentState == LOW) && (millis() - m_lTimeChanged >= m_lOffTime)) { //add one to the current count since we finished an on/off cycle, and turn on output if needed m_iCurrentCount++; if (m_iCurrentCount < m_iNumCycles) { m_bCurrentState = HIGH; writeStateToPin(); m_lTimeChanged = millis(); } } //Check to see if we just finished the requested number of cycles if (m_iCurrentCount == m_iNumCycles) { //Decrement number of active timers if (st::Everything::bTimersPending > 0) st::Everything::bTimersPending--; m_bTimerPending = false; //Queue the relay status update the ST Cloud Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off"))); } } }
//SmartThings Shield data handler (receives command to turn "both" or "off" the Alarm (digital output) void EX_Alarm::beSmart(const String &str) { String s = str.substring(str.indexOf(' ') + 1); if (debug) { Serial.print(F("EX_Alarm::beSmart s = ")); Serial.println(s); } if ((s == F("both")) || (s == F("siren"))) { m_bCurrentState = HIGH; } else if (s == F("off")) { m_bCurrentState = LOW; } writeStateToPin(); refresh(); }
void EX_RCSwitch::beSmart(const String &str) { String s=str.substring(str.indexOf(' ')+1); if (st::Executor::debug) { Serial.print(F("EX_RCSwitch::beSmart s = ")); Serial.println(s); } if(s==F("on")) { m_bCurrentState=HIGH; } else if(s==F("off")) { m_bCurrentState=LOW; } writeStateToPin(); Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH?F("on"):F("off"))); }
void EX_Alarm::setPin(byte pin) { m_nPin = pin; pinMode(m_nPin, OUTPUT); writeStateToPin(); }
void S_TimedRelay::setOutputPin(byte pin) { m_nOutputPin = pin; pinMode(m_nOutputPin, OUTPUT); writeStateToPin(); }
void EX_RCSwitch::init() { writeStateToPin(); Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off"))); }