Merge pull request #25 from edwardtfn/dev

Support ESPHome v2024.6.0
This commit is contained in:
Edward Firmo
2024-06-20 00:29:03 +02:00
committed by GitHub
20 changed files with 1177 additions and 663 deletions

32
.github/workflows/release_tag.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
---
name: Update Tags
# yamllint disable-line rule:truthy
on:
release:
types: [published]
jobs:
update-tags:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@main
with:
fetch-depth: '0'
- name: Set up Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Move and push stable tag
run: |
git tag -f stable ${{ github.event.release.tag_name }}
git push -f origin stable
- name: Move and push latest tag
run: |
git tag -f latest ${{ github.event.release.tag_name }}
git push -f origin latest
...

View File

@@ -0,0 +1,26 @@
---
name: Validate C++ (Clang Format)
# yamllint disable-line rule:truthy
on:
push:
paths:
- '**/*.h'
- '**/*.c'
- '**/*.cpp'
pull_request:
paths:
- '**/*.h'
- '**/*.c'
- '**/*.cpp'
workflow_dispatch:
jobs:
clang-format-checking:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: RafikFarhad/clang-format-github-action@v3
with:
sources: "components/tx_ultimate_easy/*.h,components/tx_ultimate_easy/*.cpp"
...

116
.github/workflows/validate_esphome.yml vendored Normal file
View File

@@ -0,0 +1,116 @@
---
name: Validate and Build ESPHome
# yamllint disable-line rule:truthy
on:
push:
paths:
- "*.yaml"
- "prebuilt/*.yaml"
- ".test/*.yaml"
- "*.h"
- "*.c"
- "*.cpp"
- "*.py"
pull_request:
paths:
- "*.yaml"
- "prebuilt/*.yaml"
- ".test/*.yaml"
- "*.h"
- "*.c"
- "*.cpp"
- "*.py"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
setup_dependencies:
name: Setup & Cache Dependencies
runs-on: ubuntu-latest
outputs:
cache-hit-arduino: ${{ steps.cache-arduino.outputs.cache-hit }}
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Cache Arduino Dependencies
id: cache-arduino
uses: actions/cache@main
with:
path: |
~/.esphome/cache
~/.platformio/packages
~/.platformio/platforms
key: ${{ runner.os }}-arduino-${{ hashFiles('**/esphome_ard_basic.yaml') }}
restore-keys: |
${{ runner.os }}-arduino-
code_scan:
name: Code scan (YAML)
runs-on: "ubuntu-latest"
needs: setup_dependencies
steps:
- name: Checkout Code
uses: actions/checkout@main
- name: Setup Python
uses: actions/setup-python@main
with:
python-version: '3.8'
- name: Install Yamllint
run: pip install yamllint
- name: Validate YAML files
run: find . -name "*.yaml" -exec yamllint -c ./.rules/yamllint.yml {} +
build_basic:
name: Basic
needs: [code_scan, setup_dependencies]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- id: ard
yaml_file: ".test/esphome_ard_basic.yaml"
cache-hit: ${{ needs.setup_dependencies.outputs.cache-hit-arduino }}
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Firmware
if: steps.matrix.outputs.cache-hit != 'true'
uses: esphome/build-action@v2.0.0
with:
yaml_file: ${{ matrix.yaml_file }}
build_bluetooth_proxy:
name: Bluetooth Proxy
needs: build_basic
runs-on: ubuntu-latest
strategy:
matrix:
include:
- id: idf_v4
base: idf_v4
yaml_file: ".test/esphome_idf_bluetooth_proxy.yaml"
- id: idf_v5
base: idf_v5
yaml_file: ".test/esphome_idf5_bluetooth_proxy.yaml"
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Build Bluetooth Proxy Firmware
uses: esphome/build-action@v2.0.0
with:
yaml_file: ${{ matrix.yaml_file }}
...

View File

