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
//! A list of all six buttons available on the Arduboy
/// Just a `const` for the UP button
pub const UP: ButtonSet = ButtonSet {
    flag_set: 0b10000000,
};
/// Just a `const` for the RIGHT button
pub const RIGHT: ButtonSet = ButtonSet {
    flag_set: 0b01000000,
};
/// Just a `const` for the LEFT button
pub const LEFT: ButtonSet = ButtonSet {
    flag_set: 0b00100000,
};
/// Just a `const` for the DOWN button
pub const DOWN: ButtonSet = ButtonSet {
    flag_set: 0b00010000,
};
/// Just a `const` for the A button
pub const A: ButtonSet = ButtonSet {
    flag_set: 0b00001000,
};
/// Just a `const` for the B button
pub const B: ButtonSet = ButtonSet {
    flag_set: 0b00000100,
};
/// Just a `const` for the any
pub const ANY_BUTTON: ButtonSet = ButtonSet {
    flag_set: 0b11111111,
};
/// Just a `const` for the UP button
pub const UP_BUTTON: ButtonSet = UP;
/// Just a `const` for the RIGHT button
pub const RIGHT_BUTTON: ButtonSet = RIGHT;
/// Just a `const` for the DOWN button
pub const DOWN_BUTTON: ButtonSet = DOWN;
/// Just a `const` for the LEFT button
pub const LEFT_BUTTON: ButtonSet = LEFT;
/// Just a `const` for the A button
pub const A_BUTTON: ButtonSet = A;
/// Just a `const` for the B button
pub const B_BUTTON: ButtonSet = B;
///This struct gives the library a understanding what Buttons on the Arduboy are.
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct ButtonSet {
    pub flag_set: u8,
}

impl ButtonSet {
    pub fn pressed(&self) -> bool {
        unsafe { crate::libraries::arduboy2_library::binding::pressed(self.flag_set) }
    }

    pub fn just_pressed(&self) -> bool {
        unsafe { crate::libraries::arduboy2_library::binding::just_pressed(self.flag_set) }
    }

    pub fn just_released(&self) -> bool {
        unsafe { crate::libraries::arduboy2_library::binding::just_released(self.flag_set) }
    }
    pub fn not_pressed(&self) -> bool {
        unsafe { crate::libraries::arduboy2_library::binding::not_pressed(self.flag_set) }
    }
}

impl core::ops::BitOr for ButtonSet {
    type Output = Self;

    fn bitor(self, other: Self) -> Self {
        Self {
            flag_set: self.flag_set | other.flag_set,
        }
    }
}