1use crate::enum_string::AsStr;
2use crate::error::Ev3Error;
3use std::fmt::{self, Display};
4use std::str::FromStr;
5
6use crate::pub_enum_str;
7
8pub_enum_str! {
9 SensorPort,
10
11 (In1, "ev3-ports:in1"),
12 (In2, "ev3-ports:in2"),
13 (In3, "ev3-ports:in3"),
14 (In4, "ev3-ports:in4"),
15}
16
17pub_enum_str! {
18 MotorPort,
19
20 (OutA, "ev3-ports:outA"),
21 (OutB, "ev3-ports:outB"),
22 (OutC, "ev3-ports:outC"),
23 (OutD, "ev3-ports:outD"),
24}
25
26pub_enum_str! {
27 Direction,
28
29 (Clockwise, "normal"),
30 (CounterClockwise, "inversed"),
31}
32
33pub_enum_str! {
34 Stop,
35
36 (Coast, "coast"),
37 (Brake, "brake"),
38 (Hold, "hold"),
39}
40
41#[derive(Debug)]
42#[allow(missing_docs)]
43pub enum Color {
44 None,
45 Black,
46 Blue,
47 Green,
48 Yellow,
49 Red,
50 White,
51 Brown,
52}
53
54impl Display for Color {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 write!(
57 f,
58 "{}",
59 match self {
60 Self::None => "None",
61 Self::Black => "Black",
62 Self::Blue => "Blue",
63 Self::Green => "Green",
64 Self::Yellow => "Yellow",
65 Self::Red => "Red",
66 Self::White => "White",
67 Self::Brown => "Brown",
68 }
69 )
70 }
71}
72
73impl FromStr for Color {
74 type Err = Ev3Error;
75 fn from_str(s: &str) -> Result<Self, Ev3Error> {
76 match s {
77 "0" => Ok(Color::None),
78 "1" => Ok(Color::Black),
79 "2" => Ok(Color::Blue),
80 "3" => Ok(Color::Green),
81 "4" => Ok(Color::Yellow),
82 "5" => Ok(Color::Red),
83 "6" => Ok(Color::White),
84 "7" => Ok(Color::Brown),
85 _ => Err(Ev3Error::ParseStr {
86 input: s.to_string(),
87 to: "Color".to_string(),
88 }),
89 }
90 }
91}
92
93#[derive(PartialEq, Eq, Hash, Debug)]
95#[allow(missing_docs)]
96pub enum Button {
97 RedUp,
98 BlueUp,
99 RedDown,
100 BlueDown,
101 BeaconOn,
102}