Commits

Trammell Hudson committed ccc85ad

Commands for hexascroller integration

  • Participants
  • Parent commits 7425d39

Comments (0)

Files changed (1)

 
 #include <avr/io.h>
 #include <avr/pgmspace.h>
+#include <avr/interrupt.h>
 #include <util/delay.h>
+#include <string.h>
 #include "usb_debug_only.h"
 #include "print.h"
 
 		send_zero();
 }
 
+
 static uint8_t pixels[NUM_LEDS][3];
 
 static void send_pixels(void)
 }
 
 
+static volatile uint8_t do_change;
+static volatile uint8_t pattern;
+
+
 static void fade_pixels(
 	uint8_t r,
 	uint8_t g,
 
 			send_pixels();
 			_delay_ms(500);
+
+			if (do_change)
+				return;
 		}
 	}
 }
 		send_pixels();
 		fade_pixels(0, 0, 0);
 		_delay_ms(30);
+
+		if (cycle & 1)
+			LED_OFF;
+		else
+			LED_ON;
+
+		if (do_change)
+			return;
 	}
 }
 
 }
 
 
+/******************
+ * Attention getting flash.
+ */
+static void pattern_flash(void)
+{
+	uint8_t i;
+	for (i = 0 ; i < 8 ; i++)
+	{
+		memset(pixels, 0, sizeof(pixels));
+		send_pixels();
+		_delay_ms(250);
+
+		memset(pixels, 0xFF, sizeof(pixels));
+		send_pixels();
+		_delay_ms(250);
+	};
+}
+
+
+typedef void (*pattern_t)(void);
+
+static const pattern_t patterns[] = {
+	pattern_flash,
+	pattern_chase,
+	pattern_fade,
+};
+
+static const uint8_t num_patterns = sizeof(patterns) / sizeof(*patterns);
+
+
+ISR(USART1_RX_vect)
+{
+	const uint8_t c = UDR1;
+	if ('0' <= c && c <= num_patterns)
+	{
+		pattern = c - '0';
+		do_change = 1;
+	}
+}
+
+
 int main(void)
 {
 	// set for 16 MHz clock, and make sure the LED is off
 	// but we care more about blinking than debug messages!
 	usb_init();
 
+	// Enable the serial port interrupts
+        // Set the port to 9600 K-baud, 1 start, 8 data, 1 parity
+        UBRR1H = 0;
+        UBRR1L = 103;
+        UCSR1B = (1 << RXEN1) | (1 << RXCIE1);
+        UCSR1C = (0 << UCSZ12) | (1 << UCSZ11) | (1 << UCSZ10);
+
+
 	LED_ON;
 
 	DDRB |= 1 << 2;
 		pixels[i][0] = pixels[i][1] = pixels[i][2] = 0xFF;
 	send_pixels();
 
+	pattern = 0;
+
 	while (1)
 	{
-		pattern_chase();
-		pattern_decay();
-		pattern_fade();
+		patterns[pattern]();
+
+		if (!do_change)
+			pattern = (pattern + 1) % num_patterns;
+
+		do_change = 0;
 	}
 }