Only enable module if it has been acked
This commit is contained in:
parent
415b77e80c
commit
14fce40f9f
1 changed files with 16 additions and 7 deletions
|
@ -19,6 +19,7 @@ namespace obus_module {
|
||||||
struct obus_can::module this_module;
|
struct obus_can::module this_module;
|
||||||
uint8_t strike_count;
|
uint8_t strike_count;
|
||||||
bool active;
|
bool active;
|
||||||
|
bool acked_after_last_hello = false;
|
||||||
uint32_t next_loop_call_deadline;
|
uint32_t next_loop_call_deadline;
|
||||||
|
|
||||||
// Current LED status
|
// Current LED status
|
||||||
|
@ -91,6 +92,7 @@ void _resetState() {
|
||||||
strike_count = 0;
|
strike_count = 0;
|
||||||
active = false;
|
active = false;
|
||||||
next_loop_call_deadline = 0;
|
next_loop_call_deadline = 0;
|
||||||
|
acked_after_last_hello = false;
|
||||||
|
|
||||||
if (this_module.type == OBUS_TYPE_PUZZLE || this_module.type == OBUS_TYPE_NEEDY) {
|
if (this_module.type == OBUS_TYPE_PUZZLE || this_module.type == OBUS_TYPE_NEEDY) {
|
||||||
pinMode(PIN_LED_RED, OUTPUT);
|
pinMode(PIN_LED_RED, OUTPUT);
|
||||||
|
@ -145,9 +147,11 @@ bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t
|
||||||
if (is_from_controller(message->from)) {
|
if (is_from_controller(message->from)) {
|
||||||
switch (message->msg_type) {
|
switch (message->msg_type) {
|
||||||
case OBUS_MSGTYPE_C_GAMESTART:
|
case OBUS_MSGTYPE_C_GAMESTART:
|
||||||
|
if (acked_after_last_hello) {
|
||||||
active = true;
|
active = true;
|
||||||
_setLed(COLOR_YELLOW);
|
_setLed(COLOR_YELLOW);
|
||||||
callback_game_start(message->gamestatus.puzzle_modules_left);
|
callback_game_start(message->gamestatus.puzzle_modules_left);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OBUS_MSGTYPE_C_HELLO:
|
case OBUS_MSGTYPE_C_HELLO:
|
||||||
_resetState();
|
_resetState();
|
||||||
|
@ -156,18 +160,23 @@ bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t
|
||||||
case OBUS_MSGTYPE_C_SOLVED:
|
case OBUS_MSGTYPE_C_SOLVED:
|
||||||
case OBUS_MSGTYPE_C_TIMEOUT:
|
case OBUS_MSGTYPE_C_TIMEOUT:
|
||||||
case OBUS_MSGTYPE_C_STRIKEOUT:
|
case OBUS_MSGTYPE_C_STRIKEOUT:
|
||||||
|
if (acked_after_last_hello) {
|
||||||
active = false;
|
active = false;
|
||||||
_setLed(COLOR_OFF);
|
_setLed(COLOR_OFF);
|
||||||
callback_game_stop();
|
callback_game_stop();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OBUS_MSGTYPE_C_ACK:
|
case OBUS_MSGTYPE_C_ACK:
|
||||||
|
if (message->payload_address.type == this_module.type && message->payload_address.id == this_module.id) {
|
||||||
|
acked_after_last_hello = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OBUS_MSGTYPE_C_STATE:
|
case OBUS_MSGTYPE_C_STATE:
|
||||||
callback_state(message->gamestatus.time_left, message->gamestatus.strikes, message->gamestatus.max_strikes, message->gamestatus.puzzle_modules_left);
|
callback_state(message->gamestatus.time_left, message->gamestatus.strikes, message->gamestatus.max_strikes, message->gamestatus.puzzle_modules_left);
|
||||||
break;
|
break;
|
||||||
case OBUS_MSGTYPE_C_INFOSTART:
|
case OBUS_MSGTYPE_C_INFOSTART:
|
||||||
// Add module type and id to seed, to remove correlation in randomness between modules
|
// Add module type and id to seed, to remove correlation in randomness between modules
|
||||||
uinst32_t seed = message->infostart.seed + ((uint32_t) this_module.type << 8) + ((uint32_t) this_module.id);
|
uint32_t seed = message->infostart.seed + ((uint32_t) this_module.type << 8) + ((uint32_t) this_module.id);
|
||||||
// randomSeed has no effect when called with 0 as seed, so we use
|
// randomSeed has no effect when called with 0 as seed, so we use
|
||||||
// a fallback value that is unlikely to collide with other frequently used seeds
|
// a fallback value that is unlikely to collide with other frequently used seeds
|
||||||
if (seed == 0) {
|
if (seed == 0) {
|
||||||
|
|
Loading…
Reference in a new issue