@@ -2,12 +2,13 @@ use crate::{
22 state:: { BleAction , GlobalState , MenuScene } ,
33 structs:: BleDisplayDevice ,
44} ;
5- use alloc:: string:: ToString ;
5+ use alloc:: { rc :: Rc , string:: ToString } ;
66use core:: cell:: RefCell ;
77use embassy_futures:: select:: { Either , select, select3, select4} ;
88use embassy_sync:: {
9- blocking_mutex:: raw:: NoopRawMutex ,
9+ blocking_mutex:: raw:: { CriticalSectionRawMutex , NoopRawMutex } ,
1010 channel:: { Channel , Sender } ,
11+ signal:: Signal ,
1112} ;
1213use embassy_time:: { Duration , Timer , with_timeout} ;
1314use esp_radio:: { Controller as RadioController , ble:: controller:: BleConnector } ;
@@ -19,6 +20,35 @@ pub async fn bluetooth_timer_task(
1920 init : & ' static RadioController < ' static > ,
2021 bt : esp_hal:: peripherals:: BT < ' static > ,
2122 state : GlobalState ,
23+ sleep_sig : Rc < Signal < CriticalSectionRawMutex , bool > > ,
24+ ) {
25+ loop {
26+ let mut sleep = false ;
27+ embassy_futures:: select:: select ( bluetooth_loop ( init, & bt, & state) , async {
28+ loop {
29+ if sleep_sig. wait ( ) . await {
30+ sleep = true ;
31+ break ;
32+ }
33+ }
34+ } )
35+ . await ;
36+
37+ Timer :: after_millis ( 1000 ) . await ;
38+ if sleep {
39+ loop {
40+ if !sleep_sig. wait ( ) . await {
41+ break ;
42+ }
43+ }
44+ }
45+ }
46+ }
47+
48+ async fn bluetooth_loop (
49+ init : & ' static RadioController < ' static > ,
50+ bt : & esp_hal:: peripherals:: BT < ' static > ,
51+ state : & GlobalState ,
2252) {
2353 loop {
2454 let mut bond_info = if let Some ( bond_info) = load_bonding_info ( & state. nvs ) . await {
0 commit comments