MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / SetSwitchPoint

Method SetSwitchPoint

cpp/src/value_classes/ValueSchedule.cpp:200–255  ·  view source on GitHub ↗

----------------------------------------------------------------------------- A value in a device has changed -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

198// A value in a device has changed
199//-----------------------------------------------------------------------------
200bool ValueSchedule::SetSwitchPoint
201(
202 uint8 const _hours, uint8 const _minutes, int8 const _setback
203)
204{
205 // Find where to insert this switch point. They must be sorted by ascending time value.
206 uint8 i;
207 uint8 insertAt = 0;
208
209 for( i=0; i<m_numSwitchPoints; ++i )
210 {
211 if( m_switchPoints[i].m_hours == _hours )
212 {
213 if( m_switchPoints[i].m_minutes == _minutes )
214 {
215 // There is already a switch point with this time, so we
216 // just update its setback value
217 m_switchPoints[i].m_setback = _setback;
218 return true;
219 }
220
221 if( m_switchPoints[i].m_minutes > _minutes )
222 {
223 break;
224 }
225 }
226 else if( m_switchPoints[i].m_hours > _hours )
227 {
228 break;
229 }
230
231 ++insertAt;
232 }
233
234 if( m_numSwitchPoints >= 9 )
235 {
236 // The schedule is full
237 return false;
238 }
239
240 // Shuffle any later switch points out of the way
241 for( i=m_numSwitchPoints; i>insertAt; --i )
242 {
243 m_switchPoints[i].m_hours = m_switchPoints[i-1].m_hours;
244 m_switchPoints[i].m_minutes = m_switchPoints[i-1].m_minutes;
245 m_switchPoints[i].m_setback = m_switchPoints[i-1].m_setback;
246 }
247
248 // Insert the new switch point
249 m_switchPoints[insertAt].m_hours = _hours;
250 m_switchPoints[insertAt].m_minutes = _minutes;
251 m_switchPoints[insertAt].m_setback = _setback;
252
253 ++m_numSwitchPoints;
254 return true;
255}
256
257//-----------------------------------------------------------------------------

Callers 1

HandleMsgMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected