forked from xiaozhi/xiaozhi-esp32
fixbug: button driver cannot be in stack memory
This commit is contained in:
@@ -30,17 +30,11 @@ private:
|
|||||||
LcdDisplay *display_;
|
LcdDisplay *display_;
|
||||||
button_handle_t btn_a;
|
button_handle_t btn_a;
|
||||||
button_handle_t btn_b;
|
button_handle_t btn_b;
|
||||||
|
button_driver_t* btn_a_driver_ = nullptr;
|
||||||
|
button_driver_t* btn_b_driver_ = nullptr;
|
||||||
|
|
||||||
static Df_K10Board* instance_;
|
static Df_K10Board* instance_;
|
||||||
|
|
||||||
static uint8_t GetButtonALevel(button_driver_t *button_driver) {
|
|
||||||
return instance_->IoExpanderGetLevel(IO_EXPANDER_PIN_NUM_2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t GetButtonBLevel(button_driver_t *button_driver) {
|
|
||||||
return instance_->IoExpanderGetLevel(IO_EXPANDER_PIN_NUM_12);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeI2c() {
|
void InitializeI2c() {
|
||||||
// Initialize I2C peripheral
|
// Initialize I2C peripheral
|
||||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
i2c_master_bus_config_t i2c_bus_cfg = {
|
||||||
@@ -113,11 +107,12 @@ private:
|
|||||||
.long_press_time = 1000,
|
.long_press_time = 1000,
|
||||||
.short_press_time = 0
|
.short_press_time = 0
|
||||||
};
|
};
|
||||||
button_driver_t btn_a_driver = {
|
btn_a_driver_ = (button_driver_t*)calloc(1, sizeof(button_driver_t));
|
||||||
.enable_power_save = false,
|
btn_a_driver_->enable_power_save = false;
|
||||||
.get_key_level = GetButtonALevel
|
btn_a_driver_->get_key_level = [](button_driver_t *button_driver) -> uint8_t {
|
||||||
|
return instance_->IoExpanderGetLevel(IO_EXPANDER_PIN_NUM_2);
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(iot_button_create(&btn_a_config, &btn_a_driver, &btn_a));
|
ESP_ERROR_CHECK(iot_button_create(&btn_a_config, btn_a_driver_, &btn_a));
|
||||||
iot_button_register_cb(btn_a, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
iot_button_register_cb(btn_a, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
||||||
auto self = static_cast<Df_K10Board*>(usr_data);
|
auto self = static_cast<Df_K10Board*>(usr_data);
|
||||||
auto& app = Application::GetInstance();
|
auto& app = Application::GetInstance();
|
||||||
@@ -142,11 +137,12 @@ private:
|
|||||||
.long_press_time = 1000,
|
.long_press_time = 1000,
|
||||||
.short_press_time = 0
|
.short_press_time = 0
|
||||||
};
|
};
|
||||||
button_driver_t btn_b_driver = {
|
btn_b_driver_ = (button_driver_t*)calloc(1, sizeof(button_driver_t));
|
||||||
.enable_power_save = false,
|
btn_b_driver_->enable_power_save = false;
|
||||||
.get_key_level = GetButtonBLevel
|
btn_b_driver_->get_key_level = [](button_driver_t *button_driver) -> uint8_t {
|
||||||
|
return instance_->IoExpanderGetLevel(IO_EXPANDER_PIN_NUM_12);
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(iot_button_create(&btn_b_config, &btn_b_driver, &btn_b));
|
ESP_ERROR_CHECK(iot_button_create(&btn_b_config, btn_b_driver_, &btn_b));
|
||||||
iot_button_register_cb(btn_b, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
iot_button_register_cb(btn_b, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
||||||
auto self = static_cast<Df_K10Board*>(usr_data);
|
auto self = static_cast<Df_K10Board*>(usr_data);
|
||||||
auto& app = Application::GetInstance();
|
auto& app = Application::GetInstance();
|
||||||
|
|||||||
@@ -65,15 +65,10 @@ private:
|
|||||||
esp_io_expander_handle_t io_expander = NULL;
|
esp_io_expander_handle_t io_expander = NULL;
|
||||||
LcdDisplay* display_;
|
LcdDisplay* display_;
|
||||||
button_handle_t boot_btn, pwr_btn;
|
button_handle_t boot_btn, pwr_btn;
|
||||||
|
button_driver_t* boot_btn_driver_ = nullptr;
|
||||||
|
button_driver_t* pwr_btn_driver_ = nullptr;
|
||||||
static CustomBoard* instance_;
|
static CustomBoard* instance_;
|
||||||
|
|
||||||
static uint8_t GetBootButtonLevel(button_driver_t *button_driver) {
|
|
||||||
return gpio_get_level(BOOT_BUTTON_GPIO);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t GetPwrButtonLevel(button_driver_t *button_driver) {
|
|
||||||
return gpio_get_level(PWR_BUTTON_GPIO);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeI2c() {
|
void InitializeI2c() {
|
||||||
// Initialize I2C peripheral
|
// Initialize I2C peripheral
|
||||||
@@ -175,11 +170,12 @@ private:
|
|||||||
.long_press_time = 2000,
|
.long_press_time = 2000,
|
||||||
.short_press_time = 0
|
.short_press_time = 0
|
||||||
};
|
};
|
||||||
button_driver_t boot_btn_driver = {
|
boot_btn_driver_ = (button_driver_t*)calloc(1, sizeof(button_driver_t));
|
||||||
.enable_power_save = false,
|
boot_btn_driver_->enable_power_save = false;
|
||||||
.get_key_level = GetBootButtonLevel
|
boot_btn_driver_->get_key_level = [](button_driver_t *button_driver) -> uint8_t {
|
||||||
|
return gpio_get_level(BOOT_BUTTON_GPIO);
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(iot_button_create(&boot_btn_config, &boot_btn_driver, &boot_btn));
|
ESP_ERROR_CHECK(iot_button_create(&boot_btn_config, boot_btn_driver_, &boot_btn));
|
||||||
iot_button_register_cb(boot_btn, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
iot_button_register_cb(boot_btn, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
||||||
auto self = static_cast<CustomBoard*>(usr_data);
|
auto self = static_cast<CustomBoard*>(usr_data);
|
||||||
auto& app = Application::GetInstance();
|
auto& app = Application::GetInstance();
|
||||||
@@ -197,11 +193,12 @@ private:
|
|||||||
.long_press_time = 5000,
|
.long_press_time = 5000,
|
||||||
.short_press_time = 0
|
.short_press_time = 0
|
||||||
};
|
};
|
||||||
button_driver_t pwr_btn_driver = {
|
pwr_btn_driver_ = (button_driver_t*)calloc(1, sizeof(button_driver_t));
|
||||||
.enable_power_save = false,
|
pwr_btn_driver_->enable_power_save = false;
|
||||||
.get_key_level = GetPwrButtonLevel
|
pwr_btn_driver_->get_key_level = [](button_driver_t *button_driver) -> uint8_t {
|
||||||
|
return gpio_get_level(PWR_BUTTON_GPIO);
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(iot_button_create(&pwr_btn_config, &pwr_btn_driver, &pwr_btn));
|
ESP_ERROR_CHECK(iot_button_create(&pwr_btn_config, pwr_btn_driver_, &pwr_btn));
|
||||||
iot_button_register_cb(pwr_btn, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
iot_button_register_cb(pwr_btn, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
||||||
// 短按无处理
|
// 短按无处理
|
||||||
}, this);
|
}, this);
|
||||||
|
|||||||
@@ -220,15 +220,10 @@ private:
|
|||||||
esp_io_expander_handle_t io_expander = NULL;
|
esp_io_expander_handle_t io_expander = NULL;
|
||||||
LcdDisplay* display_;
|
LcdDisplay* display_;
|
||||||
button_handle_t boot_btn, pwr_btn;
|
button_handle_t boot_btn, pwr_btn;
|
||||||
|
button_driver_t* boot_btn_driver_ = nullptr;
|
||||||
|
button_driver_t* pwr_btn_driver_ = nullptr;
|
||||||
static CustomBoard* instance_;
|
static CustomBoard* instance_;
|
||||||
|
|
||||||
static uint8_t GetBootButtonLevel(button_driver_t *button_driver) {
|
|
||||||
return gpio_get_level(BOOT_BUTTON_GPIO);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t GetPwrButtonLevel(button_driver_t *button_driver) {
|
|
||||||
return gpio_get_level(PWR_BUTTON_GPIO);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeI2c() {
|
void InitializeI2c() {
|
||||||
// Initialize I2C peripheral
|
// Initialize I2C peripheral
|
||||||
@@ -391,11 +386,12 @@ private:
|
|||||||
.long_press_time = 2000,
|
.long_press_time = 2000,
|
||||||
.short_press_time = 0
|
.short_press_time = 0
|
||||||
};
|
};
|
||||||
button_driver_t boot_btn_driver = {
|
boot_btn_driver_ = (button_driver_t*)calloc(1, sizeof(button_driver_t));
|
||||||
.enable_power_save = false,
|
boot_btn_driver_->enable_power_save = false;
|
||||||
.get_key_level = GetBootButtonLevel
|
boot_btn_driver_->get_key_level = [](button_driver_t *button_driver) -> uint8_t {
|
||||||
|
return gpio_get_level(BOOT_BUTTON_GPIO);
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(iot_button_create(&boot_btn_config, &boot_btn_driver, &boot_btn));
|
ESP_ERROR_CHECK(iot_button_create(&boot_btn_config, boot_btn_driver_, &boot_btn));
|
||||||
iot_button_register_cb(boot_btn, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
iot_button_register_cb(boot_btn, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
||||||
auto self = static_cast<CustomBoard*>(usr_data);
|
auto self = static_cast<CustomBoard*>(usr_data);
|
||||||
auto& app = Application::GetInstance();
|
auto& app = Application::GetInstance();
|
||||||
@@ -410,11 +406,12 @@ private:
|
|||||||
.long_press_time = 5000,
|
.long_press_time = 5000,
|
||||||
.short_press_time = 0
|
.short_press_time = 0
|
||||||
};
|
};
|
||||||
button_driver_t pwr_btn_driver = {
|
pwr_btn_driver_ = (button_driver_t*)calloc(1, sizeof(button_driver_t));
|
||||||
.enable_power_save = false,
|
pwr_btn_driver_->enable_power_save = false;
|
||||||
.get_key_level = GetPwrButtonLevel
|
pwr_btn_driver_->get_key_level = [](button_driver_t *button_driver) -> uint8_t {
|
||||||
|
return gpio_get_level(PWR_BUTTON_GPIO);
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(iot_button_create(&pwr_btn_config, &pwr_btn_driver, &pwr_btn));
|
ESP_ERROR_CHECK(iot_button_create(&pwr_btn_config, pwr_btn_driver_, &pwr_btn));
|
||||||
iot_button_register_cb(pwr_btn, BUTTON_LONG_PRESS_START, nullptr, [](void* button_handle, void* usr_data) {
|
iot_button_register_cb(pwr_btn, BUTTON_LONG_PRESS_START, nullptr, [](void* button_handle, void* usr_data) {
|
||||||
auto self = static_cast<CustomBoard*>(usr_data);
|
auto self = static_cast<CustomBoard*>(usr_data);
|
||||||
if(self->GetBacklight()->brightness() > 0) {
|
if(self->GetBacklight()->brightness() > 0) {
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ private:
|
|||||||
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
||||||
esp_lcd_panel_handle_t panel_ = nullptr;
|
esp_lcd_panel_handle_t panel_ = nullptr;
|
||||||
uint32_t long_press_cnt_;
|
uint32_t long_press_cnt_;
|
||||||
|
button_driver_t* btn_driver_ = nullptr;
|
||||||
static SensecapWatcher* instance_;
|
static SensecapWatcher* instance_;
|
||||||
|
|
||||||
void InitializePowerSaveTimer() {
|
void InitializePowerSaveTimer() {
|
||||||
@@ -230,11 +231,6 @@ private:
|
|||||||
ESP_LOGI(TAG, "Knob initialized with pins A:%d B:%d", BSP_KNOB_A_PIN, BSP_KNOB_B_PIN);
|
ESP_LOGI(TAG, "Knob initialized with pins A:%d B:%d", BSP_KNOB_A_PIN, BSP_KNOB_B_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加一个静态成员实例指针,用于按钮回调
|
|
||||||
static uint8_t GetKnobButtonLevel(button_driver_t *button_driver) {
|
|
||||||
return instance_->IoExpanderGetLevel(BSP_KNOB_BTN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeButton() {
|
void InitializeButton() {
|
||||||
// 设置静态实例指针
|
// 设置静态实例指针
|
||||||
instance_ = this;
|
instance_ = this;
|
||||||
@@ -249,12 +245,13 @@ private:
|
|||||||
.long_press_time = 2000,
|
.long_press_time = 2000,
|
||||||
.short_press_time = 0
|
.short_press_time = 0
|
||||||
};
|
};
|
||||||
button_driver_t btn_driver = {
|
btn_driver_ = (button_driver_t*)calloc(1, sizeof(button_driver_t));
|
||||||
.enable_power_save = false,
|
btn_driver_->enable_power_save = false;
|
||||||
.get_key_level = GetKnobButtonLevel
|
btn_driver_->get_key_level = [](button_driver_t *button_driver) -> uint8_t {
|
||||||
|
return !instance_->IoExpanderGetLevel(BSP_KNOB_BTN);
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_ERROR_CHECK(iot_button_create(&btn_config, &btn_driver, &btns));
|
ESP_ERROR_CHECK(iot_button_create(&btn_config, btn_driver_, &btns));
|
||||||
|
|
||||||
iot_button_register_cb(btns, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
iot_button_register_cb(btns, BUTTON_SINGLE_CLICK, nullptr, [](void* button_handle, void* usr_data) {
|
||||||
auto self = static_cast<SensecapWatcher*>(usr_data);
|
auto self = static_cast<SensecapWatcher*>(usr_data);
|
||||||
|
|||||||
Reference in New Issue
Block a user