This commit is contained in:
2026-05-10 16:35:21 -06:00
parent c473d4906e
commit 9dad0f9390
6 changed files with 182 additions and 179 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
[*.c] [*.c]
indent_style = tab indent_style = space
indent_size = 2
+1 -1
View File
@@ -1,8 +1,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/io.h>
#include "i2c.h" #include "i2c.h"
+20 -18
View File
@@ -1,11 +1,11 @@
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "config.h"
#include "as1115.h" #include "as1115.h"
#include "config.h"
#include "i2c.h" #include "i2c.h"
#if MAIN_TIME > 5999000 #if MAIN_TIME > 5999000
@@ -17,11 +17,7 @@
volatile uint32_t ms_since_boot = 0; volatile uint32_t ms_since_boot = 0;
typedef enum { typedef enum { STOPPED, PLAYER_A, PLAYER_B } state_type;
STOPPED,
PLAYER_A,
PLAYER_B
} state_type;
volatile state_type state = STOPPED; volatile state_type state = STOPPED;
@@ -31,16 +27,21 @@ volatile uint32_t move_started_at = MAIN_TIME;
volatile uint32_t finished_at = 0; volatile uint32_t finished_at = 0;
ISR(TIM1_COMPA_vect) ISR(TIM1_COMPA_vect) {
{
ms_since_boot++; ms_since_boot++;
if (state == PLAYER_A) { if (state == PLAYER_A) {
player_a_timer--; player_a_timer--;
if(player_a_timer == 0) { state = STOPPED; finished_at = ms_since_boot; } if (player_a_timer == 0) {
state = STOPPED;
finished_at = ms_since_boot;
}
} else if (state == PLAYER_B) { } else if (state == PLAYER_B) {
player_b_timer--; player_b_timer--;
if(player_b_timer == 0) { state = STOPPED; finished_at = ms_since_boot; } if (player_b_timer == 0) {
state = STOPPED;
finished_at = ms_since_boot;
}
} }
} }
@@ -61,9 +62,7 @@ void setup_clock(void) {
TIMSK1 = 0x02; TIMSK1 = 0x02;
} }
bool button_pressed(uint8_t pin) { bool button_pressed(uint8_t pin) { return (PINA & (1 << pin)) == 0; }
return (PINA & (1 << pin)) == 0;
}
#define DISPLAY_LEFT 0 #define DISPLAY_LEFT 0
#define DISPLAY_RIGHT 1 #define DISPLAY_RIGHT 1
@@ -172,20 +171,23 @@ int main() {
render_timer(player_b_timer, DISPLAY_RIGHT); render_timer(player_b_timer, DISPLAY_RIGHT);
cli(); cli();
if(button_pressed(PLAYER_A_BUTTON) && state != PLAYER_B && player_b_timer != 0 && player_a_timer != 0) { if (button_pressed(PLAYER_A_BUTTON) && state != PLAYER_B &&
player_b_timer != 0 && player_a_timer != 0) {
player_a_timer += get_increment(player_a_timer); player_a_timer += get_increment(player_a_timer);
state = PLAYER_B; state = PLAYER_B;
move_started_at = player_b_timer; move_started_at = player_b_timer;
} }
if(button_pressed(PLAYER_B_BUTTON) && state != PLAYER_A && player_b_timer != 0 && player_a_timer != 0) { if (button_pressed(PLAYER_B_BUTTON) && state != PLAYER_A &&
player_b_timer != 0 && player_a_timer != 0) {
player_b_timer += get_increment(player_b_timer); player_b_timer += get_increment(player_b_timer);
state = PLAYER_A; state = PLAYER_A;
move_started_at = player_a_timer; move_started_at = player_a_timer;
} }
sei(); sei();
if (state == STOPPED && (player_a_timer == 0 || player_b_timer == 0) && (ms_since_boot > finished_at + RESET_DELAY)) { if (state == STOPPED && (player_a_timer == 0 || player_b_timer == 0) &&
(ms_since_boot > finished_at + RESET_DELAY)) {
reset(); reset();
} }
} }