Skip to content

Commit 3593b3d

Browse files
committed
Move mutex to prevent delays processing device commands.
1 parent 1c58246 commit 3593b3d

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

myDevices/sensors/sensors.py

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -232,67 +232,67 @@ def BusInfo(self):
232232
self.currentBusInfo = json
233233
return self.currentBusInfo
234234
def SensorsInfo(self):
235-
with self.sensorMutex:
236-
devices = self.GetDevices()
237-
debug(str(time()) + ' Got devices info ' + str(self.sensorsRefreshCount))
238-
if devices is None:
239-
return {}
240-
for value in devices:
241-
sensor = instance.deviceInstance(value['name'])
242-
if 'enabled' not in value or value['enabled'] == 1:
243-
sleep(SENSOR_INFO_SLEEP)
244-
try:
245-
if value['type'] == 'Temperature':
246-
value['Celsius'] = self.CallDeviceFunction(sensor.getCelsius)
247-
value['Fahrenheit'] = self.CallDeviceFunction(sensor.getFahrenheit)
248-
value['Kelvin'] =self.CallDeviceFunction(sensor.getKelvin)
249-
if value['type'] == 'Pressure':
250-
value['Pascal'] = self.CallDeviceFunction(sensor.getPascal)
251-
if value['type'] == 'Luminosity':
252-
value['Lux'] = self.CallDeviceFunction(sensor.getLux)
253-
if value['type'] == 'Distance':
254-
value['Centimeter'] = self.CallDeviceFunction(sensor.getCentimeter)
255-
value['Inch'] = self.CallDeviceFunction(sensor.getInch)
256-
if value['type'] in ('ADC', 'DAC'):
257-
value['channelCount'] = self.CallDeviceFunction(sensor.analogCount)
258-
value['maxInteger'] = self.CallDeviceFunction(sensor.analogMaximum)
259-
value['resolution'] = self.CallDeviceFunction(sensor.analogResolution)
260-
value['allInteger'] = self.CallDeviceFunction(sensor.analogReadAll)
261-
value['allVolt'] = self.CallDeviceFunction(sensor.analogReadAllVolt)
262-
value['allFloat'] = self.CallDeviceFunction(sensor.analogReadAllFloat)
263-
if value['type'] == 'DAC':
264-
value['vref'] = self.CallDeviceFunction(sensor.analogReference)
265-
if value['type'] == 'PWM':
266-
value['channelCount'] = self.CallDeviceFunction(sensor.pwmCount)
267-
value['maxInteger'] = self.CallDeviceFunction(sensor.pwmMaximum)
268-
value['resolution'] = self.CallDeviceFunction(sensor.pwmResolution)
269-
value['all'] = self.CallDeviceFunction(sensor.pwmWildcard)
270-
if value['type'] == 'Humidity':
271-
value['float']=self.CallDeviceFunction(sensor.getHumidity)
272-
value['percent']=self.CallDeviceFunction(sensor.getHumidityPercent)
273-
if value['type'] == 'PiFaceDigital':
274-
value['all'] = self.CallDeviceFunction(sensor.readAll)
275-
if value['type'] in ('DigitalSensor', 'DigitalActuator'):
276-
value['value'] = self.CallDeviceFunction(sensor.read)
277-
if value['type'] == 'GPIOPort':
278-
value['channelCount'] = self.CallDeviceFunction(sensor.digitalCount)
279-
value['all'] = self.CallDeviceFunction(sensor.wildcard)
280-
if value['type'] == 'AnalogSensor':
281-
value['integer'] = self.CallDeviceFunction(sensor.read)
282-
value['float'] = self.CallDeviceFunction(sensor.readFloat)
283-
value['volt'] = self.CallDeviceFunction(sensor.readVolt)
284-
if value['type'] == 'ServoMotor':
285-
value['angle'] = self.CallDeviceFunction(sensor.readAngle)
286-
if value['type'] == 'AnalogActuator':
287-
value['float'] = self.CallDeviceFunction(sensor.readFloat)
288-
except:
289-
exception ("Sensor values failed: "+ value['type'] + " " + value['name'])
235+
devices = self.GetDevices()
236+
debug(str(time()) + ' Got devices info ' + str(self.sensorsRefreshCount))
237+
if devices is None:
238+
return {}
239+
for value in devices:
240+
sensor = instance.deviceInstance(value['name'])
241+
if 'enabled' not in value or value['enabled'] == 1:
242+
sleep(SENSOR_INFO_SLEEP)
290243
try:
291-
if 'hash' in value:
292-
value['sensor'] = value['hash']
293-
del value['hash']
294-
except KeyError:
295-
pass
244+
if value['type'] == 'Temperature':
245+
value['Celsius'] = self.CallDeviceFunction(sensor.getCelsius)
246+
value['Fahrenheit'] = self.CallDeviceFunction(sensor.getFahrenheit)
247+
value['Kelvin'] =self.CallDeviceFunction(sensor.getKelvin)
248+
if value['type'] == 'Pressure':
249+
value['Pascal'] = self.CallDeviceFunction(sensor.getPascal)
250+
if value['type'] == 'Luminosity':
251+
value['Lux'] = self.CallDeviceFunction(sensor.getLux)
252+
if value['type'] == 'Distance':
253+
value['Centimeter'] = self.CallDeviceFunction(sensor.getCentimeter)
254+
value['Inch'] = self.CallDeviceFunction(sensor.getInch)
255+
if value['type'] in ('ADC', 'DAC'):
256+
value['channelCount'] = self.CallDeviceFunction(sensor.analogCount)
257+
value['maxInteger'] = self.CallDeviceFunction(sensor.analogMaximum)
258+
value['resolution'] = self.CallDeviceFunction(sensor.analogResolution)
259+
value['allInteger'] = self.CallDeviceFunction(sensor.analogReadAll)
260+
value['allVolt'] = self.CallDeviceFunction(sensor.analogReadAllVolt)
261+
value['allFloat'] = self.CallDeviceFunction(sensor.analogReadAllFloat)
262+
if value['type'] == 'DAC':
263+
value['vref'] = self.CallDeviceFunction(sensor.analogReference)
264+
if value['type'] == 'PWM':
265+
value['channelCount'] = self.CallDeviceFunction(sensor.pwmCount)
266+
value['maxInteger'] = self.CallDeviceFunction(sensor.pwmMaximum)
267+
value['resolution'] = self.CallDeviceFunction(sensor.pwmResolution)
268+
value['all'] = self.CallDeviceFunction(sensor.pwmWildcard)
269+
if value['type'] == 'Humidity':
270+
value['float']=self.CallDeviceFunction(sensor.getHumidity)
271+
value['percent']=self.CallDeviceFunction(sensor.getHumidityPercent)
272+
if value['type'] == 'PiFaceDigital':
273+
value['all'] = self.CallDeviceFunction(sensor.readAll)
274+
if value['type'] in ('DigitalSensor', 'DigitalActuator'):
275+
value['value'] = self.CallDeviceFunction(sensor.read)
276+
if value['type'] == 'GPIOPort':
277+
value['channelCount'] = self.CallDeviceFunction(sensor.digitalCount)
278+
value['all'] = self.CallDeviceFunction(sensor.wildcard)
279+
if value['type'] == 'AnalogSensor':
280+
value['integer'] = self.CallDeviceFunction(sensor.read)
281+
value['float'] = self.CallDeviceFunction(sensor.readFloat)
282+
value['volt'] = self.CallDeviceFunction(sensor.readVolt)
283+
if value['type'] == 'ServoMotor':
284+
value['angle'] = self.CallDeviceFunction(sensor.readAngle)
285+
if value['type'] == 'AnalogActuator':
286+
value['float'] = self.CallDeviceFunction(sensor.readFloat)
287+
except:
288+
exception ("Sensor values failed: "+ value['type'] + " " + value['name'])
289+
try:
290+
if 'hash' in value:
291+
value['sensor'] = value['hash']
292+
del value['hash']
293+
except KeyError:
294+
pass
295+
with self.sensorMutex:
296296
if self.currentSensorsInfo:
297297
del self.currentSensorsInfo
298298
self.currentSensorsInfo = None

0 commit comments

Comments
 (0)