From dd9bceecbf0d14e8f63f73913dd5e552099a1b0f Mon Sep 17 00:00:00 2001 From: Midgard Date: Mon, 1 Feb 2021 18:51:02 +0100 Subject: [PATCH] =?UTF-8?q?Change=20field=20from=20"puzzles=20solved"=20to?= =?UTF-8?q?=20"=E2=80=A6=20left"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/protocol.txt | 4 ++-- lib/obus_can.cpp | 10 +++++----- lib/obus_can.h | 26 +++++++++++++------------- lib/obus_module.cpp | 13 ++++++------- lib/obus_module.h | 6 +++--- src/controller/controller.ino | 2 +- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/docs/protocol.txt b/docs/protocol.txt index 9ac7f92..176b8bc 100644 --- a/docs/protocol.txt +++ b/docs/protocol.txt @@ -57,13 +57,13 @@ Types for controller: - 3 state (every x ms – e.g. in the middle of each second) [ X B B B B B B B ] -------- - - - - time left ↓ ↓ #solved puzzle modules + time left ↓ ↓ #puzzle modules left #strikes #max strikes - 4-6 solved, timeout, strikeout [ X B B B B B B B ] -------- - - - - end time ↓ ↓ #solved puzzle modules + end time ↓ ↓ #puzzle modules left #strikes #max strikes - 7 info start diff --git a/lib/obus_can.cpp b/lib/obus_can.cpp index 6df9e73..c688d14 100644 --- a/lib/obus_can.cpp +++ b/lib/obus_can.cpp @@ -118,10 +118,10 @@ bool receive(struct message *msg) { Serial.println(F("W Received illegal gamestatus msg: payload <8")); return false; } - msg->gamestatus.time_left = unpack_4b_into_u32(&(receive_frame.data[1])); - msg->gamestatus.strikes = receive_frame.data[5]; - msg->gamestatus.max_strikes = receive_frame.data[6]; - msg->gamestatus.puzzle_modules_solved = receive_frame.data[7]; + msg->gamestatus.time_left = unpack_4b_into_u32(&(receive_frame.data[1])); + msg->gamestatus.strikes = receive_frame.data[5]; + msg->gamestatus.max_strikes = receive_frame.data[6]; + msg->gamestatus.puzzle_modules_left = receive_frame.data[7]; break; case OBUS_PAYLDTYPE_COUNT: @@ -187,7 +187,7 @@ void send(struct message *msg) { pack_u32_into_4b(&(send_frame.data[1]), msg->gamestatus.time_left); send_frame.data[5] = msg->gamestatus.strikes; send_frame.data[6] = msg->gamestatus.max_strikes; - send_frame.data[7] = msg->gamestatus.puzzle_modules_solved; + send_frame.data[7] = msg->gamestatus.puzzle_modules_left; length = 8; break; diff --git a/lib/obus_can.h b/lib/obus_can.h index 5f3c6b4..9ce9fe1 100644 --- a/lib/obus_can.h +++ b/lib/obus_can.h @@ -51,7 +51,7 @@ struct payld_gamestatus { uint32_t time_left; uint8_t strikes; uint8_t max_strikes; - uint8_t puzzle_modules_solved; + uint8_t puzzle_modules_left; }; struct payld_infomessage { uint8_t len; @@ -129,13 +129,13 @@ inline struct message _msg(struct module from, bool priority, uint8_t msg_type) */ inline void _send_payld_gamestatus( struct module from, bool priority, uint8_t msg_type, - uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) { + uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) { struct message msg = _msg(from, priority, msg_type); msg.gamestatus.time_left = time_left; msg.gamestatus.strikes = strikes; msg.gamestatus.max_strikes = max_strikes; - msg.gamestatus.puzzle_modules_solved = puzzle_modules_solved; + msg.gamestatus.puzzle_modules_left = puzzle_modules_left; send(&msg); } @@ -165,44 +165,44 @@ inline void send_c_hello(struct module from) { * Send a controller "game start" OBUS message */ inline void send_c_gamestart( - struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) { + struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) { assert(from.type == OBUS_TYPE_CONTROLLER); _send_payld_gamestatus( - from, false, OBUS_MSGTYPE_C_GAMESTART, time_left, strikes, max_strikes, puzzle_modules_solved); + from, false, OBUS_MSGTYPE_C_GAMESTART, time_left, strikes, max_strikes, puzzle_modules_left); } /** * Send a controller "state" OBUS message */ inline void send_c_state( - struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) { + struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) { assert(from.type == OBUS_TYPE_CONTROLLER); _send_payld_gamestatus( - from, false, OBUS_MSGTYPE_C_STATE, time_left, strikes, max_strikes, puzzle_modules_solved); + from, false, OBUS_MSGTYPE_C_STATE, time_left, strikes, max_strikes, puzzle_modules_left); } /** * Send a controller "solved" OBUS message */ inline void send_c_solved( - struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) { + struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) { assert(from.type == OBUS_TYPE_CONTROLLER); _send_payld_gamestatus( - from, false, OBUS_MSGTYPE_C_SOLVED, time_left, strikes, max_strikes, puzzle_modules_solved); + from, false, OBUS_MSGTYPE_C_SOLVED, time_left, strikes, max_strikes, puzzle_modules_left); } /** * Send a controller "timeout" OBUS message */ inline void send_c_timeout( - struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) { + struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) { assert(from.type == OBUS_TYPE_CONTROLLER); _send_payld_gamestatus( - from, false, OBUS_MSGTYPE_C_TIMEOUT, time_left, strikes, max_strikes, puzzle_modules_solved); + from, false, OBUS_MSGTYPE_C_TIMEOUT, time_left, strikes, max_strikes, puzzle_modules_left); } /** @@ -218,11 +218,11 @@ inline void send_c_infostart(struct module from) { * Send a controller "strikeout" OBUS message */ inline void send_c_strikeout( - struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) { + struct module from, uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) { assert(from.type == OBUS_TYPE_CONTROLLER); _send_payld_gamestatus( - from, false, OBUS_MSGTYPE_C_STRIKEOUT, time_left, strikes, max_strikes, puzzle_modules_solved); + from, false, OBUS_MSGTYPE_C_STRIKEOUT, time_left, strikes, max_strikes, puzzle_modules_left); } diff --git a/lib/obus_module.cpp b/lib/obus_module.cpp index 9169c3d..d6bfe78 100644 --- a/lib/obus_module.cpp +++ b/lib/obus_module.cpp @@ -108,12 +108,12 @@ void empty_callback_info(uint8_t info_id, uint8_t infomessage[7]) { (void)infomessage; } -void empty_callback_state(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) { +void empty_callback_state(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) { // Mark arguments as not used (void)time_left; (void)strikes; (void)max_strikes; - (void)puzzle_modules_solved; + (void)puzzle_modules_left; } void blink_error(String message) { @@ -127,7 +127,7 @@ void blink_error(String message) { } } -bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]), void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved)) { +bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]), void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left)) { // TODO this can be more efficient by only enabling error interrupts and // reacting to the interrupt instead of checking if the flag is set in a loop // We will need to fork our CAN library for this, because the needed functions are private. @@ -150,8 +150,7 @@ bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t case OBUS_MSGTYPE_C_GAMESTART: active = true; _setLed(COLOR_YELLOW); - // The field is named puzzle_modules_solved, but it actually contains the amount of puzzle modules - callback_game_start(message->gamestatus.puzzle_modules_solved); + callback_game_start(message->gamestatus.puzzle_modules_left); break; case OBUS_MSGTYPE_C_HELLO: _resetState(); @@ -167,7 +166,7 @@ bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t case OBUS_MSGTYPE_C_ACK: break; case OBUS_MSGTYPE_C_STATE: - callback_state(message->gamestatus.time_left, message->gamestatus.strikes, message->gamestatus.max_strikes, message->gamestatus.puzzle_modules_solved); + callback_state(message->gamestatus.time_left, message->gamestatus.strikes, message->gamestatus.max_strikes, message->gamestatus.puzzle_modules_left); break; default: break; @@ -184,7 +183,7 @@ bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t return received_message; } -bool loopNeedy(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]), void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved)) { +bool loopNeedy(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]), void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left)) { // For now this is the same function return loopPuzzle(message, callback_game_start, callback_game_stop, callback_info, callback_state); } diff --git a/lib/obus_module.h b/lib/obus_module.h index 0705b00..3c8490b 100644 --- a/lib/obus_module.h +++ b/lib/obus_module.h @@ -13,11 +13,11 @@ namespace obus_module { void setup(uint8_t type, uint8_t id); void empty_callback_info(uint8_t info_id, uint8_t infomessage[7]); -void empty_callback_state(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved); +void empty_callback_state(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left); -bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]) = empty_callback_info, void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) = empty_callback_state); +bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]) = empty_callback_info, void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) = empty_callback_state); -bool loopNeedy(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]) = empty_callback_info, void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_solved) = empty_callback_state); +bool loopNeedy(obus_can::message* message, void (*callback_game_start)(uint8_t puzzle_modules), void (*callback_game_stop)(), void (*callback_info)(uint8_t info_id, uint8_t infomessage[7]) = empty_callback_info, void (*callback_state)(uint32_t time_left, uint8_t strikes, uint8_t max_strikes, uint8_t puzzle_modules_left) = empty_callback_state); bool loopInfo(obus_can::message* message, int (*info_generator)(uint8_t*)); diff --git a/src/controller/controller.ino b/src/controller/controller.ino index 232a3af..79371c8 100644 --- a/src/controller/controller.ino +++ b/src/controller/controller.ino @@ -20,7 +20,7 @@ #define OBUS_INFO_DURATION_MS ((uint32_t) OBUS_INFO_DURATION*1000) #define DIVIDE_CEIL(dividend, divisor) ((dividend + (divisor - 1)) / divisor) -#define MAX_AMOUNT_PUZZLES 256 // The ID of a puzzle is uint8 +#define MAX_AMOUNT_PUZZLES (UINT8_MAX + 1) // The ID of a puzzle is a zero-based uint8 // buttons contains a byte with values of button s8s7s6s5s4s3s2s1