diff --git a/firmware/components/shifter/include/shifter.h b/firmware/components/shifter/include/shifter.h index 3d120b0..52f6988 100644 --- a/firmware/components/shifter/include/shifter.h +++ b/firmware/components/shifter/include/shifter.h @@ -9,25 +9,27 @@ extern "C" { #endif -static inline bool -SHIFTER_BACK_P(twai_message_t message) -{ - return message.identifier == 0x197 && message.data[2] == 0x3e; +#define POSITION_PREDICATE(name, byte) \ +static inline bool SHIFTER_##name##_P(twai_message_t message) \ +{ \ + return message.identifier == 0x197 && message.data[2] == byte; \ } +POSITION_PREDICATE(CENTER, 0x0e); +POSITION_PREDICATE(UP, 0x1e); +POSITION_PREDICATE(UP_UP, 0x2e); +POSITION_PREDICATE(DOWN, 0x3e); +POSITION_PREDICATE(DOWN_DOWN, 0x4e); +POSITION_PREDICATE(SIDE_UP, 0x5e); +POSITION_PREDICATE(SIDE_DOWN, 0x6e); +POSITION_PREDICATE(SIDE, 0x7e); + static inline bool SHIFTER_PARK_P(twai_message_t message) { return message.identifier == 0x197 && message.data[3] == 0xd5; } -static inline bool -SHIFTER_CENTER_P(twai_message_t message) -{ - return message.identifier == 0x197 && message.data[2] == 0x0e && - message.data[3] == 0xc0; -} - void shifter_send_park(void); void shifter_send_drive(bool moveable); void shifter_send_reset(void);