update function
| 77 | |
| 78 | //update function |
| 79 | void S_TimedRelay::update() |
| 80 | { |
| 81 | if (m_iCurrentCount < m_iNumCycles) |
| 82 | { |
| 83 | //Turn off digital output if timer has expired |
| 84 | if ((m_bCurrentState == HIGH) && (millis() - m_lTimeChanged >= m_lOnTime)) |
| 85 | { |
| 86 | m_bCurrentState = LOW; |
| 87 | writeStateToPin(); |
| 88 | m_lTimeChanged = millis(); |
| 89 | } |
| 90 | else if ((m_bCurrentState == LOW) && (millis() - m_lTimeChanged >= m_lOffTime)) |
| 91 | { |
| 92 | //add one to the current count since we finished an on/off cycle, and turn on output if needed |
| 93 | m_iCurrentCount++; |
| 94 | if (m_iCurrentCount < m_iNumCycles) |
| 95 | { |
| 96 | m_bCurrentState = HIGH; |
| 97 | writeStateToPin(); |
| 98 | m_lTimeChanged = millis(); |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | //Check to see if we just finished the requested number of cycles |
| 104 | if (m_iCurrentCount == m_iNumCycles) |
| 105 | { |
| 106 | //Decrement number of active timers |
| 107 | if (st::Everything::bTimersPending > 0) st::Everything::bTimersPending--; |
| 108 | m_bTimerPending = false; |
| 109 | |
| 110 | //Queue the relay status update the ST Cloud |
| 111 | Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off"))); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | void S_TimedRelay::beSmart(const String &str) |
| 117 | { |
nothing calls this directly
no outgoing calls
no test coverage detected