-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #761 from andrewdavidmackenzie/pigg_625
Pigg 625
- Loading branch information
Showing
27 changed files
with
1,100 additions
and
849 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
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,49 @@ | ||
use crate::hw_definition::config::HardwareConfigMessage::IOLevelChanged; | ||
use crate::hw_definition::config::LevelChange; | ||
use crate::hw_definition::BCMPinNumber; | ||
use crate::HARDWARE_EVENT_CHANNEL; | ||
use defmt::info; | ||
use embassy_futures::select::{select, Either}; | ||
use embassy_rp::gpio::{Flex, Level}; | ||
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | ||
use embassy_sync::channel::{Receiver, Sender}; | ||
use embassy_time::Instant; | ||
|
||
/// Wait until a level change on an input occurs and then send it via TCP to GUI | ||
#[embassy_executor::task(pool_size = 32)] | ||
pub async fn monitor_input( | ||
bcm_pin_number: BCMPinNumber, | ||
signaller: Receiver<'static, ThreadModeRawMutex, bool, 1>, | ||
returner: Sender<'static, ThreadModeRawMutex, Flex<'static>, 1>, | ||
mut flex: Flex<'static>, | ||
) { | ||
let mut level = flex.get_level(); | ||
send_input_level(bcm_pin_number, level).await; | ||
|
||
loop { | ||
match select(flex.wait_for_any_edge(), signaller.receive()).await { | ||
Either::First(()) => { | ||
let new_level = flex.get_level(); | ||
if new_level != level { | ||
send_input_level(bcm_pin_number, flex.get_level()).await; | ||
level = new_level; | ||
} | ||
} | ||
Either::Second(_) => { | ||
info!("Monitor returning Pin"); | ||
let _ = returner.send(flex).await; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Send a detected input level change back to the GUI, timestamping with the Duration since boot | ||
async fn send_input_level(bcm: BCMPinNumber, level: Level) { | ||
let level_change = LevelChange::new( | ||
level == Level::High, | ||
Instant::now().duration_since(Instant::MIN).into(), | ||
); | ||
let hardware_event = IOLevelChanged(bcm, level_change); | ||
HARDWARE_EVENT_CHANNEL.sender().send(hardware_event).await; | ||
} |
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.