Permalink
Browse files

simplify led blink patterns, add larson scanner mode

  • Loading branch information...
phooky committed Feb 25, 2014
1 parent d80c641 commit 5effa087a011bb9d600e97c1368a1f4396e47f8d
Showing with 28 additions and 17 deletions.
  1. +10 −10 code/SnapPadv1/leds.c
  2. +18 −7 code/SnapPadv1/leds.h
View
@@ -41,20 +41,16 @@ void leds_init() {
TA0CTL |= TACLR; // Clear and restart clock
}
-
-bool is_on(uint8_t mode, uint8_t phase) {
- if (mode == LED_ON) return true;
- if (mode == LED_FAST_0) return (phase & 1) == 0;
- if (mode == LED_FAST_1) return (phase & 1) != 0;
- if (mode == LED_SLOW_0) return (phase & 4) == 0;
- if (mode == LED_SLOW_1) return (phase & 4) != 0;
- return false;
-}
-
void leds_set_led(uint8_t led, uint8_t mode) {
led_mode[led] = mode;
}
+void leds_set_larson() {
+ led_mode[0] = 0x81;
+ led_mode[1] = 0x42;
+ led_mode[2] = 0x24;
+ led_mode[3] = 0x18;
+}
/**
* Turn on and off the four LEDs.
@@ -84,6 +80,10 @@ void wait_for_confirm() {
while (has_confirm());
}
+inline bool is_on(uint8_t mode, uint8_t phase) {
+ return (mode & phase) != 0;
+}
+
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0 (void) {
phase = (phase + 1) % 8;
View
@@ -11,7 +11,10 @@
#include <stdint.h>
#include <stdbool.h>
-/// A bit of a misnomer: LEDs and buttons, really.
+/***
+ * Calls to handle LED display modes and button presses.
+ */
+
/**
* Initialize LED pins and switch
*/
@@ -27,20 +30,28 @@ void leds_set(uint8_t leds);
enum {
LED_OFF = 0,
- LED_ON = 1,
- LED_SLOW_0 = 2,
- LED_SLOW_1 = 3,
- LED_FAST_0 = 4,
- LED_FAST_1 = 5
+ LED_ON = 0xff,
+ LED_SLOW_0 = 0x0f,
+ LED_SLOW_1 = 0xf0,
+ LED_FAST_0 = 0x33,
+ LED_FAST_1 = 0xcc,
+ LED_HYPER_0 = 0x55,
+ LED_HYPER_1 = 0xaa
};
+
/**
* Set the high-level behavior of each led.
* @param led the index of the LED to set (0-3).
- * @param mode the blink mode to use, or 0 to turn off.
+ * @param mode a bitfield representing the phases that the LED should be lit for.
*/
void leds_set_led(uint8_t led, uint8_t mode);
+/**
+ * Convenience method to set Larson scanner mode.
+ */
+void leds_set_larson();
+
/**
* Detect whether the CONFIRM button is currently being held down.
* @return true if CONFIRM is depressed.

0 comments on commit 5effa08

Please sign in to comment.