Ver código fonte

Merge pull request #151 from mb-tec/master

Buzzer Beep Level
pull/157/merge
Manuel83 GitHub 8 anos atrás
pai
commit
dd5b5f456a
Nenhuma chave conhecida encontrada para esta assinatura no banco de dados ID da chave GPG: 4AEE18F83AFDEB23
2 arquivos alterados com 12 adições e 4 exclusões
  1. +1
    -0
      config/schema.sql
  2. +11
    -4
      modules/buzzer/__init__.py

+ 1
- 0
config/schema.sql Ver arquivo

@@ -85,6 +85,7 @@ INSERT OR IGNORE INTO config VALUES ('sensor_cols', 4, 'select', 'Adjust the wid
INSERT OR IGNORE INTO config VALUES ('unit', 'C', 'select', 'Temperature Unit', '["C","F"]');
INSERT OR IGNORE INTO config VALUES ('brewery_name', 'My Home Brewery', 'text', 'Your brewery name', NULL );
INSERT OR IGNORE INTO config VALUES ('buzzer', 16, 'select', 'Buzzer GPIO', '[16,17,18,19,20]');
INSERT OR IGNORE INTO config VALUES ('buzzer_beep_level', 'HIGH', 'select', 'Buzzer Logic Beep Level', '["HIGH", "LOW"]');
INSERT OR IGNORE INTO config VALUES ('setup', 'YES', 'select', 'Show the Setup dialog', '["YES","NO"]');
INSERT OR IGNORE INTO config VALUES ('brew_name', '', 'text', 'Brew Name', NULL);
INSERT OR IGNORE INTO config VALUES ('donation_notification', 'YES', 'select', 'Disable Donation Notification', '["YES","NO"]');


+ 11
- 4
modules/buzzer/__init__.py Ver arquivo

@@ -10,10 +10,11 @@ except Exception as e:
class Buzzer(object):

sound = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
def __init__(self, gpio):
def __init__(self, gpio, beep_level):
try:
cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
self.gpio = int(gpio)
self.beep_level = beep_level
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.gpio, GPIO.OUT)
self.state = True
@@ -31,10 +32,14 @@ class Buzzer(object):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
if i == "H" and self.beep_level == "HIGH":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
elif i == "H" and self.beep_level != "HIGH":
GPIO.output(int(self.gpio), GPIO.LOW)
elif i == "L" and self.beep_level == "HIGH":
GPIO.output(int(self.gpio), GPIO.LOW)
else:
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
time.sleep(i)
except Exception as e:
@@ -45,6 +50,8 @@ class Buzzer(object):
@cbpi.initalizer(order=1)
def init(cbpi):
gpio = cbpi.get_config_parameter("buzzer", 16)
cbpi.buzzer = Buzzer(gpio)
beep_level = cbpi.get_config_parameter("buzzer_beep_level", "HIGH")

cbpi.buzzer = Buzzer(gpio, beep_level)
cbpi.beep()
cbpi.app.logger.info("INIT OK")

Carregando…
Cancelar
Salvar