diff --git a/lib/obus_can.h b/lib/obus_can.h index a07574d..b384ea2 100644 --- a/lib/obus_can.h +++ b/lib/obus_can.h @@ -267,6 +267,10 @@ inline void send_i_infomessage(struct module from, uint8_t *data, uint8_t data_l send(&msg); } +inline bool is_from_controller(struct module from) { + return from.type == OBUS_TYPE_CONTROLLER && from.id == OBUS_CONTROLLER_ID; +} + } #endif /* end of include guard: OBUS_CAN_H */ diff --git a/lib/obus_module.cpp b/lib/obus_module.cpp index 02b6836..45c3259 100644 --- a/lib/obus_module.cpp +++ b/lib/obus_module.cpp @@ -115,7 +115,7 @@ bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(), void bool interesting_message = false; if (obus_can::receive(message)) { - if (message->from.type == OBUS_TYPE_CONTROLLER && message->from.id == 0) { + if (is_from_controller(message->from)) { switch (message->msg_type) { case OBUS_MSGTYPE_C_GAMESTART: active = true; @@ -157,7 +157,7 @@ bool loopNeedy(obus_can::message* message, void (*callback_game_start)(), void ( bool loopInfo(obus_can::message* message, int (*info_generator)(uint8_t*)) { bool interesting_message = false; if (obus_can::receive(message)) { - if (message->from.type == OBUS_TYPE_CONTROLLER && message->from.id == 0) { + if (is_from_controller(message->from)) { switch (message->msg_type) { case OBUS_MSGTYPE_C_INFOSTART: {