Minimale Veränderungen in Btbee; Die Datenübertragung funktioniert nicht hunderprozentig, v.a. wenn mehrere Bytes übertragen werden.
Fork of btbee by
btbee.cpp@1:56f437e4d9e0, 2013-05-16 (annotated)
- Committer:
- ngoldin
- Date:
- Thu May 16 12:09:30 2013 +0000
- Revision:
- 1:56f437e4d9e0
- Parent:
- 0:e7cb710c8900
- Child:
- 2:12c38a710982
fixed;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ngoldin | 0:e7cb710c8900 | 1 | #include "btbee.h" |
ngoldin | 0:e7cb710c8900 | 2 | |
ngoldin | 0:e7cb710c8900 | 3 | btbee::btbee(PinName respin, PinName tx, PinName rx) : |
ngoldin | 0:e7cb710c8900 | 4 | Serial(tx, rx) , reset_out(respin) |
ngoldin | 0:e7cb710c8900 | 5 | { |
ngoldin | 0:e7cb710c8900 | 6 | reset_out.write(1); |
ngoldin | 0:e7cb710c8900 | 7 | } |
ngoldin | 0:e7cb710c8900 | 8 | |
ngoldin | 0:e7cb710c8900 | 9 | btbee::btbee( ) : |
ngoldin | 0:e7cb710c8900 | 10 | Serial(p28,p27), reset_out(p26) |
ngoldin | 0:e7cb710c8900 | 11 | { |
ngoldin | 0:e7cb710c8900 | 12 | reset_out.write(1); |
ngoldin | 0:e7cb710c8900 | 13 | } |
ngoldin | 0:e7cb710c8900 | 14 | |
ngoldin | 0:e7cb710c8900 | 15 | void btbee::reset(void){ |
ngoldin | 0:e7cb710c8900 | 16 | reset_out.write(0); |
ngoldin | 0:e7cb710c8900 | 17 | wait(0.01); |
ngoldin | 0:e7cb710c8900 | 18 | reset_out.write(1); |
ngoldin | 0:e7cb710c8900 | 19 | } |
ngoldin | 0:e7cb710c8900 | 20 | |
ngoldin | 1:56f437e4d9e0 | 21 | |
ngoldin | 1:56f437e4d9e0 | 22 | /* Read from the serial as long as it is readable. |
ngoldin | 1:56f437e4d9e0 | 23 | * Params: pointer to char array for the return, |
ngoldin | 1:56f437e4d9e0 | 24 | * int containing the length of the char array |
ngoldin | 1:56f437e4d9e0 | 25 | * pointer to int for return of chars read |
ngoldin | 1:56f437e4d9e0 | 26 | * Return: 1 if ok, 0 if array full but more there to read |
ngoldin | 1:56f437e4d9e0 | 27 | */ |
ngoldin | 1:56f437e4d9e0 | 28 | int btbee::read_all(char * arr, const int len, int * chars_read){ |
ngoldin | 1:56f437e4d9e0 | 29 | int pos=0; |
ngoldin | 1:56f437e4d9e0 | 30 | while (readable()){ |
ngoldin | 1:56f437e4d9e0 | 31 | if (pos==len){return 0;} |
ngoldin | 1:56f437e4d9e0 | 32 | arr[pos]=getc(); |
ngoldin | 1:56f437e4d9e0 | 33 | pos++; |
ngoldin | 1:56f437e4d9e0 | 34 | *chars_read = pos; |
ngoldin | 1:56f437e4d9e0 | 35 | } |
ngoldin | 1:56f437e4d9e0 | 36 | return 1; |
ngoldin | 1:56f437e4d9e0 | 37 | } |
ngoldin | 1:56f437e4d9e0 | 38 |