Commits

Trammell Hudson committed 3dcdac0 Draft

add a demo mode

Comments (0)

Files changed (1)

 }
 
 
+static void
+demo_mode(void)
+{
+	if (bit_is_clear(TIFR1, TOV1))
+		return;
+
+	sbi(TIFR1, TOV1);
+	static uint32_t val = 0;
+
+	//OCR1B = OCR1C = 0x3FF; // (val >> 8) & 0x3FF;
+#define FLASH_MASK (1ul << FLASH_BITS)
+#define FLASH_BITS 12
+
+	if ((val & FLASH_MASK) == 0)
+	{
+		uint8_t v = (val >> FLASH_BITS) & 0x7;
+
+		if (v & 4) // blue
+			OCR1A = 0x3FF;
+		else
+			OCR1A = 0x300;
+		if (v & 2) // green
+			OCR1B = 0x3FF;
+		else
+			OCR1B = 0x200;
+		if (v & 1) // red
+			OCR1C = 0x3FF;
+		else
+			OCR1C = 0x100;
+	}
+		
+	if (val == 0)
+		val = 0x280ul << 10;
+	else
+		val = val - 1;
+	
+	OCR3A = (val >> 10) & 0x3FF;
+}
+
+
 int main(void)
 {
 	// set for 16 MHz clock
 	// without a PC connected to the USB port, this 
 	// will wait forever.
 	usb_init();
-	while (!usb_configured()) /* wait */ ;
-	_delay_ms(1000);
-
-	// wait for the user to run their terminal emulator program
-	// which sets DTR to indicate it is ready to receive.
-	while (!(usb_serial_get_control() & USB_SERIAL_DTR))
-		continue;
-
-	// discard anything that was received prior.  Sometimes the
-	// operating system or other software will send a modem
-	// "AT command", which can still be buffered.
-	usb_serial_flush_input();
-
 #define GAUGE1 0xC6
 
 	// OC1A, OC1B and OC1C are used for the RGB LED
 	OCR3A = 255;
 	uint16_t val = 0;
 
+	// F7 is used for the switch input in pull-down mode
+	ddr(0xF7, 0);
+	out(0xF7, 1);
+
+	while (!usb_configured()) {
+		demo_mode();
+	}
+
+	_delay_ms(1000);
+
+	// wait for the user to run their terminal emulator program
+	// which sets DTR to indicate it is ready to receive.
+	while (!(usb_serial_get_control() & USB_SERIAL_DTR))
+	{
+		demo_mode();
+	}
+
+	// discard anything that was received prior.  Sometimes the
+	// operating system or other software will send a modem
+	// "AT command", which can still be buffered.
+	usb_serial_flush_input();
+
 	send_str(PSTR("badass gauge\r\n"));
 	while (1)
 	{
 		int c = usb_serial_getchar();
+
+		if (in(0xF7) == 0)
+		{
+			demo_mode();
+			continue;
+		}
+
 		if (c == -1)
 			continue;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.