Skip to content

Commit f6692e5

Browse files
committed
Fix switch state detection for 1Wire devices
1 parent 6850074 commit f6692e5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

hardware/1Wire.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ void C1Wire::SensorThread()
135135
int pollPeriod = 300 * 1000;
136136
m_sql.GetPreferencesVar("1WireSensorPollPeriod", pollPeriod);
137137

138+
int pollIterations = 1;
139+
140+
if (pollPeriod > 1000)
141+
{
142+
pollIterations = pollPeriod / 1000;
143+
pollPeriod = 1000;
144+
}
145+
146+
int iteration = 0;
138147

139148
while (!m_stoprequested)
140149
{
@@ -148,13 +157,13 @@ void C1Wire::SensorThread()
148157
PollSensors();
149158
}
150159
}
151-
}
152160

153161
_log.Log(LOG_STATUS, "1-Wire: Sensor thread terminating");
162+
}
154163

155164
void C1Wire::SwitchThread()
156165
{
157-
int pollPeriod = 300 * 1000;
166+
int pollPeriod = 100;
158167
m_sql.GetPreferencesVar("1WireSwitchPollPeriod", pollPeriod);
159168

160169
// Rescan the bus once every 10 seconds if requested
@@ -535,6 +544,10 @@ void C1Wire::ReportTemperatureHumidity(const std::string& deviceId, const float
535544

536545
void C1Wire::ReportLightState(const std::string& deviceId, const int unit, const bool state)
537546
{
547+
#if defined(_DEBUG)
548+
_log.Log(LOG_STATUS, "device '%s' unit %d state is %s", deviceId.c_str(), unit, (state) ? "on" : "off");
549+
#endif
550+
538551
// check - is state changed ?
539552
char num[16];
540553
sprintf(num, "%s/%d", deviceId.c_str(), unit);
@@ -544,11 +557,16 @@ void C1Wire::ReportLightState(const std::string& deviceId, const int unit, const
544557
it = m_LastSwitchState.find(id);
545558
if (it != m_LastSwitchState.end())
546559
{
547-
if (it->second == state)
560+
if (m_LastSwitchState[id] == state)
548561
{
549562
return;
550563
}
551564
}
565+
566+
#if defined(_DEBUG)
567+
_log.Log(LOG_STATUS, "device '%s' unit %d changed state to %s", deviceId.c_str(), unit, (state) ? "on" : "off");
568+
#endif
569+
552570
m_LastSwitchState[id] = state;
553571

554572
unsigned char deviceIdByteArray[DEVICE_ID_SIZE]={0};

0 commit comments

Comments
 (0)