Philipp Vollmer | 41b9135 | 2018-02-05 09:55:54 +0100 | [diff] [blame] | 1 | #![no_std] |
Woyten | 2b94dd5 | 2018-07-09 21:06:53 +0200 | [diff] [blame] | 2 | |
torfmaster | c84685a | 2019-02-08 19:23:22 +0100 | [diff] [blame] | 3 | use libtock::ble_parser; |
torfmaster | 3d60524 | 2019-12-16 22:36:39 +0100 | [diff] [blame] | 4 | use libtock::result::TockResult; |
torfmaster | c84685a | 2019-02-08 19:23:22 +0100 | [diff] [blame] | 5 | use libtock::simple_ble; |
Woyten | 30fc95b | 2019-01-10 21:09:46 +0100 | [diff] [blame] | 6 | use serde::Deserialize; |
Philipp Vollmer | 41b9135 | 2018-02-05 09:55:54 +0100 | [diff] [blame] | 7 | |
Johnathan Van Why | 074fa7d | 2020-10-14 17:06:50 -0700 | [diff] [blame] | 8 | libtock_core::stack_size! {0x800} |
| 9 | |
Philipp Vollmer | 349417d | 2018-02-24 17:29:19 +0100 | [diff] [blame] | 10 | #[derive(Deserialize)] |
| 11 | struct LedCommand { |
| 12 | pub nr: u8, |
| 13 | pub st: bool, |
| 14 | } |
Philipp Vollmer | 41b9135 | 2018-02-05 09:55:54 +0100 | [diff] [blame] | 15 | |
torfmaster | b06f637 | 2019-12-17 09:20:48 +0100 | [diff] [blame] | 16 | #[libtock::main] |
torfmaster | 3d60524 | 2019-12-16 22:36:39 +0100 | [diff] [blame] | 17 | async fn main() -> TockResult<()> { |
Woyten | b122620 | 2020-01-13 22:47:48 +0100 | [diff] [blame] | 18 | let mut drivers = libtock::retrieve_drivers()?; |
torfmaster | 98de36a | 2020-02-23 18:55:12 +0100 | [diff] [blame] | 19 | let leds_driver = drivers.leds.init_driver()?; |
torfmaster | 595d9c6 | 2019-12-27 18:15:31 +0100 | [diff] [blame] | 20 | |
torfmaster | dc326a4 | 2020-02-26 23:17:59 +0100 | [diff] [blame] | 21 | let mut ble_scanning_driver_factory = drivers.ble_scanning; |
torfmaster | 76c8194 | 2020-02-23 17:31:59 +0100 | [diff] [blame] | 22 | let mut ble_scanning_driver = ble_scanning_driver_factory.create_driver(); |
| 23 | let mut ble_scanning_driver_sharing = ble_scanning_driver.share_memory()?; |
| 24 | let ble_scanning_driver_scanning = ble_scanning_driver_sharing.start()?; |
torfmaster | 0f902f4 | 2020-01-04 13:07:01 +0100 | [diff] [blame] | 25 | |
torfmaster | 76c8194 | 2020-02-23 17:31:59 +0100 | [diff] [blame] | 26 | loop { |
| 27 | let value = ble_scanning_driver_scanning.stream_values().await; |
| 28 | ble_parser::find(&value, simple_ble::gap_data::SERVICE_DATA as u8) |
Woyten | 2b94dd5 | 2018-07-09 21:06:53 +0200 | [diff] [blame] | 29 | .and_then(|service_data| ble_parser::extract_for_service([91, 79], service_data)) |
| 30 | .and_then(|payload| corepack::from_bytes::<LedCommand>(&payload).ok()) |
torfmaster | 98de36a | 2020-02-23 18:55:12 +0100 | [diff] [blame] | 31 | .and_then(|msg| leds_driver.get(msg.nr as usize).ok()) |
torfmaster | 76c8194 | 2020-02-23 17:31:59 +0100 | [diff] [blame] | 32 | .and_then(|led| led.on().ok()); |
| 33 | } |
Philipp Vollmer | 41b9135 | 2018-02-05 09:55:54 +0100 | [diff] [blame] | 34 | } |