aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-08-03 19:50:17 +0200
committerlonkaars <loek@pipeframe.xyz>2021-08-03 19:50:17 +0200
commit773c4ef10e3b2be7376271afe30633848fb0eb94 (patch)
treed2d2a02b5596f413ad3b2f21e1aa6e83c59e59b7 /main.py
parent2876d7a9ec90cd75274b18f6383fa35bd075d6b2 (diff)
python from stdin + plugin beginnings
Diffstat (limited to 'main.py')
-rw-r--r--main.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/main.py b/main.py
index 56ec77b..5daa82a 100644
--- a/main.py
+++ b/main.py
@@ -1,23 +1,23 @@
+#!/bin/python3
from bluepy.btle import Peripheral, ADDR_TYPE_PUBLIC
import time
import colorsys
-import json
+import sys
-lampmac = "FC:58:FA:A1:CF:F1"
+lampmac = sys.argv[1]
dev = Peripheral(lampmac, ADDR_TYPE_PUBLIC)
def makemsg(r, g, b, l=0):
- return bytearray((b"\x01" if g > 0 else b"\x00") + bytes([g]) +\
- b"\x00\x00" +\
- (b"\x01" if b > 0 else b"\x00") + bytes([b]) +\
- (b"\x01" if r > 0 else b"\x00") + bytes([r]) +\
- (b"\x01" if l > 0 else b"\x00") + bytes([l]))
+ return bytes([
+ int(g > 0), g,
+ 0x00, 0x00,
+ int(b > 0), b,
+ int(r > 0), r,
+ int(l > 0), l,
+ ])
-hue = 0
-while True:
- hue = (hue + 1) % 360
- r, g, b = map(lambda x: int(x * 255), colorsys.hsv_to_rgb(hue / 360, 1, 1))
+for line in sys.stdin:
+ r, g, b, l = [ int(x, 16) for x in [ line.strip()[i:i+2] for i in range(0, 8, 2) ] ]
+ dev.writeCharacteristic(0x002A, makemsg(r, g, b, l))
- color = makemsg(r, g, b)
- dev.writeCharacteristic(0x002A, color)