crankit_input/
lib.rs

1#![no_std]
2
3//! An ergonomic input API for the playdate
4//!
5//! The traits [`ButtonsStateSource`] and [`CrankStateSource`] describe the available API.
6//!
7//! ## Feature flags
8//!
9//! * `playdate-sys-v02`: provides implementations of the input source traits for the type `ffi::playdate_sys` and `ffi::PlaydateAPI` of the crate [`playdate-sys`](https://docs.rs/playdate-sys/0.2) (version `0.2`)
10
11mod button;
12mod impls;
13
14pub use button::{Button, Set as ButtonSet, State as ButtonsState};
15
16/// A source of button state
17///
18/// It is notably implemented for for the type `ffi::playdate_sys` and `ffi::PlaydateAPI` of the crate [`playdate-sys`](https://docs.rs/playdate-sys/0.2) (require the feature flag `playdate-sys-v02`)
19pub trait ButtonsStateSource {
20    /// Returns the current [`ButtonsState`]
21    #[must_use]
22    fn buttons_state(&self) -> ButtonsState;
23}
24
25/// A source of the crank state
26///
27/// It is notably implemented for for the type `ffi::playdate_sys` and `ffi::PlaydateAPI` of the crate [`playdate-sys`](https://docs.rs/playdate-sys/0.2) (require the feature flag `playdate-sys-v02`)
28pub trait CrankStateSource {
29    /// Returns the current position of the crank, in degrees (range from `0` to `360`).
30    ///
31    /// Zero is pointing up, and the value increases as the crank moves clockwise, as viewed from the right side of the device.
32    #[must_use]
33    fn crank_angle_deg(&self) -> f32;
34
35    /// Returns the current position of the crank, in the radians (range from `0` to `2 * f32::consts::PI`).
36    ///
37    /// Zero is pointing up, and the value increases as the crank moves clockwise, as viewed from the right side of the device.
38    #[must_use]
39    fn crank_angle_rad(&self) -> f32 {
40        self.crank_angle_deg().to_radians()
41    }
42
43    /// Returns the angle change (in degrees) of the crank since the last time this function was called.
44    ///
45    /// Negative values are anti-clockwise.
46    #[must_use]
47    fn crank_change_deg(&self) -> f32;
48
49    /// Returns the angle change (in radians) of the crank since the last time this function was called.
50    ///
51    /// Negative values are anti-clockwise.
52    #[must_use]
53    fn crank_change_rad(&self) -> f32 {
54        self.crank_angle_deg().to_radians()
55    }
56
57    /// Returns whether or not the crank is folded into the unit.
58    #[must_use]
59    fn is_crank_docked(&self) -> bool;
60}