@@ -0,0 +1,100 @@
---
name: Validate ESPHome (Beta)
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
setup_dependencies:
name: Setup & Cache Dependencies
runs-on: ubuntu-latest
outputs:
cache-hit-arduino: ${{ steps.cache-arduino.outputs.cache-hit }}
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Cache Arduino Dependencies
id: cache-arduino
uses: actions/cache@main
with:
path: |
~/.esphome/cache
~/.platformio/packages
~/.platformio/platforms
key: ${{ runner.os }}-arduino-${{ hashFiles('**/esphome_ard_basic.yaml') }}
restore-keys: |
${{ runner.os }}-arduino-
code_scan:
name: Code scan (YAML)
runs-on: "ubuntu-latest"
needs: setup_dependencies
steps:
- name: Checkout Code
uses: actions/checkout@main
- name: Setup Python
uses: actions/setup-python@main
with:
python-version: '3.8'
- name: Install Yamllint
run: pip install yamllint
- name: Validate YAML files
run: find . -name "*.yaml" -exec yamllint -c ./.rules/yamllint.yml {} +
build_basic:
name: Basic
needs: [code_scan, setup_dependencies]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- id: ard
yaml_file: ".test/esphome_ard_basic.yaml"
cache-hit: ${{ needs.setup_dependencies.outputs.cache-hit-arduino }}
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Firmware
if: steps.matrix.outputs.cache-hit != 'true'
uses: barndawgie/build-action@v1.9.0
with:
yaml_file: ${{ matrix.yaml_file }}
version: beta
build_bluetooth_proxy:
name: Bluetooth Proxy
needs: build_basic
runs-on: ubuntu-latest
strategy:
matrix:
include:
- id: idf_v4
base: idf_v4
yaml_file: ".test/esphome_idf_bluetooth_proxy.yaml"
- id: idf_v5
base: idf_v5
yaml_file: ".test/esphome_idf5_bluetooth_proxy.yaml"
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Build Bluetooth Proxy Firmware
uses: barndawgie/build-action@v1.9.0
with:
yaml_file: ${{ matrix.yaml_file }}
version: beta
...

58
.github/workflows/validate_markdown.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
---
name: Validate Markdown
# yamllint disable-line rule:truthy
on:
pull_request:
paths:
- '**/*.md'
push:
paths:
- '**/*.md'
workflow_dispatch:
jobs:
markdown-lint:
name: Markdown Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@main
with:
fetch-depth: '0'
# https://github.com/marketplace/actions/markdownlint-cli2-action
- name: Identify changed files
uses: tj-actions/changed-files@v41
id: changed-files
with:
files: '**/*.md'
separator: ","
# https://github.com/marketplace/actions/markdownlint-cli2-action
- name: Markdown Lint
uses: DavidAnson/markdownlint-cli2-action@v14
if: steps.changed-files.outputs.any_changed == 'true'
with:
globs: ${{ steps.changed-files.outputs.all_changed_files }}
separator: ","
config: '.rules/.markdownlint.jsonc'
fix: true
markdown-links:
name: Check links
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@main
with:
fetch-depth: '0'
# https://github.com/gaurav-nelson/github-action-markdown-link-check
- name: Markdown links
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
# yamllint disable-line rule:truthy
check-modified-files-only: yes
config-file: '.rules/mlc_config.json'
base-branch: 'main'
...

30
.github/workflows/validate_python.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
---
name: Validate Python (flake8)
# yamllint disable-line rule:truthy
on:
push:
paths:
- '*.py'
pull_request:
paths:
- '*.py'
workflow_dispatch:
jobs:
flake8-lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout@main
- name: Set up Python environment
uses: actions/setup-python@main
with:
python-version: "3.11"
- name: flake8 Lint
uses: py-actions/flake8@v2
with:
max-line-length: "200"
path: "components/tx_ultimate_easy"
...

