From 2730c69f59c5ae103bf06eae8d1c910e7eb872ef Mon Sep 17 00:00:00 2001 From: Thammi Date: Wed, 4 Sep 2013 01:52:32 +0200 Subject: [PATCH] Add geiger app --- firmware/apps/buggy.c | 4 +-- firmware/apps/geiger.c | 60 ++++++++++++++++++++++++++++++++++++++++++ firmware/lib/hal.c | 2 +- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 firmware/apps/geiger.c diff --git a/firmware/apps/buggy.c b/firmware/apps/buggy.c index aa2b348..d242274 100644 --- a/firmware/apps/buggy.c +++ b/firmware/apps/buggy.c @@ -16,11 +16,11 @@ static void init(void) { } static void run(void) { - uint16_t light = photons_measure(); + uint8_t light = photons_measure(); pentatonic_all_led_set(light >> 3); - motor_set(biased_random(light) > 0x50 ? ON : OFF); + motor_set(biased_random(light) > 0x50); led_set(RIGHT, biased_random(light) > 0x20); led_set(LEFT, biased_random(light) > 0x20); diff --git a/firmware/apps/geiger.c b/firmware/apps/geiger.c new file mode 100644 index 0000000..00ad1fa --- /dev/null +++ b/firmware/apps/geiger.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +inline uint16_t biased_random(uint8_t value) { + return value / 4 * (rand() & 7); +} + +enum modes { + GEIGER, + TWITCH, + MAX_MODE, +}; + +static void init(void) { + photons_init(); +} + +static enum modes mode = 0; + +static void run(void) { + uint8_t light = photons_measure(); + + if(button_clicked(RIGHT)) { + ++mode; + + if(mode == MAX_MODE) { + mode = 0; + } + } + + if(button_clicked(LEFT)) { + if(mode == 0) { + mode = MAX_MODE; + } + + --mode; + } + + switch(mode) { + case GEIGER: + if(light / 16 * (rand() & 15) > 0x40) { + set_note(NOTE_C, 3); + } else { + stop_note(); + } + + wait_ms(20); + break; + case TWITCH: + set_note(500 + light, 0); + wait_ms(10); + break; + case MAX_MODE: + break; + } +} + +REGISTER(run, init, NULL); diff --git a/firmware/lib/hal.c b/firmware/lib/hal.c index 15befcf..91899b4 100644 --- a/firmware/lib/hal.c +++ b/firmware/lib/hal.c @@ -8,7 +8,7 @@ #include static volatile uint8_t ir_active = 0; -static int int_skip = 0; +static uint16_t int_skip = 0; static volatile int16_t wait_time = 0; static uint16_t button_count[2];