lincomatic/open_evse — pull request #6 by scanchain (2014-03-17 02:54:51+00:00)
Title: Fix DelayTimer

Fix DelayTimer's failure to stop charging if start and end times straddle across midnight.

a). Condition changed from
if ( ( (m_CurrTimeMinutes >= m_StartTimerMinutes) && (m_CurrTimeMinutes >= m_StopTimerMinutes) ) || ( (m_CurrTimeMinutes <= m_StartTimerMinutes) && (m_CurrTimeMinutes <= m_StopTimerMinutes) ) )

to

if ( ( (m_CurrTimeMinutes >= m_StartTimerMinutes) && (m_CurrTimeMinutes > m_StopTimerMinutes) ) || ( (m_CurrTimeMinutes <= m_StartTimerMinutes) && (m_CurrTimeMinutes < m_StopTimerMinutes) ) )

b) Added second attempt to stop changing in case interrupt is late (rare)
if ((m_CurrTimeMinutes >= m_StopTimerMinutes)&&(m_CurrTimeMinutes <= m_StopTimerMinutes+1)) {
// Not in time interval
if (g_EvseController.GetState() != EVSE_STATE_DISABLED)
g_EvseController.Disable();

c) Reduce code size by changing to variables to minutes since original code considers minutes only anyway
uint16_t m_StartTimerMinutes = m_StartTimerHour * 60 + m_StartTimerMin;
uint16_t m_StopTimerMinutes = m_StopTimerHour * 60 + m_StopTimerMin;
uint16_t m_CurrTimeMinutes = m_CurrHour * 60 + m_CurrMin;