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
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use driver::Attribute;
use driver::AttributeResult;

pub trait Device {
    fn get_attribute(&mut self, name: &str) -> &Attribute;


    fn get_address(&mut self) -> AttributeResult<String> {
        self.get_attribute("address").get_str()
    }

    fn set_command(&mut self, command: String) -> AttributeResult<()> {
        self.get_attribute("command").set_str(command)
    }

    fn get_commands(&mut self) -> AttributeResult<Vec<String>> {
        self.get_attribute("commands").get_vec()
    }

    fn get_driver_name(&mut self) -> AttributeResult<String> {
        self.get_attribute("driver_name").get_str()
    }
}

pub trait Motor: Device {}

pub trait Sensor: Device {
    fn get_bin_data(&mut self) -> AttributeResult<String> {
        self.get_attribute("bin_data").get_str()
    }
    fn get_bin_data_format(&mut self) -> AttributeResult<String> {
        self.get_attribute("bin_data_format").get_str()
    }

    fn get_decimals(&mut self) -> AttributeResult<isize> {
        self.get_attribute("decimals").get_int()
    }

    fn get_fw_version(&mut self) -> AttributeResult<String> {
        self.get_attribute("fw_version").get_str()
    }

    fn get_mode(&mut self) -> AttributeResult<String> {
        self.get_attribute("mode").get_str()
    }
    fn set_mode(&mut self, mode: String) -> AttributeResult<()> {
        self.get_attribute("mode").set_str(mode)
    }

    fn get_modes(&mut self) -> AttributeResult<Vec<String>> {
        self.get_attribute("modes").get_vec()
    }

    fn get_num_values(&mut self) -> AttributeResult<isize> {
        self.get_attribute("num_values").get_int()
    }

    fn get_poll_ms(&mut self) -> AttributeResult<isize> {
        self.get_attribute("poll_ms").get_int()
    }
    fn set_poll_ms(&mut self, poll_ms: isize) -> AttributeResult<()> {
        self.get_attribute("poll_ms").set_int(poll_ms)
    }

    fn get_units(&mut self) -> AttributeResult<String> {
        self.get_attribute("units").get_str()
    }

    fn get_value0(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value0").get_int()
    }
    fn get_value1(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value1").get_int()
    }
    fn get_value2(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value2").get_int()
    }
    fn get_value3(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value3").get_int()
    }
    fn get_value4(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value4").get_int()
    }
    fn get_value5(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value5").get_int()
    }
    fn get_value6(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value6").get_int()
    }
    fn get_value7(&mut self) -> AttributeResult<isize> {
        self.get_attribute("value7").get_int()
    }

    fn get_text_value(&mut self) -> AttributeResult<String> {
        self.get_attribute("text_value").get_str()
    }
}

pub trait Port {
    fn address(&self) -> String;
}

pub enum MotorPort {
    OutA,
    OutB,
    OutC,
    OutD,
}

impl Port for MotorPort {
    fn address(&self) -> String {
        match self {
            MotorPort::OutA => String::from("outA"),
            MotorPort::OutB => String::from("outB"),
            MotorPort::OutC => String::from("outC"),
            MotorPort::OutD => String::from("outD"),
        }
    }
}

pub enum SensorPort {
    In1,
    In2,
    In3,
    In4,
}

impl Port for SensorPort {
    fn address(&self) -> String {
        match self {
            SensorPort::In1 => String::from("in1"),
            SensorPort::In2 => String::from("in2"),
            SensorPort::In3 => String::from("in3"),
            SensorPort::In4 => String::from("in4"),
        }
    }
}