From e366853f11671b6a8f3c2835498ae5b6596f3b8c Mon Sep 17 00:00:00 2001 From: redfast00 Date: Thu, 22 Oct 2020 21:16:12 +0200 Subject: [PATCH] Extract function --- lib/obus_can.h | 4 ++++ lib/obus_module.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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: {