From 44c6c764a8384c3bfe2adbb1e7a57513d723ed2a Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 23 Feb 2024 22:48:50 +0100 Subject: [PATCH] Unsure about the dynamic dispatch. --- src/dispatch.rs | 12 ++++++++++-- src/layout.rs | 12 ++++++++++++ src/main.rs | 16 ++++++++-------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/dispatch.rs b/src/dispatch.rs index 83b18f2..ce7f7ae 100644 --- a/src/dispatch.rs +++ b/src/dispatch.rs @@ -13,14 +13,22 @@ //! let mut dispatch_manager = DispatchManager::new(); //! let macro_action = dispatch_manager.process_keypresses(); // Process captured keypresses and get the corresponding macro action //! ``` -use crate::{keysend::send_keypress, ChannelType}; +use crate::{keysend::send_keypress, layout::A1, layout::B1, layout::C1, ChannelType}; use enum_dispatch::enum_dispatch; +use portable_atomic::Ordering; use crate::{keyboard::KeyCode, layout::KeypadKey}; pub(crate) async fn keydispatch_press(pressed_key: &KeypadKey) { // Big switchcase - + match ( + A1.load(Ordering::Relaxed), + B1.load(Ordering::Relaxed), + C1.load(Ordering::Relaxed), + pressed_key, + ) { + (_, _, _, _) => (), + } // Return } pub(crate) async fn keydispatch_release(pressed_key: &KeypadKey) { diff --git a/src/layout.rs b/src/layout.rs index cd5881d..ecfb6b7 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -4,7 +4,19 @@ //! //! It provides functionality for defining the physical layout of the macropad, mapping keys to specific actions or macros, and managing the layout configuration. //! + +// TODO: Add a macro to generate all this and most of the dispatch + +use core::sync::atomic::AtomicBool; // #[derive(Debug)] +pub(crate) static A1: AtomicBool = AtomicBool::new(false); +pub(crate) static B1: AtomicBool = AtomicBool::new(false); +pub(crate) static C1: AtomicBool = AtomicBool::new(false); +pub(crate) enum MODKEYS { + A1, + B1, + C1, +} pub(crate) enum KeypadKey { A1, A2, diff --git a/src/main.rs b/src/main.rs index 6b8e3ae..fee559a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,14 +107,14 @@ async fn main(_spawner: Spawner) { }; let in_fut = async { - loop { - await_key(p.PIN_1, layout::KeypadKey::A1, &channel); - // info!("Waiting for HIGH on pin 1"); - // pin.wait_for_high().await; - // info!("HIGH DETECTED"); - // pin.wait_for_low().await; - // info!("LOW DETECTED"); - } + // loop { + await_key(p.PIN_1, layout::KeypadKey::A1, &channel).await; + // info!("Waiting for HIGH on pin 1"); + // pin.wait_for_high().await; + // info!("HIGH DETECTED"); + // pin.wait_for_low().await; + // info!("LOW DETECTED"); + // } }; let out_fut = async {