finish up tetris and fix step1

This commit is contained in:
2024-08-10 14:19:04 -05:00
parent a0de2ccd04
commit e75e7465fb
10 changed files with 215 additions and 91 deletions
+12 -4
View File
@@ -31,7 +31,9 @@ static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
for (int i = 0; i < 16; i++) {
int bit_selector = (1 << i);
if ((*keypad_bitfield) & bit_selector) {
*kp = (KeypadKey) i;
if (kp != nullptr) {
*kp = (KeypadKey) i;
}
// clear bit
*keypad_bitfield &= ~bit_selector;
return true;
@@ -90,7 +92,9 @@ static bool _take_button(ButtonKey* button, uint16_t* button_bitfield) {
for (int i = 0; i < 4; i++) {
int bit_selector = (1 << (i+8));
if ((*button_bitfield) & bit_selector) {
*button = (ButtonKey) i;
if (button != nullptr) {
*button = (ButtonKey) i;
}
// clear bit
*button_bitfield &= ~bit_selector;
return true;
@@ -102,7 +106,9 @@ static bool _take_switch(SwitchKey* switch_, uint16_t* button_bitfield) {
for (int i = 0; i < 4; i++) {
int bit_selector = (1 << i);
if ((*button_bitfield) & bit_selector) {
*switch_ = (SwitchKey) i;
if (switch_ != nullptr) {
*switch_ = (SwitchKey) i;
}
// clear bit
*button_bitfield &= ~bit_selector;
return true;
@@ -132,7 +138,9 @@ bool get_flipped_switch(SwitchKey* switch_) {
for (int i = 0; i < 4; i++) {
int bit_selector = (1 << (i+4));
if (button_pressed & bit_selector || button_released & bit_selector) {
*switch_ = (SwitchKey) i;
if (switch_ != nullptr) {
*switch_ = (SwitchKey) i;
}
// clear bit
button_pressed &= ~bit_selector;
button_released &= ~bit_selector;
+14 -2
View File
@@ -58,11 +58,23 @@ static void game_timer_task(void *arg)
vTaskDelayUntil( &lastWakeTime, pdMS_TO_TICKS(frequency));
if (is_game_playing) {
game_time_left = sat_sub(game_time_left, frequency);
set_game_sseg_num(game_time_left / 100, 1);
if (game_time_left > 60'000) {
int disp_time = (game_time_left / 60'000) * 100;
disp_time = disp_time + ((game_time_left % 60'000) / 1'000);
set_game_sseg_num(disp_time, 2);
} else {
set_game_sseg_num(game_time_left / 100, 1);
}
}
if (is_module_playing) {
module_time_left = sat_sub(module_time_left, frequency);
set_module_sseg_num(module_time_left / 100, 1);
if (module_time_left > 60'000) {
int disp_time = (module_time_left / 60'000) * 100;
disp_time = disp_time + ((module_time_left % 60'000) / 1'000);
set_module_sseg_num(disp_time, 2);
} else {
set_module_sseg_num(module_time_left / 100, 1);
}
}
}