bolar_2 backup
This commit is contained in:
66
main/platform/borla_s3/button_input.h
Normal file
66
main/platform/borla_s3/button_input.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "ports/event_publisher.h"
|
||||
#include "ports/remote_behavior_config.h"
|
||||
#include "platform/borla_s3/tca9555.h"
|
||||
|
||||
#include <button_interface.h>
|
||||
#include <button_types.h>
|
||||
#include <iot_button.h>
|
||||
|
||||
namespace borla {
|
||||
|
||||
class ButtonInput final {
|
||||
public:
|
||||
ButtonInput(
|
||||
IEventPublisher& publisher,
|
||||
//const IRemoteBehaviorConfig& behavior_config);//2026-9-4 ckkj mod
|
||||
const IRemoteBehaviorConfig& behavior_config,TCA9555& tca9555);
|
||||
~ButtonInput();
|
||||
|
||||
bool Initialize();
|
||||
|
||||
private:
|
||||
struct TcaButtonCtx {
|
||||
button_driver_t base{};
|
||||
TCA9555* tca = nullptr;
|
||||
ButtonInput* owner = nullptr; // 用于在轮询回调里收尾多击分组
|
||||
// KEY(P1.0) 去抖状态:get_key_level 由 iot_button 定时器每 5ms 调一次,
|
||||
// 只有连续 kButtonDebounceSamples 次读到同一电平才认可电平变化。
|
||||
uint8_t stable_level = 0; // 去抖后的电平:1=按下,0=松开
|
||||
uint16_t same_count = 0; // 与 stable_level 不同的连续采样次数
|
||||
uint32_t read_fail_count = 0; // 连续 I2C 读失败次数
|
||||
uint32_t press_start_ms = 0; // 本次按下(去抖确认后)的时间戳
|
||||
uint32_t last_press_ms = 0; // 最近一次按下的持续时间,用于诊断
|
||||
};
|
||||
static uint8_t TcaGetKeyLevel(button_driver_t* driver);
|
||||
static esp_err_t TcaDelDriver(button_driver_t* driver);
|
||||
bool ReadTcaButtonRaw(bool* pressed);
|
||||
bool WaitTcaButtonReleased(uint32_t timeout_ms);
|
||||
|
||||
TcaButtonCtx driver_ctx_{};//2026-9-4 ckkj add
|
||||
|
||||
// 多击分组:iot_button 的内置分组会把"按下超过 short_press_time 的那一击"
|
||||
// 当成分组结束并丢弃整组点击(四击因此被拆成多次单击),所以这里只使用
|
||||
// 组件的边沿事件(按下/松开/长按),点击数由自己按"松开→按下"间隔归组。
|
||||
static void OnPressDown(void* handle, void* context);
|
||||
static void OnPressUp(void* handle, void* context);
|
||||
static void OnLongPress(void* handle, void* context);
|
||||
// 松开且超过分组窗口后,发布当前分组的点击次数(由 get_key_level 每 5ms 驱动)
|
||||
void CloseClickGroupIfIdle(uint8_t stable_level, uint32_t now_ms);
|
||||
|
||||
void PublishClick(int32_t count);
|
||||
void PublishLongPress();
|
||||
bool RegisterCallbacks();
|
||||
|
||||
IEventPublisher& publisher_;
|
||||
const IRemoteBehaviorConfig& behavior_config_;
|
||||
TCA9555& tca9555_;
|
||||
button_handle_t button_ = nullptr;
|
||||
uint32_t press_down_ms_ = 0; // 最近一次按下的时间戳
|
||||
uint32_t last_release_ms_ = 0; // 最近一次松开的时间戳(分组窗口起点)
|
||||
uint8_t click_count_ = 0; // 当前分组内累计的点击数
|
||||
bool click_group_open_ = false; // 是否还有未发布的多击分组
|
||||
};
|
||||
|
||||
} // namespace borla
|
||||
Reference in New Issue
Block a user