Initial commit.
Some checks failed
Sync remain PRs to Jira / Sync PRs to Jira (push) Has been cancelled
Some checks failed
Sync remain PRs to Jira / Sync PRs to Jira (push) Has been cancelled
This commit is contained in:
3
examples/common/app_reset/CMakeLists.txt
Normal file
3
examples/common/app_reset/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "app_reset.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES gpio_button rmaker_common)
|
||||
66
examples/common/app_reset/app_reset.c
Normal file
66
examples/common/app_reset/app_reset.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
/* It is recommended to copy this code in your example so that you can modify as
|
||||
* per your application's needs, especially for the indicator calbacks,
|
||||
* wifi_reset_indicate() and factory_reset_indicate().
|
||||
*/
|
||||
#include <esp_log.h>
|
||||
#include <esp_err.h>
|
||||
#include <iot_button.h>
|
||||
#include <esp_rmaker_utils.h>
|
||||
|
||||
static const char *TAG = "app_reset";
|
||||
|
||||
#define REBOOT_DELAY 2
|
||||
#define RESET_DELAY 2
|
||||
|
||||
static void wifi_reset_trigger(void *arg)
|
||||
{
|
||||
esp_rmaker_wifi_reset(RESET_DELAY, REBOOT_DELAY);
|
||||
}
|
||||
|
||||
static void wifi_reset_indicate(void *arg)
|
||||
{
|
||||
ESP_LOGI(TAG, "Release button now for Wi-Fi reset. Keep pressed for factory reset.");
|
||||
}
|
||||
|
||||
static void factory_reset_trigger(void *arg)
|
||||
{
|
||||
esp_rmaker_factory_reset(RESET_DELAY, REBOOT_DELAY);
|
||||
}
|
||||
|
||||
static void factory_reset_indicate(void *arg)
|
||||
{
|
||||
ESP_LOGI(TAG, "Release button to trigger factory reset.");
|
||||
}
|
||||
|
||||
esp_err_t app_reset_button_register(button_handle_t btn_handle, uint8_t wifi_reset_timeout,
|
||||
uint8_t factory_reset_timeout)
|
||||
{
|
||||
if (!btn_handle) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (wifi_reset_timeout) {
|
||||
iot_button_add_on_release_cb(btn_handle, wifi_reset_timeout, wifi_reset_trigger, NULL);
|
||||
iot_button_add_on_press_cb(btn_handle, wifi_reset_timeout, wifi_reset_indicate, NULL);
|
||||
}
|
||||
if (factory_reset_timeout) {
|
||||
if (factory_reset_timeout <= wifi_reset_timeout) {
|
||||
ESP_LOGW(TAG, "It is recommended to have factory_reset_timeout > wifi_reset_timeout");
|
||||
}
|
||||
iot_button_add_on_release_cb(btn_handle, factory_reset_timeout, factory_reset_trigger, NULL);
|
||||
iot_button_add_on_press_cb(btn_handle, factory_reset_timeout, factory_reset_indicate, NULL);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
button_handle_t app_reset_button_create(gpio_num_t gpio_num, button_active_t active_level)
|
||||
{
|
||||
return iot_button_create(gpio_num, active_level);
|
||||
}
|
||||
50
examples/common/app_reset/app_reset.h
Normal file
50
examples/common/app_reset/app_reset.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <esp_err.h>
|
||||
#include <iot_button.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Create a button handle
|
||||
*
|
||||
* This is just a wrapper over iot_button_create(). This can be used to register
|
||||
* Wi-Fi/Factory reset functionality for a button.
|
||||
*
|
||||
* @param[in] gpio_num GPIO index of the pin that the button uses.
|
||||
* @param[in] active_level button hardware active level.
|
||||
* "BUTTON_ACTIVE_LOW" means that when the button is pressed, the GPIO will read low level.
|
||||
* For "BUTTON_ACTIVE_HIGH", it will be reverse.
|
||||
*
|
||||
* @return A button_handle_t handle to the created button object, or NULL in case of error.
|
||||
*/
|
||||
button_handle_t app_reset_button_create(gpio_num_t gpio_num, button_active_t active_level);
|
||||
|
||||
/** Register callbacks for Wi-Fi/Factory reset
|
||||
*
|
||||
* Register Wi-Fi reset or factory reset functionality on a button.
|
||||
* If you want to use different buttons for these two, call this API twice, with appropriate
|
||||
* button handles.
|
||||
*
|
||||
* @param[in] btn_handle Button handle returned by iot_button_create() or app_button_create()
|
||||
* @param[in] wifi_reset_timeout Timeout after which the Wi-Fi reset should be triggered. Set to 0,
|
||||
* if you do not want Wi-Fi reset.
|
||||
* @param[in] factory_reset_timeout Timeout after which the factory reset should be triggered. Set to 0,
|
||||
* if you do not want factory reset.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t app_reset_button_register(button_handle_t btn_handle, uint8_t wifi_reset_timeout, uint8_t factory_reset_timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
2
examples/common/app_reset/component.mk
Normal file
2
examples/common/app_reset/component.mk
Normal file
@@ -0,0 +1,2 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := .
|
||||
COMPONENT_SRCDIRS := .
|
||||
Reference in New Issue
Block a user