7
mirror of https://github.com/tenderlove/initial-v.git synced 2025-04-07 18:05:08 +00:00

simplify predicate definition

This commit is contained in:
Aaron Patterson 2022-08-20 13:38:29 -07:00
parent c872d2dfd4
commit cbebe3742e
No known key found for this signature in database
GPG Key ID: 953170BCB4FFAFC6

View File

@ -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);