diff --git a/config/schema.sql b/config/schema.sql index ce62c26..f10ed2b 100644 --- a/config/schema.sql +++ b/config/schema.sql @@ -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"]'); diff --git a/modules/buzzer/__init__.py b/modules/buzzer/__init__.py index 5120587..d0140a6 100644 --- a/modules/buzzer/__init__.py +++ b/modules/buzzer/__init__.py @@ -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")