瀏覽代碼

Merge ebfc1e2d2d into 5b47b94833

pull/219/merge
Alexander Solncev GitHub 7 年之前
父節點
當前提交
029f330f7a
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 4 個檔案被更改,包括 27 行新增11 行删除
  1. +1
    -0
      config/schema.sql
  2. +5
    -5
      modules/base_plugins/gpio_actor/__init__.py
  3. +20
    -6
      modules/buzzer/__init__.py
  4. +1
    -0
      update/4_passive_buzzer.sql

+ 1
- 0
config/schema.sql 查看文件

@@ -86,6 +86,7 @@ INSERT OR IGNORE INTO config VALUES ('unit', 'C', 'select', 'Temperature Unit',
INSERT OR IGNORE INTO config VALUES ('brewery_name', 'My Home Brewery', 'text', 'Your brewery name', NULL ); 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', 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 ('buzzer_beep_level', 'HIGH', 'select', 'Buzzer Logic Beep Level', '["HIGH", "LOW"]');
INSERT OR IGNORE INTO config VALUES ('buzzer_type', 'ACTIVE', 'select', 'Buzzer type', '["ACTIVE", "PASSIVE"]');
INSERT OR IGNORE INTO config VALUES ('setup', 'YES', 'select', 'Show the Setup dialog', '["YES","NO"]'); 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 ('brew_name', '', 'text', 'Brew Name', NULL);
INSERT OR IGNORE INTO config VALUES ('donation_notification', 'YES', 'select', 'Disable Donation Notification', '["YES","NO"]'); INSERT OR IGNORE INTO config VALUES ('donation_notification', 'YES', 'select', 'Disable Donation Notification', '["YES","NO"]');


+ 5
- 5
modules/base_plugins/gpio_actor/__init__.py 查看文件

@@ -44,16 +44,16 @@ class GPIOPWM(ActorBase):
def init(self): def init(self):
GPIO.setup(int(self.gpio), GPIO.OUT) GPIO.setup(int(self.gpio), GPIO.OUT)
GPIO.output(int(self.gpio), 0) GPIO.output(int(self.gpio), 0)
if self.frequency is None:
self.frequency = 0.5 # 2 sec

self.p = GPIO.PWM(int(self.gpio), float(self.frequency))




def on(self, power=None): def on(self, power=None):
if power is not None: if power is not None:
self.power = int(power) self.power = int(power)

if self.frequency is None:
self.frequency = 0.5 # 2 sec

self.p = GPIO.PWM(int(self.gpio), float(self.frequency))
print "GPIO ON"
self.p.start(int(self.power)) self.p.start(int(self.power))


def set_power(self, power): def set_power(self, power):


+ 20
- 6
modules/buzzer/__init__.py 查看文件

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


sound = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"] sound = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
def __init__(self, gpio, beep_level):
def __init__(self, gpio, buzzer_type, beep_level):
try: try:
cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio) cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
self.gpio = int(gpio) self.gpio = int(gpio)
self.beep_level = beep_level self.beep_level = beep_level
self.buzzer_type = buzzer_type
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
GPIO.setup(self.gpio, GPIO.OUT) GPIO.setup(self.gpio, GPIO.OUT)
if buzzer_type == "PASSIVE":
self.p = GPIO.PWM(int(gpio), 5000)
self.state = True self.state = True
cbpi.app.logger.info("BUZZER SETUP OK") cbpi.app.logger.info("BUZZER SETUP OK")
except Exception as e: except Exception as e:
@@ -29,19 +32,29 @@ class Buzzer(object):
return return


def play(sound): def play(sound):
def output(level):
if self.buzzer_type == "PASSIVE" and level == GPIO.LOW:
self.p.stop()
elif self.buzzer_type == "PASSIVE":
self.p.start(50)
else:
GPIO.output(int(self.gpio), level)

try: try:
for i in sound: for i in sound:
if (isinstance(i, str)): if (isinstance(i, str)):
if i == "H" and self.beep_level == "HIGH": if i == "H" and self.beep_level == "HIGH":
GPIO.output(int(self.gpio), GPIO.HIGH)
output(GPIO.HIGH)
elif i == "H" and self.beep_level != "HIGH": elif i == "H" and self.beep_level != "HIGH":
GPIO.output(int(self.gpio), GPIO.LOW)
output(GPIO.LOW)
elif i == "L" and self.beep_level == "HIGH": elif i == "L" and self.beep_level == "HIGH":
GPIO.output(int(self.gpio), GPIO.LOW)
output(GPIO.LOW)
else: else:
GPIO.output(int(self.gpio), GPIO.HIGH)
output(GPIO.HIGH)
else: else:
time.sleep(i) time.sleep(i)
if self.buzzer_type == "PASSIVE":
self.p.stop()
except Exception as e: except Exception as e:
pass pass


@@ -51,7 +64,8 @@ class Buzzer(object):
def init(cbpi): def init(cbpi):
gpio = cbpi.get_config_parameter("buzzer", 16) gpio = cbpi.get_config_parameter("buzzer", 16)
beep_level = cbpi.get_config_parameter("buzzer_beep_level", "HIGH") beep_level = cbpi.get_config_parameter("buzzer_beep_level", "HIGH")
buzzer_type = cbpi.get_config_parameter("buzzer_type", "ACTIVE")


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

+ 1
- 0
update/4_passive_buzzer.sql 查看文件

@@ -0,0 +1 @@
INSERT OR IGNORE INTO config VALUES ('buzzer_type', 'ACTIVE', 'select', 'Buzzer type', '["ACTIVE", "PASSIVE"]');

Loading…
取消
儲存