-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb2582b
commit bfa5ab1
Showing
20 changed files
with
896 additions
and
193 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::{error::Error, str::FromStr}; | ||
|
||
use crate::bluetooth::Connection; | ||
use crate::config::*; | ||
use btleplug::api::Peripheral; | ||
use tokio::sync::mpsc; | ||
use uuid::Uuid; | ||
|
||
pub enum BleAction { | ||
CalibrateCo2, | ||
CalibrateTemperature(i32), | ||
Stop, | ||
} | ||
|
||
pub async fn run_ble_mpsc<TPeripheral: Peripheral>( | ||
connection: &Connection<TPeripheral>, | ||
mut ble_action_receiver: mpsc::Receiver<BleAction>, | ||
) -> Result<(), Box<dyn Error>> { | ||
while let Some(action) = ble_action_receiver.recv().await { | ||
match action { | ||
BleAction::CalibrateCo2 => { | ||
tracing::info!("Calibrating CO2 sensor"); | ||
connection | ||
.write_to_sennsor( | ||
"what the fuck".as_bytes(), | ||
Uuid::from_str(&BLE_MAIN_SENSOR_CO2_CALIBRATION_CHAR).unwrap(), | ||
) | ||
.await? | ||
} | ||
BleAction::CalibrateTemperature(_temperature) => { | ||
tracing::info!("Calibrating temperature sensor"); | ||
} | ||
BleAction::Stop => { | ||
connection.disconnect().await?; | ||
tracing::info!("Stopping BLE actions"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.