Change field from "puzzles solved" to "… left"

This commit is contained in:
Midgard 2021-02-01 18:51:02 +01:00
parent 1f14c8aecd
commit dd9bceecbf
Signed by: midgard
GPG key ID: 511C112F1331BBB4
6 changed files with 30 additions and 31 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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