First Refactoring

- Major API Changes in Core Module
- Will be changed further. Still work in progress
This commit is contained in:
Manuel83
2017-09-21 00:03:33 +02:00
parent bf3fbddbe2
commit 42ed9f02af
50 changed files with 3031 additions and 3216 deletions
Regular → Executable
+53 -50
View File
@@ -1,50 +1,53 @@
import time
from thread import start_new_thread
from modules import cbpi
try:
import RPi.GPIO as GPIO
except Exception as e:
pass
class Buzzer(object):
sound = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
def __init__(self, gpio):
try:
cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
self.gpio = int(gpio)
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.gpio, GPIO.OUT)
self.state = True
cbpi.app.logger.info("BUZZER SETUP OK")
except Exception as e:
cbpi.app.logger.info("BUZZER EXCEPTION %s" % str(e))
self.state = False
def beep(self):
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.sound,))
@cbpi.initalizer(order=1)
def init(cbpi):
gpio = cbpi.get_config_parameter("buzzer", 16)
cbpi.buzzer = Buzzer(gpio)
cbpi.beep()
cbpi.app.logger.info("INIT OK")
import time
from thread import start_new_thread
from modules.core.baseapi import Buzzer
from modules.core.core import cbpi
try:
import RPi.GPIO as GPIO
except Exception as e:
pass
class GPIOBuzzer(Buzzer):
sound = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
def __init__(self, gpio):
try:
cbpi._app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
self.gpio = int(gpio)
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.gpio, GPIO.OUT)
self.state = True
cbpi._app.logger.info("BUZZER SETUP OK")
except Exception as e:
cbpi._app.logger.info("BUZZER EXCEPTION %s" % str(e))
self.state = False
def beep(self):
if self.state is False:
cbpi._app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.sound,))
@cbpi.addon.core.initializer(order=1)
def init(cbpi):
gpio = cbpi.get_config_parameter("buzzer", 16)
cbpi.buzzer = GPIOBuzzer(gpio)