feat: add button repeat counter and os button

This commit is contained in:
s3lph 2023-09-13 23:44:07 +02:00
parent 597daf33f0
commit 1e3064fadf
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5
2 changed files with 39 additions and 9 deletions

View file

@ -56,15 +56,15 @@ Presses on the app button (by default the left one) are published to MQTT as wel
Example of a button event:
```json
{"mode":"Numbers","type":"button","button":"left","repeat":false}
{"mode":"Numbers","type":"button","button":"app_left","repeat":0}
```
The keys and their values are defined as follows:
| Key | Value |
|:---|:---|
| `button` | The direction in which the button was pressed. One of `left`, `right`, `down`. |
| `repeat` | If the button is held for a longer time, the button event is repeated every 500ms. This value is `false` for the inital event and `true` for repeat events. |
| `button` | The direction in which the button was pressed. One of `app_left`, `app_right`, `app_down`, `os_left`, `os_right`, `os_down`. |
| `repeat` | If the button is held for a longer time, the button event is repeated every 500ms. This value is `0` for the inital event and incremented by one for each repeat event. |
## UI Config

View file

@ -33,6 +33,9 @@ class Flow3rOpenhabMqtt(Application):
self.touch_tip = [False]*10
self.touch_log = [[]]*10
self.button_app = None
self.button_app_repeat = 0
self.button_os = None
self.button_os_repeat = 0
self.ui_config = {}
def mqtt_cb(self, topic, msg):
@ -95,27 +98,54 @@ class Flow3rOpenhabMqtt(Application):
self.state = 1
if self.state == 1:
self.mqtt.check_msg()
if ins.buttons.app != ins.buttons.NOT_PRESSED:
now = time.ticks_ms()
btn = None
if ins.buttons.app == ins.buttons.PRESSED_LEFT:
btn = 'left'
btn = 'app_left'
elif ins.buttons.app == ins.buttons.PRESSED_RIGHT:
btn = 'right'
btn = 'app_right'
elif ins.buttons.app == ins.buttons.PRESSED_DOWN:
btn = 'down'
btn = 'app_down'
if self.button_app is None:
self.button_app = now
msg = b'{{"mode":"{}","type":"button","button":"{}","repeat":false}}'\
msg = b'{{"mode":"{}","type":"button","button":"{}","repeat":0}}'\
.format(self.ui_config.get('mode'), btn)
self.mqtt.publish(self.base_topic + 'event', msg)
elif now - self.button_app > 500:
msg = b'{{"mode":"{}","type":"button","button":"{}","repeat":true}}'\
.format(self.ui_config.get('mode'), btn)
self.button_app_repeat += 1
msg = b'{{"mode":"{}","type":"button","button":"{}","repeat":{}}}'\
.format(self.ui_config.get('mode'), btn, self.button_app_repeat)
self.mqtt.publish(self.base_topic + 'event', msg)
self.button_app = now
else:
self.button_app = None
self.button_app_repeat = 0
if ins.buttons.os != ins.buttons.NOT_PRESSED:
now = time.ticks_ms()
btn = None
if ins.buttons.os == ins.buttons.PRESSED_LEFT:
btn = 'os_left'
elif ins.buttons.os == ins.buttons.PRESSED_RIGHT:
btn = 'os_right'
elif ins.buttons.os == ins.buttons.PRESSED_DOWN:
btn = 'os_down'
if self.button_os is None:
self.button_os = now
msg = b'{{"mode":"{}","type":"button","button":"{}","repeat":0}}'\
.format(self.ui_config.get('mode'), btn)
self.mqtt.publish(self.base_topic + 'event', msg)
elif now - self.button_os > 500:
self.button_os_repeat += 1
msg = b'{{"mode":"{}","type":"button","button":"{}","repeat":{}}}'\
.format(self.ui_config.get('mode'), btn, self.button_os_repeat)
self.mqtt.publish(self.base_topic + 'event', msg)
self.button_os = now
else:
self.button_os = None
self.button_os_repeat = 0
for i in range(10):
if ins.captouch.petals[i].pressed: