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
use crate::io::gpio::{GPIOError, GPIOManager, GPIOMode, GPIOState};
use chrono::Utc;
use std::collections::HashMap;

#[derive(Default)]
pub struct Dummy {
    map: HashMap<usize, GPIOState>,
}

impl GPIOManager for Dummy {
    fn setup(&mut self, _pin: usize, _mode: &GPIOMode) -> Result<(), GPIOError> {
        Ok(())
    }

    fn set_pin(&mut self, pin_id: usize, state: &GPIOState) -> Result<(), GPIOError> {
        println!(
            "{} Setting pin {} to {:?}",
            Utc::now().format("%H:%M:%S"),
            pin_id,
            state
        );
        self.map.insert(pin_id, state.clone());
        Ok(())
    }

    fn get_pin(&self, pin: usize) -> Result<GPIOState, GPIOError> {
        Ok(self.map.get(&pin).cloned().unwrap_or(GPIOState::High))
    }
}