The unified diff between revisions [cc8258a6..] and [23a3e9a5..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'main.c'

#
# old_revision [cc8258a6c3643514892e84cf24fed008bc6f9660]
# new_revision [23a3e9a50b4034343e3bd217d2c225dcaec064dd]
#
# patch "main.c"
#  from [0a896cdc054a7e9fc0211de74469c22eef83a867]
#    to [e1a823b4962f3e8dc43b519a1f57745854ae6689]
#
============================================================
--- main.c	0a896cdc054a7e9fc0211de74469c22eef83a867
+++ main.c	e1a823b4962f3e8dc43b519a1f57745854ae6689
@@ -4,6 +4,7 @@
 #include "timer.h"
 #include "uart.h"
 #include "interrupt.h"
+#include "event.h"
 
 #define PINSEL0 (*((volatile unsigned char *) 0xE002C000))
 #define FP0XDIR (*((volatile unsigned int *) 0x3FFFC000))
@@ -158,20 +159,44 @@ void average_sample(void)
 	putstr(")\r\n");
 }
 
-int main(void) {
-	int i;
+void timer_event_handler(void)
+{
+	wmp_start_sample();
+}
 
+void menu_handler(void);
+
+int main(void) {
 	init_interrupt();
 	init_uart();
 	init_i2c();
 	init_pins();
 	init_timer();
+
+	event_register(EVENT_UART_INPUT, menu_handler);
+
+	event_register(EVENT_I2C_COMPLETE, wmp_event_handler);
+
+	event_register(EVENT_TIMER, timer_event_handler);
+
 	putstr("Your entire life has been a mathematical error... a mathematical error I'm about to correct!\r\n");
 
+	putstr("prompt> ");
+
 	while (1) {
-		char c;
-		putstr("prompt> ");
-		c = getch();
+		FP0XVAL ^= 0x04000000;
+		event_dispatch();
+	}
+
+	return 0;
+}
+
+void menu_handler(void)
+{
+	int i;
+	char c;
+
+	while (getch(&c)) {
 		if (c == 0x0a)
 			continue;
 		putch(c);
@@ -252,14 +277,16 @@ int main(void) {
 			break;
 		case 'P':
 			putstr("Initialising timer... ");
-			timer_set_period(10000*TIMER_MS);
+			/* We want a 100Hz loop but two samples per iteration.
+			 * So, we go for 200Hz. */
+			timer_set_period(5*TIMER_MS);
 			reply("done");
+			wmp_start_zero();
 			break;
 		default:
 			reply("Unrecognised command.");
 			break;
 		}
+		putstr("prompt> ");
 	}
-
-	return 0;
 }