6#include "driver/gpio.h"
12RTC_DATA_ATTR
static unsigned int boot_count = 0;
16 type = Esp32Command_power_command_tag;
24 Log.traceln(
"ModulePower::OnReceive");
27 if (cmd.which_command != Esp32Command_power_command_tag) {
31 Log.traceln(
"PowerCommand type: %d", cmd.command.power_command.type);
34 switch (cmd.command.power_command.type) {
35 case PowerCommand_Type_SLEEP:
36 Log.traceln(
"Calling SLEEP");
40 case PowerCommand_Type_WAKEUP:
41 Log.traceln(
"Calling REASON");
46 Log.warningln(
"Power command type not found!");
52 Log.traceln(
"ModulePower::OnRequest");
53 memcpy(
buffer, request_buffer, request_buffer_len);
54 return request_buffer_len;
57void ModulePower::Sleep() {
58 Log.noticeln(
"Setting sleep flag");
61 PowerCommand resp = PowerCommand_init_zero;
62 resp.type = PowerCommand_Type_SLEEP;
68void ModulePower::Wakeup() {
69 Log.noticeln(
"Wakeup called");
71 esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
73 PowerCommand resp = PowerCommand_init_zero;
74 resp.type = PowerCommand_Type_WAKEUP;
75 resp.reason =
static_cast<PowerCommand_WakeupReason
>(wakeup_reason);
76 resp.boot_count = boot_count;
88 Log.noticeln(
"Entering deep sleep mode");
91 const gpio_config_t config = {
92 .pin_bit_mask = BIT(GPIO_NUM_3),
93 .mode = GPIO_MODE_INPUT,
94 .pull_up_en = GPIO_PULLUP_DISABLE,
95 .pull_down_en = GPIO_PULLDOWN_DISABLE,
98 esp_deep_sleep_enable_gpio_wakeup(BIT(wakeup_pin), ESP_GPIO_WAKEUP_GPIO_HIGH);
101 esp_deep_sleep_start();
void OnReceive(const Esp32Command &cmd)
void EnterSleep()
Put the esp32 into a deep sleep state if stated.
size_t OnRequest(uint8_t *buffer)
size_t EncodePowerCommand(const PowerCommand *power_cmd, uint8_t *buffer, size_t size)
Encodes a PowerCommand.
Power module for the esp32.
Module for controlling power on esp32.
Library for encoding/decoding protobuf messages.