From b794830f6ec7df1c1680a39e4b8ae48a3a21dd79 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Tue, 20 Apr 2021 01:13:47 +0200 Subject: [PATCH] Added multitouch to binary_sensor. --- doc/configuration.md | 31 +++++++++++++++++++++---------- front_panel_hal.h | 44 ++++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/doc/configuration.md b/doc/configuration.md index 40115c3..f37303b 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -243,22 +243,32 @@ for the front panel. On touch, a binary_sensor will publish `True`, on release i will publish `False`. The configuration of a binary_sensor determines what part or parts of the front panel are involved in the touch events. +For referencing the parts of the front panel, the following identifiers are available: + +* POWER_BUTTON (or its alias: POWER) +* COLOR_BUTTON (or its alias: COLOR) +* SLIDER + ```yaml binary_sensor: - platform: xiaomi_bslamp2 id: my_bedside_lamp_power_button - part: POWER_BUTTON + for: POWER_BUTTON on_press: then: - light.toggle: my_bedside_lamp -``` -For specifying specific parts of the front panel in the upcoming configuration variables, -the following identifiers are available: - -* POWER_BUTTON (or its alias: POWER) -* COLOR_BUTTON (or its alias: COLOR) -* SLIDER + - platform: xiaomi_bslamp2 + id: my_bedside_lamp_power_plus_color_button + for: + - POWER_BUTTON + - COLOR_BUTTON + on_press: + then: + - light.turn_on: + id: my_bedside_lamp + effect: BlinkyBlink +``` ### Configuration variables: @@ -267,8 +277,9 @@ the following identifiers are available: * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id, you can reference the binary_sensor from automation rules (to retrieve the current state of the binary_sensor). -* **part** (*Optional*, part identifier): This specifies what part of the front panel the binary sensor must - look at. Valid options are: "any" (the default) or one of the abovementioned part identifiers. +* **for** (*Mandatory*, part identifier or list): This specifies what part or parts of the + front panel the binary sensor must look at. When multiple parts are specified here, the + binary_sensor will handle multi-touch events using those parts. * All other options from [Binary Sensor](https://esphome.io/components/binary_sensor/index.html#config-binary-sensor). ## Component: sensor diff --git a/front_panel_hal.h b/front_panel_hal.h index d435928..2235298 100644 --- a/front_panel_hal.h +++ b/front_panel_hal.h @@ -37,39 +37,39 @@ using EVENT = uint16_t; // BITS INDICATE PATTERN RESULT // 1 status 0 parsing event failed // 1 parsing event successful -// 2-3 part 00 part unknown -// 01 power button -// 10 color button -// 11 slider -// 4-5 type 00 type unknown +// 2-4 part 000 part unknown +// 001 power button +// 010 color button +// 100 slider +// 5-6 type 00 type unknown // 01 touch // 10 release -// 6-10 slider 00000 level known (or part is not "slider") +// 7-11 slider 00000 level known (or part is not "slider") // level 00001 level 1 // ... up to // 10101 level 21 // -static const EVENT FLAG_INIT = 0b0000000000; +static const EVENT FLAG_INIT = 0b00000000000; -static const EVENT FLAG_ERR = 0b0000000000; -static const EVENT FLAG_OK = 0b0000000001; +static const EVENT FLAG_ERR = 0b00000000000; +static const EVENT FLAG_OK = 0b00000000001; static const EVENT FLAG_PART_SHIFT = 1; -static const EVENT FLAG_PART_MASK = 0b0000000110; -static const EVENT FLAG_PART_UNKNOWN = 0b0000000000; -static const EVENT FLAG_PART_POWER = 0b0000000010; -static const EVENT FLAG_PART_COLOR = 0b0000000100; -static const EVENT FLAG_PART_SLIDER = 0b0000000110; +static const EVENT FLAG_PART_MASK = 0b00000001110; +static const EVENT FLAG_PART_UNKNOWN = 0b00000000000; +static const EVENT FLAG_PART_POWER = 0b00000000010; +static const EVENT FLAG_PART_COLOR = 0b00000000100; +static const EVENT FLAG_PART_SLIDER = 0b00000001000; -static const EVENT FLAG_TYPE_SHIFT = 3; -static const EVENT FLAG_TYPE_MASK = 0b0000011000; -static const EVENT FLAG_TYPE_UNKNOWN = 0b0000000000; -static const EVENT FLAG_TYPE_TOUCH = 0b0000001000; -static const EVENT FLAG_TYPE_RELEASE = 0b0000010000; +static const EVENT FLAG_TYPE_SHIFT = 4; +static const EVENT FLAG_TYPE_MASK = 0b00000110000; +static const EVENT FLAG_TYPE_UNKNOWN = 0b00000000000; +static const EVENT FLAG_TYPE_TOUCH = 0b00000010000; +static const EVENT FLAG_TYPE_RELEASE = 0b00000100000; -static const EVENT FLAG_LEVEL_SHIFT = 5; -static const EVENT FLAG_LEVEL_MASK = 0b1111100000; -static const EVENT FLAG_LEVEL_UNKNOWN = 0b0000000000; +static const EVENT FLAG_LEVEL_SHIFT = 6; +static const EVENT FLAG_LEVEL_MASK = 0b11111000000; +static const EVENT FLAG_LEVEL_UNKNOWN = 0b00000000000; /** * This class implements a parser that translates event byte codes from the