diff --git a/README.md b/README.md index 00d95ac..a00a4f3 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,14 @@ The touch events detected by the flow3r are published to the topic `flow3r-/ui_config`, at which it listens for JSON arrays such as below: ```json -["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"] +{ + "mode": "Numbers", + "labels": ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"] +} ``` -Each position in the array corrensponds to one of the petals, and the text for each petal is shown on the display close to the corresponding petal. +* `labels`: Each position in the array corrensponds to one of the petals, and the text for each petal is shown on the display close to the corresponding petal. +* `mode`: The text is shown in big in the center of the display. It is also sent with each event, so that subscribers can perform differnt actions depending on the active mode. ## Integration into OpenHAB @@ -92,7 +97,7 @@ actions: id: "2" configuration: itemName: flow3r_ui_config # item needs to be created and linked to the ui_config topic beforehand - command: '["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"]' + command: '{"labels":["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"]}' type: core.ItemCommandAction ``` @@ -115,7 +120,7 @@ actions: type: application/javascript script: >- var payload = JSON.parse(this.event.event); - if (payload.petal == "10" and payload.duration > 1000) { + if (payload.petal == "10" && payload.duration > 1000) { console.log("longpress!"); } ``` diff --git a/flow3r_openhab/__init__.py b/flow3r_openhab/__init__.py index 9211fa9..e3e772f 100644 --- a/flow3r_openhab/__init__.py +++ b/flow3r_openhab/__init__.py @@ -32,7 +32,7 @@ class Flow3rOpenhabMqtt(Application): self.touch_base = [False]*10 self.touch_tip = [False]*10 self.touch_log = [[]]*10 - self.ui_config = [""]*10 + self.ui_config = {} def mqtt_cb(self, topic, msg): print(topic, msg) @@ -54,12 +54,16 @@ class Flow3rOpenhabMqtt(Application): ctx.text_align = ctx.CENTER ctx.text_baseline = ctx.MIDDLE ctx.font_size = 20 - for i, text in enumerate(self.ui_config): + for i, text in enumerate(self.ui_config.get('labels', [])): phi = (2*math.pi/10)*(i+1)-(math.pi/2) radius = 50 if i%2 else 80 x = radius*math.cos(phi) y = radius*math.sin(phi) ctx.rgb(1, 1, 1).move_to(x, y).text(text) + mode = self.ui_config.get('mode') + if mode: + ctx.font_size = 50 + ctx.rgb(1, 1, 1).move_to(0, 0).text(mode) if CONFIG.get('debug_touch', False): ctx.line_width =1 for i in range(10): @@ -129,8 +133,8 @@ class Flow3rOpenhabMqtt(Application): event = 'swipe_left' if event is not None: human_petal = 10-(-i%10) - msg = b'{{"petal":"{}","event":"{}","dx":{},"dy":{},"duration":{}}}'\ - .format(human_petal, event, d_x, d_y, duration) + msg = b'{{"mode":"{}","petal":"{}","event":"{}","dx":{},"dy":{},"duration":{}}}'\ + .format(self.ui_config.get('mode'), human_petal, event, d_x, d_y, duration) self.mqtt.publish(self.base_topic + 'event', msg) self.touch_time[i] = None self.touch_begin[i] = None