Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:c3d2/PentaLight

  • Loading branch information...
commit 301323e16b7a7868dc7fb23ad09139c2fce4dcc8 2 parents d4b929f + 2b24d6d
@thammi thammi authored
Showing with 34 additions and 27 deletions.
  1. +29 −24 firmware/apps/click.c
  2. +5 −3 firmware/sim/main.c
View
53 firmware/apps/click.c
@@ -3,29 +3,40 @@
#include <stdlib.h>
#define CYCLE(x,c) ((x + c) % c)
+#define MAX(a,b) ((a) < (b) ? (b) : (a))
+#define MIN(a,b) ((a) > (b) ? (b) : (a))
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(*array))
-#define MAX_TICK 2
+#define PENALTY -1
static void init(void) ATTRIBUTES;
static uint8_t tick(void);
static void key(key_type key, event_type event);
-void draw_winner1(void);
-void draw_winner2(void);
+static void draw_flash(uint8_t b);
+static void draw_winner1(void);
+static void draw_winner2(void);
-static uint8_t ticks = 0;
-static uint8_t left_bar = 3;
-static uint8_t right_bar = 3;
-static uint8_t flash_light = 1;
+static int8_t left_bar = 0;
+static int8_t right_bar = 0;
+static uint8_t flash_light = 0;
static uint8_t winner = 0;
static uint8_t end = 0;
+static uint8_t state = 0;
void init(void) {
registerApp(tick, key, 22);
}
uint8_t tick() {
- int8_t y, c;
+ if (state == 0) {
+ state = 1;
+ left_bar = 0;
+ right_bar = 0;
+ flash_light = 0;
+ winner = 0;
+ end = 0;
+ }
+ int8_t y;
for(y = 0; y < LED_HEIGHT; y++) {
setLedXY(0, y,
y < left_bar / 7 ? 7 :
@@ -34,31 +45,25 @@ uint8_t tick() {
y < right_bar / 7 ? 7 :
y == right_bar / 7 ? right_bar % 7 : 0);
}
- if(flash_light > 0) {
- draw_flash(7);
- --flash_light;
- } else {
- draw_flash(1);
- flash_light = rand()%7;
- }
+ draw_flash(flash_light ? 7 : 1);
+ if(rand()%100 < 50 - 20*flash_light) flash_light = !flash_light;
if(winner == 1) draw_winner1();
if(winner == 2) draw_winner2();
- if(winner > 0 && --end == 0) return 1;
+ if(winner > 0 && --end == 0) {
+ state = 0;
+ return 1;
+ }
return 0;
}
void key(key_type key, event_type event) {
if(event == DOWN && end == 0) {
if(key == KEY_A) {
- right_bar += flash_light > 0 ? 1 : -2;
- if (right_bar >= LED_HEIGHT * 7) {
- winner = 1;
- }
+ right_bar = MAX(right_bar + (flash_light > 0 ? 1 : PENALTY), 0);
+ if (right_bar >= LED_HEIGHT * 7) winner = 1;
} else {
- left_bar += flash_light > 0 ? 1 : -2;
- if (left_bar >= LED_HEIGHT * 7) {
- winner = 2;
- }
+ left_bar = MAX(left_bar + (flash_light > 0 ? 1 : PENALTY), 0);
+ if (left_bar >= LED_HEIGHT * 7) winner = 2;
}
if(winner > 0) end = 10;
}
View
8 firmware/sim/main.c
@@ -28,17 +28,17 @@ void registerAnimation(tick_fun tick, uint16_t t, uint16_t ignore)
{
tick_fp = tick;
key_fp = NULL;
-
+
assert(t > 0);
// 122Hz / tick
interval = 1000000 / 122 * t;
}
-
+
void registerApp(tick_fun tick, key_fun key, uint16_t t)
{
tick_fp = tick;
key_fp = key;
-
+
assert(t > 0);
interval = 1000000 / 122 * t;
}
@@ -76,10 +76,12 @@ int main(int argc, char *argv[]) {
running = 0;
break;
+ case 'd':
case SDLK_RIGHT:
key_emit(KEY_A, ev.type);
break;
+ case 'a':
case SDLK_LEFT:
key_emit(KEY_B, ev.type);
break;
Please sign in to comment.
Something went wrong with that request. Please try again.