feat: added get/set battery mode
This commit is contained in:
parent
3d789205d1
commit
1391c9b3c1
@ -32,7 +32,7 @@ extern "C"
|
||||
wifi_interface_t wifi_interface; // WiFi interface (STA or AP) used for ESP-NOW operation. @note The MAC address of the device depends on the selected WiFi interface.
|
||||
uint8_t wifi_channel; // Wi-Fi channel uses to send/receive ESP-NOW data. @note Values from 1 to 14.
|
||||
uint8_t attempts; // Maximum number of attempts to send a message. @note It is not recommended to set a value greater than 10.
|
||||
bool battery_mode; // Battery operation mode. If true, the node does not receive messages.
|
||||
bool battery_mode; // Battery operation mode. If true the node does not receive messages.
|
||||
} zh_espnow_init_config_t;
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(ZH_ESPNOW);
|
||||
@ -160,6 +160,24 @@ extern "C"
|
||||
*/
|
||||
esp_err_t zh_espnow_set_channel(uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Get battery mode.
|
||||
*
|
||||
* @return True if battery mode set false otherwise.
|
||||
*/
|
||||
bool zh_espnow_get_battery_mode(void);
|
||||
|
||||
/**
|
||||
* @brief Set battery mode.
|
||||
*
|
||||
* @param[in] battery_mode True to enable the mode false to disable it.
|
||||
*
|
||||
* @note If true the node does not receive messages.
|
||||
*
|
||||
* @return ESP_OK if success or an error code otherwise.
|
||||
*/
|
||||
esp_err_t zh_espnow_set_battery_mode(bool battery_mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1 +1 @@
|
||||
1.5.0
|
||||
1.6.0
|
22
zh_espnow.c
22
zh_espnow.c
@ -571,3 +571,25 @@ esp_err_t zh_espnow_set_channel(uint8_t channel)
|
||||
ZH_ESPNOW_LOGI("ESP-NOW channel set successfully.");
|
||||
return err;
|
||||
}
|
||||
|
||||
bool zh_espnow_get_battery_mode(void)
|
||||
{
|
||||
return _init_config.battery_mode;
|
||||
}
|
||||
|
||||
esp_err_t zh_espnow_set_battery_mode(bool battery_mode)
|
||||
{
|
||||
ZH_ESPNOW_CHECK(_is_initialized == true, ESP_ERR_INVALID_STATE, "Battery mode set failed. ESP-NOW is not initialized.");
|
||||
esp_err_t err = esp_now_unregister_send_cb();
|
||||
ZH_ESPNOW_CHECK(err == ESP_OK, err, "Battery mode set failed. Failed to unregister send callback.");
|
||||
if (_init_config.battery_mode == false)
|
||||
{
|
||||
err = esp_now_unregister_recv_cb();
|
||||
ZH_ESPNOW_CHECK(err == ESP_OK, err, "Battery mode set failed. Failed to unregister receive callback.");
|
||||
}
|
||||
err = _zh_espnow_register_callbacks(battery_mode);
|
||||
ZH_ESPNOW_CHECK(err == ESP_OK, err, "Battery mode set failed. Failed to register callbacks.");
|
||||
_init_config.battery_mode = battery_mode;
|
||||
ZH_ESPNOW_LOGI("Battery mode set successfully.");
|
||||
return ESP_OK;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user