environment sensor library for raspberry dependencies to adafruit exist
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

__init__.py 771B

123456789101112131415161718192021222324252627282930313233
  1. import logging
  2. import threading
  3. import time
  4. DEBUG = False
  5. logger_name = 'RPI_ENVSENS'
  6. logger = logging.getLogger(logger_name)
  7. class background_task(object):
  8. RUN_SLEEP_TIME = 2.0
  9. def __init__(self):
  10. self.__active__ = True
  11. self.__thread__ = threading.Thread(target=self.run, args=())
  12. self.__thread__.daemon = True # Daemonize thread
  13. self.__thread__.start() # Start the execution
  14. def __run__(self):
  15. pass
  16. def run(self):
  17. while self.__active__:
  18. self.__run__()
  19. time.sleep(self.RUN_SLEEP_TIME)
  20. def close(self):
  21. self.__active__ = False
  22. self.__thread__.join()
  23. def __del__(self):
  24. self.close()