3,12 → 3,10 |
#include "I2C1.h" |
|
static CONTROLLER_DATA *ctrl_data_p; |
static BOARD_STATE *board_state_p; |
|
void Controller_Init(CONTROLLER_DATA *data, BOARD_STATE *state, |
void Controller_Init(CONTROLLER_DATA *data, |
void (*btn_change_callback)(uint8_t, uint8_t)) { |
ctrl_data_p = data; |
board_state_p = state; |
|
ctrl_data_p->btn_change_callback = btn_change_callback; |
|
105,23 → 103,20 |
} |
|
// If board is in an idle state and a controller is connected, switch modes |
if (board_state_p->cube_mode == BOARD_MODE_IDLE) { |
if (Get_Board_State() == BOARD_MODE_IDLE) { |
// If both controllers are active, go into game TRON mode |
if (ctrl_data_p->ctrl_1_active && ctrl_data_p->ctrl_2_active) { |
board_state_p->cube_mode = BOARD_MODE_TRON; |
Reset_Board(); |
Reset_Board(BOARD_MODE_TRON); |
} |
// Otherwise if only one controller is active, go into game SNAKE mode |
if (ctrl_data_p->ctrl_1_active || ctrl_data_p->ctrl_2_active) { |
board_state_p->cube_mode = BOARD_MODE_SNAKE; |
Reset_Board(); |
Reset_Board(BOARD_MODE_SNAKE); |
} |
} |
if (board_state_p->cube_mode == BOARD_MODE_SNAKE) { |
if (Get_Board_State() == BOARD_MODE_SNAKE) { |
// If both controllers are active, go into game TRON mode |
if (ctrl_data_p->ctrl_1_active && ctrl_data_p->ctrl_2_active) { |
board_state_p->cube_mode = BOARD_MODE_TRON; |
Reset_Board(); |
Reset_Board(BOARD_MODE_TRON); |
} |
} |
|
136,4 → 131,15 |
void Controller_Set_Leds(uint8_t ctrl_1, uint8_t ctrl_2) { |
ctrl_data_p->ctrl_1_leds = ctrl_1; |
ctrl_data_p->ctrl_2_leds = ctrl_2; |
} |
|
uint8_t Controller_Query(void) { |
// Returns the active status of attached controllers |
if (ctrl_data_p->ctrl_1_active && ctrl_data_p->ctrl_2_active) |
return 0x3; |
else if (ctrl_data_p->ctrl_1_active) |
return 0x1; |
else if (ctrl_data_p->ctrl_2_active) |
return 0x2; |
return 0; |
} |