small library for the ble setup

Dependents:   robot

Committer:
ece4180fl16
Date:
Fri Nov 04 15:51:32 2016 +0000
Revision:
0:36eed245dcee
add ble

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ece4180fl16 0:36eed245dcee 1 //state used to remember previous characters read in a button message
ece4180fl16 0:36eed245dcee 2 //global variables for main and interrupt routine
ece4180fl16 0:36eed245dcee 3 #include "mbed.h"
ece4180fl16 0:36eed245dcee 4 volatile bool button_ready = 0;
ece4180fl16 0:36eed245dcee 5 volatile int bnum = 0;
ece4180fl16 0:36eed245dcee 6 volatile int bhit ;
ece4180fl16 0:36eed245dcee 7 Serial Blue(p28,p27);
ece4180fl16 0:36eed245dcee 8 enum statetype {start = 0, got_exclm, got_B, got_num, got_hit};
ece4180fl16 0:36eed245dcee 9 statetype state = start;
ece4180fl16 0:36eed245dcee 10 void parse_message()
ece4180fl16 0:36eed245dcee 11 {
ece4180fl16 0:36eed245dcee 12 switch (state) {
ece4180fl16 0:36eed245dcee 13 case start:
ece4180fl16 0:36eed245dcee 14 if (Blue.getc()=='!') state = got_exclm;
ece4180fl16 0:36eed245dcee 15 else state = start;
ece4180fl16 0:36eed245dcee 16 break;
ece4180fl16 0:36eed245dcee 17 case got_exclm:
ece4180fl16 0:36eed245dcee 18 if (Blue.getc() == 'B') state = got_B;
ece4180fl16 0:36eed245dcee 19 else state = start;
ece4180fl16 0:36eed245dcee 20 break;
ece4180fl16 0:36eed245dcee 21 case got_B:
ece4180fl16 0:36eed245dcee 22 bnum = Blue.getc();
ece4180fl16 0:36eed245dcee 23 state = got_num;
ece4180fl16 0:36eed245dcee 24 break;
ece4180fl16 0:36eed245dcee 25 case got_num:
ece4180fl16 0:36eed245dcee 26 bhit = Blue.getc();
ece4180fl16 0:36eed245dcee 27 state = got_hit;
ece4180fl16 0:36eed245dcee 28 break;
ece4180fl16 0:36eed245dcee 29 case got_hit:
ece4180fl16 0:36eed245dcee 30 if (Blue.getc() == char(~('!' + ' B' + bnum + bhit))) button_ready = 1;
ece4180fl16 0:36eed245dcee 31 state = start;
ece4180fl16 0:36eed245dcee 32 break;
ece4180fl16 0:36eed245dcee 33 default:
ece4180fl16 0:36eed245dcee 34 Blue.getc();
ece4180fl16 0:36eed245dcee 35 state = start;
ece4180fl16 0:36eed245dcee 36 }
ece4180fl16 0:36eed245dcee 37 }