1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Input device module for RMK
//!
//! This module defines the `InputDevice` trait, `Runnable` trait and several macros for running input devices and processors.
//! The `InputDevice` trait provides the interface for individual input devices, and the macros facilitate their concurrent execution.
use crateRunnable;
/// The trait for input devices.
///
/// This trait defines the interface for input devices in RMK.
/// Use the `#[input_device]` macro to automatically implement this trait.
///
/// # Example
/// ```rust
/// // For single-event devices, use the macro:
/// #[input_device(publish = BatteryEvent)]
/// struct MyInputDevice;
///
/// impl MyInputDevice {
/// // You MUST implement this read method for the published event.
/// // The method name follows the pattern: read_{event_name}_event
/// async fn read_battery_event(&mut self) -> BatteryEvent {
/// // Implementation for reading an event
/// }
/// }
///
/// // For multi-event devices, a derived enum should be used.
/// // **Note**: Wrapper enums only implement publish traits, not subscribe traits.
/// // This is because wrapper enums route events to their concrete type channels,
/// // and you should subscribe to the individual event types instead.
/// #[derive(Event)]
/// enum MultiDeviceEvent {
/// Battery(BatteryEvent),
/// Pointing(PointingEvent),
/// }
///
/// #[input_device(publish = MultiDeviceEvent)]
/// struct MyInputDevice;
///
/// impl MyInputDevice {
/// // Returns the `MultiDeviceEvent`
/// async fn read_multi_device_event(&mut self) -> MultiDeviceEvent {
/// // Implementation for reading multiple types of events
/// }
/// }
/// ```
/// Run multiple tasks concurrently by calling each task's `run` method.
///
/// The `Runnable` trait is brought into scope for input devices and
/// processors. Types with an inherent `run` method, such as `BleTransport`,
/// can be included without implementing `Runnable`.
///
/// # Example
/// ```rust
/// // Define your runnables
/// let mut device = MyInputDevice::new();
/// let mut processor = MyProcessor::new();
///
/// // Run all runnables concurrently
/// run_all!(device, processor);
/// ```