summaryrefslogtreecommitdiff
path: root/firmware/blinkyfications.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/blinkyfications.cpp')
-rw-r--r--firmware/blinkyfications.cpp46
1 files changed, 38 insertions, 8 deletions
diff --git a/firmware/blinkyfications.cpp b/firmware/blinkyfications.cpp
index 1fc1e84..ffb4654 100644
--- a/firmware/blinkyfications.cpp
+++ b/firmware/blinkyfications.cpp
@@ -26,7 +26,6 @@
#include <stdio.h>
#include "util.h"
-#include "led.h"
#include "usbio.h"
#include "Arduino.h"
@@ -36,6 +35,8 @@
#define NUM_LEDS 8
#define DATA_PIN 1 // PB1 @ Atmega32U2
+#define _10MS_ ((uint16_t)625) // 10ms @ 16MHz / Prescaler 1:256
+
CRGB leds[NUM_LEDS];
void fastled_init()
@@ -44,16 +45,45 @@ void fastled_init()
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}
+void timer_init()
+{
+ TCCR1A = 0;
+ TCCR1B = 0;
+ TCCR1C = 0;
+
+ OCR1A = 0xFFFF;
+ TCNT1 = 0;
+ TIMSK1 = (1 << OCIE1A);
+}
+
+void timer_start(uint16_t timeout)
+{
+ OCR1A = timeout;
+ TCNT1 = 0;
+ TCCR1B = (1 << CS12);
+}
+
+ISR(TIMER1_COMPA_vect)
+{
+ TCCR1B = 0;
+ fill_solid(leds, NUM_LEDS, CRGB::Black);
+ FastLED.show();
+}
void handle_cmd(uint8_t cmd)
{
switch(cmd) {
- case '0': fill_solid(leds, NUM_LEDS, CRGB::Black); FastLED.show(); led_off(); break;
- case '1': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); led_on(); break;
- case 'r': fill_solid(leds, NUM_LEDS, CRGB::Red); FastLED.show(); led_on(); break;
- case 'g': fill_solid(leds, NUM_LEDS, CRGB::Green); FastLED.show(); led_on(); break;
- case 'b': fill_solid(leds, NUM_LEDS, CRGB::Blue); FastLED.show(); led_on(); break;
- case 'w': fill_rainbow(leds, NUM_LEDS, 0, 256/NUM_LEDS); FastLED.show(); led_on(); break;
+ case '0': fill_solid(leds, NUM_LEDS, CRGB::Black); FastLED.show(); break;
+ case '1': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); break;
+ case 'r': fill_solid(leds, NUM_LEDS, CRGB::Red); FastLED.show(); break;
+ case 'g': fill_solid(leds, NUM_LEDS, CRGB::Green); FastLED.show(); break;
+ case 'b': fill_solid(leds, NUM_LEDS, CRGB::Blue); FastLED.show(); break;
+ case 'w': fill_rainbow(leds, NUM_LEDS, 0, 256/NUM_LEDS); FastLED.show(); break;
+
+ case '.': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); timer_start(10 * _10MS_); break;
+ case 'o': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); timer_start(30 * _10MS_); break;
+ case 'O': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); timer_start(100 * _10MS_); break;
+
case '!': reset2bootloader(); break;
default: printf("error\r\n"); return;
}
@@ -66,11 +96,11 @@ int main(void)
wdt_disable();
cpu_init();
- led_init();
usbio_init();
fastled_init();
sei();
+ timer_init();
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
for(;;) {