ev3dev_lang_rust/sensors/
touch_sensor.rs

1//! Touch Sensor
2
3use super::{Sensor, SensorPort};
4use crate::{Attribute, Device, Driver, Ev3Error, Ev3Result};
5
6/// Touch Sensor
7#[derive(Debug, Clone, Device, Sensor)]
8pub struct TouchSensor {
9    driver: Driver,
10}
11
12impl TouchSensor {
13    fn new(driver: Driver) -> Self {
14        Self { driver }
15    }
16
17    findable!(
18        "lego-sensor",
19        ["lego-ev3-touch", "lego-nxt-touch"],
20        SensorPort,
21        "TouchSensor",
22        "in"
23    );
24
25    /// Button state
26    pub const MODE_TOUCH: &'static str = "TOUCH";
27
28    /// A boolean indicating whether the current touch sensor is being pressed.
29    pub fn get_pressed_state(&self) -> Ev3Result<bool> {
30        Ok(self.get_value0()? != 0)
31    }
32}