format
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
||||
[*.c]
|
||||
indent_style = tab
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "i2c.h"
|
||||
|
||||
|
||||
+20
-18
@@ -1,11 +1,11 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "as1115.h"
|
||||
#include "config.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#if MAIN_TIME > 5999000
|
||||
@@ -17,11 +17,7 @@
|
||||
|
||||
volatile uint32_t ms_since_boot = 0;
|
||||
|
||||
typedef enum {
|
||||
STOPPED,
|
||||
PLAYER_A,
|
||||
PLAYER_B
|
||||
} state_type;
|
||||
typedef enum { STOPPED, PLAYER_A, PLAYER_B } state_type;
|
||||
|
||||
volatile state_type state = STOPPED;
|
||||
|
||||
@@ -31,16 +27,21 @@ volatile uint32_t move_started_at = MAIN_TIME;
|
||||
|
||||
volatile uint32_t finished_at = 0;
|
||||
|
||||
ISR(TIM1_COMPA_vect)
|
||||
{
|
||||
ISR(TIM1_COMPA_vect) {
|
||||
ms_since_boot++;
|
||||
|
||||
if (state == PLAYER_A) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
bool button_pressed(uint8_t pin) {
|
||||
return (PINA & (1 << pin)) == 0;
|
||||
}
|
||||
bool button_pressed(uint8_t pin) { return (PINA & (1 << pin)) == 0; }
|
||||
|
||||
#define DISPLAY_LEFT 0
|
||||
#define DISPLAY_RIGHT 1
|
||||
@@ -172,20 +171,23 @@ int main() {
|
||||
render_timer(player_b_timer, DISPLAY_RIGHT);
|
||||
|
||||
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);
|
||||
state = PLAYER_B;
|
||||
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);
|
||||
state = PLAYER_A;
|
||||
move_started_at = player_a_timer;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user