Skip to content

Commit f01fc9f

Browse files
committed
fix: reversed sleep state
1 parent 00ef8df commit f01fc9f

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

src/buttons.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ async fn wakeup_button(
8282
state: &GlobalState,
8383
) -> Result<bool, ()> {
8484
if sleep_state() {
85-
let _drop = state.state.lock().await;
85+
state.state.signal();
86+
return Ok(true);
8687
}
8788

8889
Ok(false)

src/lcd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub async fn lcd_task(
128128
log::debug!("current_state: {:?}", current_state);
129129
last_update = Instant::now();
130130

131-
if !sleep_state() {
131+
if sleep_state() {
132132
#[cfg(feature = "esp32c3")]
133133
{
134134
_ = bl_pin.set_high();
@@ -139,7 +139,7 @@ pub async fn lcd_task(
139139
}
140140

141141
unsafe {
142-
crate::state::SLEEP_STATE = true;
142+
crate::state::SLEEP_STATE = false;
143143
}
144144
}
145145

@@ -164,7 +164,7 @@ pub async fn lcd_task(
164164
lcd_driver.display_on_lcd(&mut lcd, &mut delay).unwrap();
165165
}
166166

167-
if sleep_state() && (Instant::now() - last_update).as_secs() > 60 * 5 {
167+
if !sleep_state() && (Instant::now() - last_update).as_secs() > 60 * 5 {
168168
#[cfg(feature = "esp32c3")]
169169
{
170170
_ = bl_pin.set_low();
@@ -175,7 +175,7 @@ pub async fn lcd_task(
175175
}
176176

177177
unsafe {
178-
crate::state::SLEEP_STATE = false;
178+
crate::state::SLEEP_STATE = true;
179179
}
180180
}
181181
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use esp_hal::{
1818
timer::timg::TimerGroup,
1919
};
2020
use esp_storage::FlashStorage;
21-
use state::{get_ota_state, GlobalStateInner, SavedGlobalState, Scene};
21+
use state::{ota_state, GlobalStateInner, SavedGlobalState, Scene};
2222
use structs::ConnSettings;
2323
use translations::init_translations;
2424
use utils::{logger::FkmLogger, set_brownout_detection};
@@ -319,7 +319,7 @@ async fn main(spawner: Spawner) {
319319
tmp_logs.push(msg);
320320
}
321321

322-
if get_ota_state() {
322+
if ota_state() {
323323
continue;
324324
}
325325

src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn sleep_state() -> bool {
2121
}
2222

2323
#[inline(always)]
24-
pub fn get_ota_state() -> bool {
24+
pub fn ota_state() -> bool {
2525
unsafe { OTA_STATE }
2626
}
2727

src/utils/buttons.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ impl ButtonsHandler {
144144
.find(|(_, h)| h.button == button);
145145

146146
if let Some(ref default_handler) = self.default_handler {
147-
_ = default_handler
147+
let res = default_handler
148148
.execute(&ButtonTrigger::Down, 0, state)
149149
.await;
150+
151+
if res == Ok(true) {
152+
return;
153+
}
150154
}
151155

152156
if let Some((i, handler)) = &mut handler {
@@ -237,9 +241,14 @@ impl ButtonsHandler {
237241

238242
let hold_time = (Instant::now() - self.press_time).as_millis();
239243
if let Some(ref default_handler) = self.default_handler {
240-
_ = default_handler
244+
let res = default_handler
241245
.execute(&ButtonTrigger::Up, hold_time, state)
242246
.await;
247+
248+
if res == Ok(true) {
249+
self.current_handler_down = None;
250+
return;
251+
}
243252
}
244253

245254
let handler = &self.handlers[self.current_handler_down.expect("Cant fail")];

src/utils/logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::state::get_ota_state;
1+
use crate::state::ota_state;
22
use alloc::string::String;
33
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
44

@@ -52,7 +52,7 @@ impl log::Log for FkmLogger {
5252
esp_println::println!("{}{} - {}{}", color, record.level(), record.args(), reset);
5353

5454
#[cfg(not(feature = "bat_dev_lcd"))]
55-
if !get_ota_state() {
55+
if !ota_state() {
5656
if LOGS_CHANNEL.is_full() {
5757
_ = LOGS_CHANNEL.try_receive();
5858
}

src/ws.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ async fn ws_rw(
249249
}
250250
},
251251
WsFrame::Binary(data) => {
252-
if !crate::state::get_ota_state() {
252+
if !crate::state::ota_state() {
253253
continue;
254254
}
255255

0 commit comments

Comments
 (0)