Blinking works now freely
This commit is contained in:
parent
92c1b6b005
commit
b903f636d2
@ -415,25 +415,40 @@ def set_pixel(r, g, b):
|
|||||||
_write_byte(0)
|
_write_byte(0)
|
||||||
_enqueue()
|
_enqueue()
|
||||||
|
|
||||||
def blink(r, g, b, t, repeats):
|
def blink(r, g, b, ontime, offtime, blinktimes):
|
||||||
for i in range(0, repeats + 1):
|
logging.info("[buttonshim] Blink")
|
||||||
|
for i in range(0, blinktimes):
|
||||||
set_pixel(r, g, b)
|
set_pixel(r, g, b)
|
||||||
time.sleep(t)
|
time.sleep(ontime)
|
||||||
set_pixel(0, 0, 0)
|
set_pixel(0, 0, 0)
|
||||||
time.sleep(t)
|
time.sleep(offtime)
|
||||||
|
|
||||||
def runCommand(button, pressed, plugin):
|
def runCommand(button, pressed, plugin):
|
||||||
logging.debug(f"[buttonshim] Button Pressed! Loading command from slot '{button}' for button '{NAMES[button]}'")
|
logging.info(f"[buttonshim] Button Pressed! Loading command from slot '{button}' for button '{NAMES[button]}'")
|
||||||
command = plugin.commands[button]
|
bCfg = plugin.options['buttons'][NAMES[button]]
|
||||||
logging.debug(f"[buttonshim] Running command: {command}")
|
blinkCfg = bCfg['blink']
|
||||||
process = subprocess.Popen(command, shell=True, stdin=None, stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash")
|
logging.debug(blink)
|
||||||
r = plugin.colors[button][0]
|
if blinkCfg['enabled'] == True:
|
||||||
g = plugin.colors[button][1]
|
logging.debug(f"[buttonshim] Blinking led")
|
||||||
b = plugin.colors[button][2]
|
red = int(blinkCfg['red'])
|
||||||
thread = Thread(target=blink,args=(r, g, b, 0.3, 3))
|
green = int(blinkCfg['green'])
|
||||||
thread.start()
|
blue = int(blinkCfg['blue'])
|
||||||
process.wait()
|
on_time = float(blinkCfg['on_time'])
|
||||||
thread.stop()
|
off_time = float(blinkCfg['off_time'])
|
||||||
|
blink_times = int(blinkCfg['blink_times'])
|
||||||
|
logging.debug(f"red {red} green {green} blue {blue} on_time {on_time} off_time {off_time} blink_times {blink_times}")
|
||||||
|
thread = Thread(target=blink, args=(red, green, blue, on_time, off_time, blink_times))
|
||||||
|
thread.start()
|
||||||
|
logging.debug(f"[buttonshim] Blink thread started")
|
||||||
|
command = bCfg['command']
|
||||||
|
if command == '':
|
||||||
|
logging.debug(f"[buttonshim] Command empty")
|
||||||
|
else:
|
||||||
|
logging.debug(f"[buttonshim] Process create: {command}")
|
||||||
|
process = subprocess.Popen(command, shell=True, stdin=None, stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash")
|
||||||
|
process.wait()
|
||||||
|
process = None
|
||||||
|
logging.debug(f"[buttonshim] Process end")
|
||||||
|
|
||||||
class Buttonshim(plugins.Plugin):
|
class Buttonshim(plugins.Plugin):
|
||||||
__author__ = 'gon@o2online.de'
|
__author__ = 'gon@o2online.de'
|
||||||
@ -444,18 +459,10 @@ class Buttonshim(plugins.Plugin):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
self.options = dict()
|
self.options = dict()
|
||||||
self.commands = ['', '', '', '', '']
|
|
||||||
self.colors = [[0xFF,0x00,0x00],[0x00,0xFF,0x00],[0x00,0x00,0xFF],[0xFF,0xFF,0x00],[0x00,0xFF,0xFF]]
|
|
||||||
global _handlers
|
global _handlers
|
||||||
_handlers = [Handler(self) for x in range(NUM_BUTTONS)]
|
_handlers = [Handler(self) for x in range(NUM_BUTTONS)]
|
||||||
on_press([BUTTON_A, BUTTON_B, BUTTON_C, BUTTON_D, BUTTON_E], runCommand)
|
on_press([BUTTON_A, BUTTON_B, BUTTON_C, BUTTON_D, BUTTON_E], runCommand)
|
||||||
|
|
||||||
def on_loaded(self):
|
def on_loaded(self):
|
||||||
i = 0
|
|
||||||
for b in self.options['buttons']:
|
|
||||||
self.commands[i] = b
|
|
||||||
#self.colors = self.options['colors']
|
|
||||||
logging.debug(f"[buttonshim] Loaded command '{b}' into slot '{i}' for button '{NAMES[i]}'.")
|
|
||||||
i=i+1
|
|
||||||
logging.info("[buttonshim] GPIO Button plugin loaded.")
|
logging.info("[buttonshim] GPIO Button plugin loaded.")
|
||||||
self.running = True
|
self.running = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user