GAP based TOF Demo
Dependencies: BLE_API X_NUCLEO_6180XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
bricks/print.h@29:0f068d70c1a5, 2018-08-20 (annotated)
- Committer:
- hux
- Date:
- Mon Aug 20 16:42:06 2018 +0000
- Revision:
- 29:0f068d70c1a5
made in Shanghai
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 29:0f068d70c1a5 | 1 | // print.h - print value of a characteristic |
hux | 29:0f068d70c1a5 | 2 | // |
hux | 29:0f068d70c1a5 | 3 | // Synopsis: |
hux | 29:0f068d70c1a5 | 4 | // |
hux | 29:0f068d70c1a5 | 5 | // See also: CHARACTERISTIC, GET, SET |
hux | 29:0f068d70c1a5 | 6 | // |
hux | 29:0f068d70c1a5 | 7 | #ifndef _PRINT_H_ |
hux | 29:0f068d70c1a5 | 8 | #define _PRINT_H_ |
hux | 29:0f068d70c1a5 | 9 | |
hux | 29:0f068d70c1a5 | 10 | #include "ble/Gap.h" |
hux | 29:0f068d70c1a5 | 11 | #include "bricks/o.h" |
hux | 29:0f068d70c1a5 | 12 | #include "bricks/types.h" |
hux | 29:0f068d70c1a5 | 13 | #include "bricks/characteristic.h" |
hux | 29:0f068d70c1a5 | 14 | |
hux | 29:0f068d70c1a5 | 15 | //============================================================================== |
hux | 29:0f068d70c1a5 | 16 | // Some Callbacks |
hux | 29:0f068d70c1a5 | 17 | //============================================================================== |
hux | 29:0f068d70c1a5 | 18 | |
hux | 29:0f068d70c1a5 | 19 | inline void print(O&o, Characteristic<Buffer> &chr, const char *name) |
hux | 29:0f068d70c1a5 | 20 | { |
hux | 29:0f068d70c1a5 | 21 | Serial out(USBTX, USBRX); // serial port to PC terminal |
hux | 29:0f068d70c1a5 | 22 | |
hux | 29:0f068d70c1a5 | 23 | Buffer data; uint8_t *p = data; |
hux | 29:0f068d70c1a5 | 24 | get(o,chr,data); |
hux | 29:0f068d70c1a5 | 25 | |
hux | 29:0f068d70c1a5 | 26 | out.printf("%s: %02x-%02x-%02x-%02x-%02x-",name,(int)(p[0]),(int)(p[1]),(int)(p[2]),(int)(p[3]),(int)(p[4])); |
hux | 29:0f068d70c1a5 | 27 | out.printf("%02x-%02x-%02x-%02x-%02x\r\n",(int)(p[5]),(int)(p[6]),(int)(p[7]),(int)(p[8]),(int)(p[9])); |
hux | 29:0f068d70c1a5 | 28 | } |
hux | 29:0f068d70c1a5 | 29 | |
hux | 29:0f068d70c1a5 | 30 | inline void print(O&o, Characteristic<Bool> &chr, const char *name) |
hux | 29:0f068d70c1a5 | 31 | { |
hux | 29:0f068d70c1a5 | 32 | Serial out(USBTX, USBRX); // serial port to PC terminal |
hux | 29:0f068d70c1a5 | 33 | Bool data; |
hux | 29:0f068d70c1a5 | 34 | |
hux | 29:0f068d70c1a5 | 35 | get(o,chr,data); |
hux | 29:0f068d70c1a5 | 36 | out.printf("%s: %02x\r\n",name,(int)data); |
hux | 29:0f068d70c1a5 | 37 | } |
hux | 29:0f068d70c1a5 | 38 | |
hux | 29:0f068d70c1a5 | 39 | // we provide also some PRINT methods for non Characteristics. If the value of |
hux | 29:0f068d70c1a5 | 40 | // a characteristic needs to be printed the value must be fetched before with |
hux | 29:0f068d70c1a5 | 41 | // the GET function. |
hux | 29:0f068d70c1a5 | 42 | |
hux | 29:0f068d70c1a5 | 43 | inline void print(O&o, Bool data, const char *name) |
hux | 29:0f068d70c1a5 | 44 | { |
hux | 29:0f068d70c1a5 | 45 | Serial out(USBTX, USBRX); // serial port to PC terminal |
hux | 29:0f068d70c1a5 | 46 | out.printf("%s: %02x\r\n",(int)&data); |
hux | 29:0f068d70c1a5 | 47 | } |
hux | 29:0f068d70c1a5 | 48 | |
hux | 29:0f068d70c1a5 | 49 | #endif // _PRINT_H_ |