47
.github/workflows/validate_yamllint.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
---
name: Validate YAML (secondary files)
# yamllint disable-line rule:truthy
on:
push:
paths:
- '**/*.yml'
- '**/*.yaml'
pull_request:
paths:
- '**/*.yml'
- '**/*.yaml'
workflow_dispatch:
jobs:
code_scan:
name: Validate YAML
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@main
with:
fetch-depth: '0'
- name: Identify changed files
uses: tj-actions/changed-files@v41
id: changed-files
with:
files: '**/*.y*ml'
separator: ","
- name: Validate YAML
if: steps.changed-files.outputs.any_changed == 'true'
run: |
IFS=',' read -ra FILES <<< "${{ steps.changed-files.outputs.all_changed_files }}"
for file in "${FILES[@]}"; do
if [[ "$file" =~ ^*\.yaml$ ]] || \
[[ "$file" =~ ^ESPHome/*\.yaml$ ]]; then
echo "Skipping $file"
continue
fi
echo "::group::Validating $file"
yamllint -c "./.rules/yamllint.yml" "$file"
echo "::endgroup::"
done
...

View File

@@ -0,0 +1,4 @@
{
"MD013": { "line_length": 200 }
}

2
.rules/markdownlint.yml Normal file
View File

@@ -0,0 +1,2 @@
MD013:
line_length: 200

13
.rules/mlc_config.json Normal file
View File

@@ -0,0 +1,13 @@
{
"ignorePatterns": [
{
"pattern": "^http://homeassistant\\.local.*$"
},
{
"pattern": "^https://sonoff.tech/product/central-control-panel/nspanel/$"
},
{
"pattern": "^https://sonoff.tech/wp-content/uploads/2021/11/%E4%BA%A7%E5%93%81%E5%8F%82%E6%95%B0%E8%A1%A8-NSPanel-20210831.pdf$"
}
]
}

42
.rules/yamllint.yml Normal file
View File

@@ -0,0 +1,42 @@
# https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration
---
yaml-files:
- '*.yaml'
- '*.yml'
- '.yamllint'
rules:
anchors:
forbid-undeclared-aliases: true
forbid-duplicated-anchors: true
braces: enable
brackets: enable
colons: enable
commas: enable
comments:
level: warning
comments-indentation:
level: warning
document-end:
level: warning
document-start:
level: warning
empty-lines: enable
empty-values: disable
float-values:
level: warning
hyphens: enable
indentation: enable
key-duplicates: enable
key-ordering: disable
line-length:
max: 200
new-line-at-end-of-file: enable
new-lines: enable
octal-values:
level: warning
quoted-strings: disable
trailing-spaces: enable
truthy:
level: warning
...

View File

@@ -0,0 +1,8 @@
---
packages:
basic_package: !include ../TX-Ultimate-Easy-ESPHome.yaml # Basic package
esp32:
framework:
type: arduino
...

View File

@@ -0,0 +1,11 @@
---
packages:
basic_package: !include ../TX-Ultimate-Easy-ESPHome.yaml # Core package
addon_bluetooth_proxy: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_addon_ble_proxy.yaml
esp32:
framework:
type: esp-idf
version: 5.0.2
platform_version: 6.3.2
...

View File

@@ -0,0 +1,5 @@
---
packages:
basic_package: !include ../TX-Ultimate-Easy-ESPHome.yaml # Core package
addon_bluetooth_proxy: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_addon_ble_proxy.yaml
...

10
.test/secrets.yaml Normal file
View File

@@ -0,0 +1,10 @@
---
api_encryption_key: MSANehPIH8kCp/vGcpPcKPSkYnv3zchyxkXCleXJinM=
mysntpserver: 192.168.0.1
web_server_password: NotASecret01
web_server_username: NotASecret01
wifi_ssid: NotASecret01
wifi_password: NotASecret01
wifi_password_backup: NotASecret02
wifi_ssid_backup: NotASecret02
...

View File

@@ -0,0 +1,37 @@
---
bluetooth_proxy:
esp32:
framework:
type: esp-idf
sdkconfig_options:
CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST: "y"
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY: "y"
CONFIG_ESP32_REV_MIN_3: "y"
CONFIG_MBEDTLS_DYNAMIC_BUFFER: "y"
CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT: "y"
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA: "y"
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC: "y"
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY: "y"
CONFIG_SPIRAM_RODATA: "y"
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP: "y"
esphome:
platformio_options:
build_flags:
- -D TX_ULTIMATE_EASY_ADDON_BLE_PROXY
i2s_audio: !remove
light:
- id: !extend light_full
platform: esp32_rmt_led_strip
rgb_order: GRB
rmt_channel: 0
chipset: ws2812
type: !remove
variant: !remove
max_refresh_rate: 33ms
media_player: !remove
...

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,4 @@
---
substitutions: substitutions:
name: tx-ultimate-easy name: tx-ultimate-easy
friendly_name: TX Ultimate Easy friendly_name: TX Ultimate Easy
@@ -10,10 +11,8 @@ packages:
remote_package: remote_package:
url: https://github.com/edwardtfn/TX-Ultimate-Easy url: https://github.com/edwardtfn/TX-Ultimate-Easy
ref: dev ref: dev
refresh: 1h refresh: 30s
files: files:
- ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml - ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml
# - ESPHome/TX-Ultimate-Easy-ESPHome_addon_ble_proxy.yaml # Adds experimental BLE proxy support (limited)
### Uncomment the lines bellow if you have issues with OTA and cannot flash via serial at this moment. ### ...
#esp32:
# flash_size: 4MB

View File

@@ -1,50 +1,61 @@
// tx_ultimate_easy.cpp
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "tx_ultimate_easy.h" #include "tx_ultimate_easy.h"
#include <string>
namespace esphome { namespace esphome {
namespace tx_ultimate_easy { namespace tx_ultimate_easy {
static const char *TAG = "tx_ultimate_easy";
void TxUltimateEasy::setup() { void TxUltimateEasy::setup() {
ESP_LOGI("log", "%s", "Tx Ultimate Easy is initialized"); ESP_LOGI(TAG, "TX Ultimate Easy is initialized");
} }
void TxUltimateEasy::loop() { void TxUltimateEasy::loop() {
bool found = false; bool found = false;
int uart_received_bytes[15] = {}; std::array<int, UART_RECEIVED_BYTES_SIZE> uart_received_bytes{};
int byte = -1; int byte = -1;
int i = 0; int i = 0;
while (this->available()) { while (this->available()) {
byte = this->read(); byte = this->read();
if (byte == 170) { if (byte == HEADER_BYTE_1) {
handle_touch(uart_received_bytes); this->handle_touch(uart_received_bytes);
i = 0; i = 0;
} }
uart_received_bytes[i] = byte; if (i < UART_RECEIVED_BYTES_SIZE) {
i++; uart_received_bytes[i] = byte;
if (byte != 0) { i++;
found = true;
} }
}; if (byte != 0x00) {
if (found) handle_touch(uart_received_bytes); found = true;
}
}
if (found) this->handle_touch(uart_received_bytes);
} }
void TxUltimateEasy::handle_touch(int uart_received_bytes[]) { void TxUltimateEasy::handle_touch(const std::array<int, UART_RECEIVED_BYTES_SIZE> &uart_received_bytes) {
ESP_LOGVV(TAG, "------------"); ESP_LOGV(TAG, "------------");
ESP_LOGVV(TAG, "- UART-Log -"); ESP_LOGV(TAG, "- UART-Log -");
ESP_LOGVV(TAG, "------------"); ESP_LOGV(TAG, "------------");
for (int i = 0; i < 15; i++) ESP_LOGVV(TAG, "UART - Log - Byte[%i]: %i", i, uart_received_bytes[i]); for (int i = 0; i < UART_RECEIVED_BYTES_SIZE; i++) {
if (is_valid_data(uart_received_bytes)) send_touch_(get_touch_point(uart_received_bytes)); ESP_LOGV(TAG, "UART - Log - Byte[%i]: %i", i, uart_received_bytes[i]);
}
if (this->is_valid_data(uart_received_bytes)) {
this->send_touch_(this->get_touch_point(uart_received_bytes));
}
} }
void TxUltimateEasy::dump_config() { ESP_LOGCONFIG(TAG, "Tx Ultimate Easy"); } void TxUltimateEasy::dump_config() {
ESP_LOGCONFIG(TAG, "TX Ultimate Easy");
}
void TxUltimateEasy::send_touch_(TouchPoint tp) { void TxUltimateEasy::send_touch_(TouchPoint tp) {
this->trigger_touch_event_.trigger(tp); this->trigger_touch_event_.trigger(tp);
switch (tp.state) { switch (tp.state) {
case TOUCH_STATE_RELEASE: case TOUCH_STATE_RELEASE:
if (tp.x >= 17) { if (tp.x >= 17) {
tp.x = tp.x - 16; tp.x -= 16;
ESP_LOGV(TAG, "Long touch - Released (x=%d)", tp.x); ESP_LOGV(TAG, "Long touch - Released (x=%d)", tp.x);
this->trigger_long_touch_release_.trigger(tp); this->trigger_long_touch_release_.trigger(tp);
} else { } else {
@@ -78,55 +89,51 @@ namespace esphome {
} }
} }
bool TxUltimateEasy::is_valid_data(int uart_received_bytes[]) { bool TxUltimateEasy::is_valid_data(const std::array<int, UART_RECEIVED_BYTES_SIZE> &uart_received_bytes) {
bool valid = true; if (uart_received_bytes[0] != HEADER_BYTE_1 ||
if (!(uart_received_bytes[0] == 170 && uart_received_bytes[1] == 85 && uart_received_bytes[2] == 1 && uart_received_bytes[3] == 2)) return false; uart_received_bytes[1] != HEADER_BYTE_2 ||
uart_received_bytes[2] != VALID_DATA_BYTE_2 ||
int state = get_touch_state(uart_received_bytes); uart_received_bytes[3] != VALID_DATA_BYTE_3) {
if (state != TOUCH_STATE_PRESS &&
state != TOUCH_STATE_RELEASE &&
state != TOUCH_STATE_SWIPE_LEFT &&
state != TOUCH_STATE_SWIPE_RIGHT &&
state != TOUCH_STATE_MULTI_TOUCH)
return false; return false;
}
if (uart_received_bytes[6] < 0 && state != TOUCH_STATE_MULTI_TOUCH) return false; int state = this->get_touch_state(uart_received_bytes);
return (state == TOUCH_STATE_PRESS ||
return true; state == TOUCH_STATE_RELEASE ||
state == TOUCH_STATE_SWIPE_LEFT ||
state == TOUCH_STATE_SWIPE_RIGHT ||
state == TOUCH_STATE_MULTI_TOUCH) &&
(uart_received_bytes[6] >= 0 || state == TOUCH_STATE_MULTI_TOUCH);
} }
int TxUltimateEasy::get_touch_position_x(int uart_received_bytes[]) { int TxUltimateEasy::get_touch_position_x(const std::array<int, UART_RECEIVED_BYTES_SIZE> &uart_received_bytes) {
int state = uart_received_bytes[4]; switch (uart_received_bytes[4]) {
switch (state) {
case TOUCH_STATE_RELEASE: case TOUCH_STATE_RELEASE:
case TOUCH_STATE_MULTI_TOUCH: case TOUCH_STATE_MULTI_TOUCH:
case TOUCH_STATE_SWIPE_LEFT: case TOUCH_STATE_SWIPE_LEFT:
case TOUCH_STATE_SWIPE_RIGHT: case TOUCH_STATE_SWIPE_RIGHT:
return uart_received_bytes[5]; return uart_received_bytes[5];
break;
default: default:
return uart_received_bytes[6]; return uart_received_bytes[6];
break;
} }
} }
int TxUltimateEasy::get_touch_state(int uart_received_bytes[]) { int TxUltimateEasy::get_touch_state(const std::array<int, UART_RECEIVED_BYTES_SIZE> &uart_received_bytes) {
int state = uart_received_bytes[4]; int state = uart_received_bytes[4];
if (state == TOUCH_STATE_PRESS && uart_received_bytes[5] != 0) state = TOUCH_STATE_RELEASE; if (state == TOUCH_STATE_PRESS && uart_received_bytes[5] != 0) state = TOUCH_STATE_RELEASE;
if (state == TOUCH_STATE_RELEASE && uart_received_bytes[5] == TOUCH_STATE_MULTI_TOUCH) state = TOUCH_STATE_MULTI_TOUCH; if (state == TOUCH_STATE_RELEASE && uart_received_bytes[5] == TOUCH_STATE_MULTI_TOUCH) state = TOUCH_STATE_MULTI_TOUCH;
if (state == TOUCH_STATE_SWIPE) { if (state == TOUCH_STATE_SWIPE) {
if (uart_received_bytes[5] == TOUCH_STATE_SWIPE_RIGHT) state = TOUCH_STATE_SWIPE_RIGHT; state = (uart_received_bytes[5] == TOUCH_STATE_SWIPE_RIGHT) ? TOUCH_STATE_SWIPE_RIGHT :
else if (uart_received_bytes[5] == TOUCH_STATE_SWIPE_LEFT) state = TOUCH_STATE_SWIPE_LEFT; (uart_received_bytes[5] == TOUCH_STATE_SWIPE_LEFT) ? TOUCH_STATE_SWIPE_LEFT : state;
} }
return state; return state;
} }
TouchPoint TxUltimateEasy::get_touch_point(int uart_received_bytes[]) { TouchPoint TxUltimateEasy::get_touch_point(const std::array<int, UART_RECEIVED_BYTES_SIZE> &uart_received_bytes) {
TouchPoint tp; TouchPoint tp;
tp.x = get_touch_position_x(uart_received_bytes); tp.x = this->get_touch_position_x(uart_received_bytes);
tp.state = get_touch_state(uart_received_bytes); tp.state = this->get_touch_state(uart_received_bytes);
tp.state_str = "Unknown";
switch (tp.state) { switch (tp.state) {
case TOUCH_STATE_RELEASE: case TOUCH_STATE_RELEASE:
tp.state_str = "RELEASE"; tp.state_str = "RELEASE";
@@ -146,6 +153,9 @@ namespace esphome {
case TOUCH_STATE_SWIPE_LEFT: case TOUCH_STATE_SWIPE_LEFT:
tp.state_str = "SWIPE_LEFT"; tp.state_str = "SWIPE_LEFT";
break; break;
default:
tp.state_str = "Unknown";
break;
} }
return tp; return tp;
} }

View File

@@ -1,3 +1,5 @@
// tx_ultimate_easy.h
#pragma once #pragma once
#include "esphome/core/automation.h" #include "esphome/core/automation.h"
@@ -7,15 +9,27 @@
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/components/switch/switch.h" #include "esphome/components/switch/switch.h"
#include "esphome/components/light/addressable_light.h" #include "esphome/components/light/addressable_light.h"
#include <array>
namespace esphome { namespace esphome {
namespace tx_ultimate_easy { namespace tx_ultimate_easy {
const static uint8_t TOUCH_STATE_RELEASE = 1; // Touch State Constants
const static uint8_t TOUCH_STATE_PRESS = 2; constexpr uint8_t TOUCH_STATE_RELEASE = 0x01;
const static uint8_t TOUCH_STATE_SWIPE = 3; constexpr uint8_t TOUCH_STATE_PRESS = 0x02;
const static uint8_t TOUCH_STATE_MULTI_TOUCH = 11; constexpr uint8_t TOUCH_STATE_SWIPE = 0x03;
const static uint8_t TOUCH_STATE_SWIPE_RIGHT = 12; constexpr uint8_t TOUCH_STATE_MULTI_TOUCH = 0x0B;
const static uint8_t TOUCH_STATE_SWIPE_LEFT = 13; constexpr uint8_t TOUCH_STATE_SWIPE_RIGHT = 0x0C;
constexpr uint8_t TOUCH_STATE_SWIPE_LEFT = 0x0D;
// UART Constants
constexpr int UART_RECEIVED_BYTES_SIZE = 15;
constexpr int HEADER_BYTE_1 = 0xAA;
constexpr int HEADER_BYTE_2 = 0x55;
constexpr int VALID_DATA_BYTE_2 = 0x01;
constexpr int VALID_DATA_BYTE_3 = 0x02;
// Log tag
static const char *TAG = "tx_ultimate_easy";
struct TouchPoint { struct TouchPoint {
int8_t x = -1; int8_t x = -1;
@@ -41,12 +55,12 @@ namespace esphome {
protected: protected:
void send_touch_(TouchPoint tp); void send_touch_(TouchPoint tp);
void handle_touch(int bytes[]); void handle_touch(const std::array<int, UART_RECEIVED_BYTES_SIZE> &bytes);
TouchPoint get_touch_point(int bytes[]); TouchPoint get_touch_point(const std::array<int, UART_RECEIVED_BYTES_SIZE> &bytes);
bool is_valid_data(int bytes[]); bool is_valid_data(const std::array<int, UART_RECEIVED_BYTES_SIZE> &bytes);
int get_touch_position_x(int bytes[]); int get_touch_position_x(const std::array<int, UART_RECEIVED_BYTES_SIZE> &bytes);
int get_touch_state(int bytes[]); int get_touch_state(const std::array<int, UART_RECEIVED_BYTES_SIZE> &bytes);
Trigger<TouchPoint> trigger_touch_event_; Trigger<TouchPoint> trigger_touch_event_;
Trigger<TouchPoint> trigger_touch_; Trigger<TouchPoint> trigger_touch_;