small library for the ble setup

Dependents:   robot

Files at this revision

API Documentation at this revision

Comitter:
ece4180fl16
Date:
Fri Nov 04 15:51:32 2016 +0000
Commit message:
add ble

Changed in this revision

ble.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ble.h	Fri Nov 04 15:51:32 2016 +0000
@@ -0,0 +1,37 @@
+//state used to remember previous characters read in a button message
+//global variables for main and interrupt routine
+#include "mbed.h"
+volatile bool button_ready = 0;
+volatile int  bnum = 0;
+volatile int  bhit  ;
+Serial Blue(p28,p27);
+enum statetype {start = 0, got_exclm, got_B, got_num, got_hit};
+statetype state = start;
+void parse_message()
+{
+    switch (state) {
+        case start:
+            if (Blue.getc()=='!') state = got_exclm;
+            else state = start;
+            break;
+        case got_exclm:
+            if (Blue.getc() == 'B') state = got_B;
+            else state = start;
+            break;
+        case got_B:
+            bnum = Blue.getc();
+            state = got_num;
+            break;
+        case got_num:
+            bhit = Blue.getc();
+            state = got_hit;
+            break;
+        case got_hit:
+            if (Blue.getc() == char(~('!' + ' B' + bnum + bhit))) button_ready = 1;
+            state = start;
+            break;
+        default:
+            Blue.getc();
+            state = start;
+    }
+}
\ No newline at end of file