- improved tempsensor exception
This commit is contained in:
@@ -2,6 +2,11 @@ import abc
|
|||||||
from utils.value import AttributeChange
|
from utils.value import AttributeChange
|
||||||
|
|
||||||
|
|
||||||
|
class TemperatureSensorException(Exception):
|
||||||
|
def __init__(self, error_txt):
|
||||||
|
Exception.__init__(self, error_txt)
|
||||||
|
|
||||||
|
|
||||||
class ATemperatureSensor(AttributeChange):
|
class ATemperatureSensor(AttributeChange):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
AttributeChange.__init__(self)
|
AttributeChange.__init__(self)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import time
|
import time
|
||||||
from components import ATemperatureSensor
|
from components import ATemperatureSensor, TemperatureSensorException
|
||||||
import spidev
|
import spidev
|
||||||
|
|
||||||
|
|
||||||
@@ -38,6 +38,8 @@ class TempSensor_max31865(ATemperatureSensor):
|
|||||||
lsb = self.read_reg(0x02)
|
lsb = self.read_reg(0x02)
|
||||||
if lsb & 0x01 == 0x00:
|
if lsb & 0x01 == 0x00:
|
||||||
digits = (256*msb + lsb) >> 1
|
digits = (256*msb + lsb) >> 1
|
||||||
|
else
|
||||||
|
raise TemperatureSensorException("Could not read sensor!")
|
||||||
|
|
||||||
self.write_reg(0x00, 0xA3)
|
self.write_reg(0x00, 0xA3)
|
||||||
return digits
|
return digits
|
||||||
|
|||||||
+3
-3
@@ -2,7 +2,7 @@ import asyncio
|
|||||||
from tasks import ATask
|
from tasks import ATask
|
||||||
from ws.message import MsgIo
|
from ws.message import MsgIo
|
||||||
from utils.value import ChangedFloat
|
from utils.value import ChangedFloat
|
||||||
from components import ATemperatureSensor
|
from components import ATemperatureSensor, TemperatureSensorException
|
||||||
|
|
||||||
|
|
||||||
class TempSensorTask(ATask):
|
class TempSensorTask(ATask):
|
||||||
@@ -30,6 +30,6 @@ class TempSensorTask(ATask):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.temp = self.sensor.temperature()
|
self.temp = self.sensor.temperature()
|
||||||
except Exception:
|
except TemperatureSensorException as e:
|
||||||
pass
|
print(e)
|
||||||
await asyncio.sleep(self.interval)
|
await asyncio.sleep(self.interval)
|
||||||
|
|||||||
Reference in New Issue
Block a user