DEBUG mode identification changed + warning in case of debug-mode
This commit is contained in:
parent
2ffcdf2d59
commit
8efefc4843
21
bmp.py
21
bmp.py
@ -1,3 +1,5 @@
|
|||||||
|
import smbus
|
||||||
|
from . import background_task
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -8,16 +10,6 @@ except ImportError:
|
|||||||
|
|
||||||
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
||||||
|
|
||||||
from . import background_task
|
|
||||||
|
|
||||||
try:
|
|
||||||
import smbus
|
|
||||||
except ImportError:
|
|
||||||
logger.warning("Could not import smbus. DEBUG set to True.")
|
|
||||||
DEBUG = True
|
|
||||||
else:
|
|
||||||
from . import DEBUG
|
|
||||||
|
|
||||||
|
|
||||||
class bmp_180(background_task):
|
class bmp_180(background_task):
|
||||||
RUN_SLEEP_TIME = 2.0
|
RUN_SLEEP_TIME = 2.0
|
||||||
@ -29,6 +21,7 @@ class bmp_180(background_task):
|
|||||||
|
|
||||||
def __init__(self, data_callback=None):
|
def __init__(self, data_callback=None):
|
||||||
self.__data_callback__ = data_callback
|
self.__data_callback__ = data_callback
|
||||||
|
self.DEBUG = False
|
||||||
# Initialise background_task
|
# Initialise background_task
|
||||||
background_task.__init__(self)
|
background_task.__init__(self)
|
||||||
|
|
||||||
@ -42,11 +35,15 @@ class bmp_180(background_task):
|
|||||||
logger.debug('BMP-Communication failed: No data received')
|
logger.debug('BMP-Communication failed: No data received')
|
||||||
|
|
||||||
def __bmp_data_transmission__(self):
|
def __bmp_data_transmission__(self):
|
||||||
if not DEBUG:
|
if not self.DEBUG:
|
||||||
rv = {}
|
rv = {}
|
||||||
# Get I2C bus
|
# Get I2C bus
|
||||||
|
try:
|
||||||
bus = smbus.SMBus(1)
|
bus = smbus.SMBus(1)
|
||||||
|
except PermissionError:
|
||||||
|
logger.warning("Switching to DEBUG mode due to permission error...")
|
||||||
|
self.DEBUG = True
|
||||||
|
else:
|
||||||
# BMP180 address, 0x77(119)
|
# BMP180 address, 0x77(119)
|
||||||
# Read data back from 0xAA(170), 22 bytes
|
# Read data back from 0xAA(170), 22 bytes
|
||||||
data = bus.read_i2c_block_data(0x77, 0xAA, 22)
|
data = bus.read_i2c_block_data(0x77, 0xAA, 22)
|
||||||
|
20
dht.py
20
dht.py
@ -1,3 +1,5 @@
|
|||||||
|
import adafruit_dht
|
||||||
|
from . import background_task
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -8,16 +10,6 @@ except ImportError:
|
|||||||
|
|
||||||
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
||||||
|
|
||||||
from . import background_task
|
|
||||||
|
|
||||||
try:
|
|
||||||
import adafruit_dht
|
|
||||||
except ImportError:
|
|
||||||
logger.warning("Could not import adafruit_dht. DEBUG set to True")
|
|
||||||
DEBUG = True
|
|
||||||
else:
|
|
||||||
from . import DEBUG
|
|
||||||
|
|
||||||
|
|
||||||
class dht_22(background_task):
|
class dht_22(background_task):
|
||||||
RUN_SLEEP_TIME = 4.0
|
RUN_SLEEP_TIME = 4.0
|
||||||
@ -32,8 +24,12 @@ class dht_22(background_task):
|
|||||||
self.__temp_monitor__ = gradient_monitor(.5)
|
self.__temp_monitor__ = gradient_monitor(.5)
|
||||||
self.__hum_monitor__ = gradient_monitor(5)
|
self.__hum_monitor__ = gradient_monitor(5)
|
||||||
self.__monitor__ = dht_22_monitor(300)
|
self.__monitor__ = dht_22_monitor(300)
|
||||||
|
self.DEBUG = gpio is None
|
||||||
|
if self.DEBUG:
|
||||||
|
logger.warning("Switching to DEBUG mode due to gpio is None...")
|
||||||
|
|
||||||
# Initial the dht device, with data pin connected to:
|
# Initial the dht device, with data pin connected to:
|
||||||
if not DEBUG:
|
if not self.DEBUG:
|
||||||
self.__dht_device__ = adafruit_dht.DHT22(gpio, use_pulseio=False)
|
self.__dht_device__ = adafruit_dht.DHT22(gpio, use_pulseio=False)
|
||||||
# Initialise background_task
|
# Initialise background_task
|
||||||
background_task.__init__(self)
|
background_task.__init__(self)
|
||||||
@ -55,7 +51,7 @@ class dht_22(background_task):
|
|||||||
logger.debug("DHT-Communication failed: Gradient to high. Ignoring data %s!", repr(data))
|
logger.debug("DHT-Communication failed: Gradient to high. Ignoring data %s!", repr(data))
|
||||||
|
|
||||||
def __dht_data_transmission__(self):
|
def __dht_data_transmission__(self):
|
||||||
if not DEBUG:
|
if not self.DEBUG:
|
||||||
while self.__active__:
|
while self.__active__:
|
||||||
try:
|
try:
|
||||||
# Store the values
|
# Store the values
|
||||||
|
Loading…
x
Reference in New Issue
Block a user