mirror of
https://github.com/espressif/esp-rainmaker.git
synced 2026-01-14 15:35:45 +00:00
examples: Use modified app_reset APIs and upstream button component
This commit is contained in:
@@ -10,9 +10,10 @@
|
||||
#include <sdkconfig.h>
|
||||
|
||||
#include <iot_button.h>
|
||||
#include <button_gpio.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
|
||||
#include <app_reset.h>
|
||||
#include <ws2812_led.h>
|
||||
@@ -63,7 +64,7 @@ esp_err_t app_fan_init(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void push_btn_cb(void *arg)
|
||||
static void push_btn_cb(void *arg, void *data)
|
||||
{
|
||||
uint8_t old_speed = g_speed;
|
||||
g_speed++;
|
||||
@@ -90,10 +91,19 @@ static void push_btn_cb(void *arg)
|
||||
void app_driver_init()
|
||||
{
|
||||
app_fan_init();
|
||||
button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
|
||||
if (btn_handle) {
|
||||
/* Register a callback for a button tap (short press) event */
|
||||
iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
|
||||
button_config_t btn_cfg = {
|
||||
.long_press_time = 0, /* Use default */
|
||||
.short_press_time = 0, /* Use default */
|
||||
};
|
||||
button_gpio_config_t gpio_cfg = {
|
||||
.gpio_num = BUTTON_GPIO,
|
||||
.active_level = BUTTON_ACTIVE_LEVEL,
|
||||
.enable_power_save = false,
|
||||
};
|
||||
button_handle_t btn_handle = NULL;
|
||||
if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) {
|
||||
/* Register a callback for a button single click event */
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL);
|
||||
/* Register Wi-Fi reset and factory reset functionality on same button */
|
||||
app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -6,3 +6,5 @@ dependencies:
|
||||
espressif/esp_rainmaker:
|
||||
version: ">=1.0"
|
||||
override_path: '../../../components/esp_rainmaker/'
|
||||
espressif/button:
|
||||
version: "^4.1.4"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Switch demo implementation using button and RGB LED
|
||||
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
@@ -10,8 +10,9 @@
|
||||
#include <sdkconfig.h>
|
||||
|
||||
#include <iot_button.h>
|
||||
#include <button_gpio.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
|
||||
#include <app_reset.h>
|
||||
#include <ws2812_led.h>
|
||||
@@ -47,7 +48,7 @@ static void app_indicator_init(void)
|
||||
ws2812_led_init();
|
||||
app_indicator_set(g_power_state);
|
||||
}
|
||||
static void push_btn_cb(void *arg)
|
||||
static void push_btn_cb(void *arg, void *data)
|
||||
{
|
||||
bool new_state = !g_power_state;
|
||||
app_driver_set_state(new_state);
|
||||
@@ -65,10 +66,19 @@ static void set_power_state(bool target)
|
||||
|
||||
void app_driver_init()
|
||||
{
|
||||
button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
|
||||
if (btn_handle) {
|
||||
/* Register a callback for a button tap (short press) event */
|
||||
iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
|
||||
button_config_t btn_cfg = {
|
||||
.long_press_time = 0, /* Use default */
|
||||
.short_press_time = 0, /* Use default */
|
||||
};
|
||||
button_gpio_config_t gpio_cfg = {
|
||||
.gpio_num = BUTTON_GPIO,
|
||||
.active_level = BUTTON_ACTIVE_LEVEL,
|
||||
.enable_power_save = false,
|
||||
};
|
||||
button_handle_t btn_handle = NULL;
|
||||
if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) {
|
||||
/* Register a callback for a button single click event */
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL);
|
||||
/* Register Wi-Fi reset and factory reset functionality on same button */
|
||||
app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -6,3 +6,5 @@ dependencies:
|
||||
espressif/esp_rainmaker:
|
||||
version: ">=1.0"
|
||||
override_path: '../../../components/esp_rainmaker/'
|
||||
espressif/button:
|
||||
version: "^4.1.4"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <sdkconfig.h>
|
||||
#include <esp_log.h>
|
||||
#include <iot_button.h>
|
||||
#include <button_gpio.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
@@ -121,7 +122,7 @@ esp_err_t app_light_set_saturation(uint16_t saturation)
|
||||
return app_light_set_led(g_hue, g_saturation, g_value);
|
||||
}
|
||||
|
||||
static void push_btn_cb(void *arg)
|
||||
static void push_btn_cb(void *arg, void *data)
|
||||
{
|
||||
app_light_set_power(!g_power);
|
||||
esp_rmaker_param_update_and_report(
|
||||
@@ -132,10 +133,19 @@ static void push_btn_cb(void *arg)
|
||||
void app_driver_init()
|
||||
{
|
||||
app_light_init();
|
||||
button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
|
||||
if (btn_handle) {
|
||||
/* Register a callback for a button tap (short press) event */
|
||||
iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
|
||||
button_config_t btn_cfg = {
|
||||
.long_press_time = 0, /* Use default */
|
||||
.short_press_time = 0, /* Use default */
|
||||
};
|
||||
button_gpio_config_t gpio_cfg = {
|
||||
.gpio_num = BUTTON_GPIO,
|
||||
.active_level = BUTTON_ACTIVE_LEVEL,
|
||||
.enable_power_save = false,
|
||||
};
|
||||
button_handle_t btn_handle = NULL;
|
||||
if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) {
|
||||
/* Register a callback for a button single click event */
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL);
|
||||
/* Register Wi-Fi reset and factory reset functionality on same button */
|
||||
app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -6,3 +6,5 @@ dependencies:
|
||||
espressif/esp_rainmaker:
|
||||
version: ">=1.0"
|
||||
override_path: '../../../components/esp_rainmaker/'
|
||||
espressif/button:
|
||||
version: "^4.1.4"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <freertos/timers.h>
|
||||
|
||||
#include <iot_button.h>
|
||||
#include <button_gpio.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
@@ -83,7 +84,7 @@ static void app_indicator_init(void)
|
||||
app_indicator_set(g_power_state);
|
||||
}
|
||||
|
||||
static void push_btn_cb(void *arg)
|
||||
static void push_btn_cb(void *arg, void *data)
|
||||
{
|
||||
bool new_state = !g_power_state;
|
||||
app_driver_set_state(new_state);
|
||||
@@ -100,10 +101,19 @@ static void set_power_state(bool target)
|
||||
|
||||
void app_driver_init()
|
||||
{
|
||||
button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
|
||||
if (btn_handle) {
|
||||
/* Register a callback for a button tap (short press) event */
|
||||
iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
|
||||
button_config_t btn_cfg = {
|
||||
.long_press_time = 0, /* Use default */
|
||||
.short_press_time = 0, /* Use default */
|
||||
};
|
||||
button_gpio_config_t gpio_cfg = {
|
||||
.gpio_num = BUTTON_GPIO,
|
||||
.active_level = BUTTON_ACTIVE_LEVEL,
|
||||
.enable_power_save = false,
|
||||
};
|
||||
button_handle_t btn_handle = NULL;
|
||||
if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) {
|
||||
/* Register a callback for a button single click event */
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL);
|
||||
/* Register Wi-Fi reset and factory reset functionality on same button */
|
||||
app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -6,3 +6,5 @@ dependencies:
|
||||
espressif/esp_rainmaker:
|
||||
version: ">=1.0"
|
||||
override_path: '../../../components/esp_rainmaker/'
|
||||
espressif/button:
|
||||
version: "^4.1.4"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Switch demo implementation using button and RGB LED
|
||||
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
@@ -10,8 +10,9 @@
|
||||
#include <sdkconfig.h>
|
||||
|
||||
#include <iot_button.h>
|
||||
#include <button_gpio.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
|
||||
#include <app_reset.h>
|
||||
#include <ws2812_led.h>
|
||||
@@ -47,7 +48,7 @@ static void app_indicator_init(void)
|
||||
ws2812_led_init();
|
||||
app_indicator_set(g_power_state);
|
||||
}
|
||||
static void push_btn_cb(void *arg)
|
||||
static void push_btn_cb(void *arg, void *data)
|
||||
{
|
||||
bool new_state = !g_power_state;
|
||||
app_driver_set_state(new_state);
|
||||
@@ -82,10 +83,19 @@ static void set_power_state(bool target)
|
||||
|
||||
void app_driver_init()
|
||||
{
|
||||
button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
|
||||
if (btn_handle) {
|
||||
/* Register a callback for a button tap (short press) event */
|
||||
iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
|
||||
button_config_t btn_cfg = {
|
||||
.long_press_time = 0, /* Use default */
|
||||
.short_press_time = 0, /* Use default */
|
||||
};
|
||||
button_gpio_config_t gpio_cfg = {
|
||||
.gpio_num = BUTTON_GPIO,
|
||||
.active_level = BUTTON_ACTIVE_LEVEL,
|
||||
.enable_power_save = false,
|
||||
};
|
||||
button_handle_t btn_handle = NULL;
|
||||
if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) {
|
||||
/* Register a callback for a button single click event */
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL);
|
||||
/* Register Wi-Fi reset and factory reset functionality on same button */
|
||||
app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -6,3 +6,5 @@ dependencies:
|
||||
espressif/esp_rainmaker:
|
||||
version: ">=1.0"
|
||||
override_path: '../../../components/esp_rainmaker/'
|
||||
espressif/button:
|
||||
version: "^4.1.4"
|
||||
|
||||
Reference in New Issue
Block a user