ws_oled_driver/lib.rs
1pub mod button;
2pub mod display;
3pub mod gfx;
4pub mod joystick;
5
6use anyhow::Result;
7use button::ButtonController;
8use display::Display;
9use joystick::Joystick;
10
11/// # Device
12/// the `Device` struct offers an organized way to access various componenets on the Waveshare OLED
13/// Display Hat. It has three fields, `display`, `joystick` and `button_controller`
14/// - The `display` field is an instance of the `Display` struct that let's you initialze and control
15/// the display
16/// - The `joystick` is an instance of the `Joystick` struct that let's you initalize and read
17/// input from the joystick on the device.
18/// - The button_controller field is an instance of the ButtonController Struct that let's you
19/// initalize and read input from the three buttons on the device
20///
21/// # Usage
22/// ```
23/// use ws_oled_driver::Device;
24/// let mut device = Device::new()?.initialize_components()?;
25/// ````
26pub struct Device {
27 pub display: Display,
28 pub joystick: Joystick,
29 pub button_controller: ButtonController,
30}
31
32impl Device {
33 /// Creates a new `Device`. It returns `Result<Device, anyhow::Error>`.
34 pub fn new() -> Result<Self> {
35 Ok(Self {
36 display: Display::new()?,
37 joystick: Joystick::new()?,
38 button_controller: ButtonController::new()?,
39 })
40 }
41
42 /// Intializes components - display, joystick & buttons.
43 pub fn initialize_components(&mut self) -> Result<()> {
44 self.display.initialize()?;
45 Ok(())
46 }
47}