Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add light sleep support in button actions #2578

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/espurna/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Copyright (C) 2019-2021 by Maxim Prokhorov <prokhorov dot max at outlook dot com
#include "relay.h"
#include "system.h"
#include "ws.h"
#include "wifi.h"

#include "mcp23s08_pin.h"

Expand Down Expand Up @@ -1180,6 +1181,10 @@ void buttonEvent(size_t id, ButtonEvent event) {
#endif
break;

case ButtonAction::Sleep:
lightSleep();

break;
case ButtonAction::None:
break;

Expand Down
1 change: 1 addition & 0 deletions code/espurna/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class ButtonAction {
BrightnessDecrease,
DisplayOn,
Custom,
Sleep,
FanLow,
FanMedium,
FanHigh,
Expand Down
4 changes: 4 additions & 0 deletions code/espurna/config/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
#define BUTTON8_PIN GPIO_NONE
#endif

#ifndef BUTTON_WAKEUP_PIN
#define BUTTON_WAKEUP_PIN BUTTON1_PIN
#endif

#ifndef BUTTON1_PIN_TYPE
#define BUTTON1_PIN_TYPE GPIO_TYPE_HARDWARE
#endif
Expand Down
2 changes: 2 additions & 0 deletions code/espurna/config/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define BUTTON_ACTION_DIM_UP ButtonAction::BrightnessIncrease
#define BUTTON_ACTION_DIM_DOWN ButtonAction::BrightnessDecrease
#define BUTTON_ACTION_DISPLAY_ON ButtonAction::DisplayOn
#define BUTTON_ACTION_SLEEP ButtonAction::Sleep
#define BUTTON_ACTION_CUSTOM ButtonAction::Custom
#define BUTTON_ACTION_FAN_LOW ButtonAction::FanLow
#define BUTTON_ACTION_FAN_MEDIUM ButtonAction::FanMedium
Expand All @@ -49,6 +50,7 @@
#define BUTTON_MODE_DIM_UP BUTTON_ACTION_DIM_UP
#define BUTTON_MODE_DIM_DOWN BUTTON_ACTION_DIM_DOWN
#define BUTTON_MODE_DISPLAY_ON BUTTON_ACTION_DISPLAY_ON
#define BUTTON_MODE_SLEEP BUTTON_ACTION_SLEEP

// compat definitions for DebounceEvent
#define BUTTON_PUSHBUTTON ButtonMask::Pushbutton
Expand Down
18 changes: 18 additions & 0 deletions code/espurna/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ bool sleep() {
return false;
}

void lightSleep()
{
wifi_set_opmode_current(NULL_MODE);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
yield();
wifi_fpm_open();
yield();
gpio_pin_wakeup_enable(GPIO_ID_PIN(BUTTON_WAKEUP_PIN), GPIO_PIN_INTR_LOLEVEL);
wifi_fpm_do_sleep(0xFFFFFFF);
delay(10);
wifi_fpm_close();
wifiTurnOn();
}

bool wakeup() {
if (wifi_fpm_get_sleep_type() != NONE_SLEEP_T) {
wifi_fpm_do_wakeup();
Expand Down Expand Up @@ -3041,3 +3055,7 @@ IPAddress wifiApIp() {
void wifiSetup() {
espurna::wifi::setup();
}

void lightSleep() {
espurna::wifi::lightSleep();
}
1 change: 1 addition & 0 deletions code/espurna/wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ void wifiApCheck();

void wifiRegister(espurna::wifi::EventCallback);
void wifiSetup();
void lightSleep();