Minimale Veränderungen in Btbee; Die Datenübertragung funktioniert nicht hunderprozentig, v.a. wenn mehrere Bytes übertragen werden.

Fork of btbee by Nikolas Goldin

Committer:
friedrich_h
Date:
Tue Jun 28 09:23:51 2016 +0000
Revision:
6:cf8611463f79
Parent:
2:12c38a710982
C++-Code f?r die LNDW 2016;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ngoldin 0:e7cb710c8900 1 #include "btbee.h"
friedrich_h 6:cf8611463f79 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 2:12c38a710982 6 reset_out.write(1);
ngoldin 2:12c38a710982 7 baud(DEFAULT_BAUD);
ngoldin 0:e7cb710c8900 8 }
friedrich_h 6:cf8611463f79 9
ngoldin 0:e7cb710c8900 10 btbee::btbee( ) :
ngoldin 0:e7cb710c8900 11 Serial(p28,p27), reset_out(p26)
ngoldin 0:e7cb710c8900 12 {
ngoldin 0:e7cb710c8900 13 reset_out.write(1);
ngoldin 2:12c38a710982 14 baud(DEFAULT_BAUD);
ngoldin 0:e7cb710c8900 15 }
friedrich_h 6:cf8611463f79 16
ngoldin 0:e7cb710c8900 17 void btbee::reset(void){
ngoldin 0:e7cb710c8900 18 reset_out.write(0);
ngoldin 0:e7cb710c8900 19 wait(0.01);
ngoldin 0:e7cb710c8900 20 reset_out.write(1);
ngoldin 0:e7cb710c8900 21 }
friedrich_h 6:cf8611463f79 22
ngoldin 2:12c38a710982 23 void btbee::at_baud(void){
ngoldin 2:12c38a710982 24 baud(AT_BAUD);
ngoldin 2:12c38a710982 25 }
friedrich_h 6:cf8611463f79 26
ngoldin 2:12c38a710982 27 void btbee::factory_baud(void){
ngoldin 2:12c38a710982 28 baud(FACTORY_BAUD);
ngoldin 2:12c38a710982 29 }
friedrich_h 6:cf8611463f79 30
ngoldin 2:12c38a710982 31 void btbee::default_baud(void){
ngoldin 2:12c38a710982 32 baud(DEFAULT_BAUD);
ngoldin 2:12c38a710982 33 }
friedrich_h 6:cf8611463f79 34
ngoldin 1:56f437e4d9e0 35 /* Read from the serial as long as it is readable.
ngoldin 1:56f437e4d9e0 36 * Params: pointer to char array for the return,
ngoldin 1:56f437e4d9e0 37 * int containing the length of the char array
ngoldin 1:56f437e4d9e0 38 * pointer to int for return of chars read
ngoldin 1:56f437e4d9e0 39 * Return: 1 if ok, 0 if array full but more there to read
ngoldin 1:56f437e4d9e0 40 */
ngoldin 1:56f437e4d9e0 41 int btbee::read_all(char * arr, const int len, int * chars_read){
ngoldin 1:56f437e4d9e0 42 int pos=0;
ngoldin 1:56f437e4d9e0 43 while (readable()){
ngoldin 1:56f437e4d9e0 44 if (pos==len){return 0;}
ngoldin 1:56f437e4d9e0 45 arr[pos]=getc();
ngoldin 1:56f437e4d9e0 46 pos++;
ngoldin 1:56f437e4d9e0 47 *chars_read = pos;
ngoldin 1:56f437e4d9e0 48 }
ngoldin 1:56f437e4d9e0 49 return 1;
ngoldin 1:56f437e4d9e0 50 }
friedrich_h 6:cf8611463f79 51
friedrich_h 6:cf8611463f79 52 /* Read from the serial as long as no LF (\n) char has been read.
friedrich_h 6:cf8611463f79 53 * WARNING: This will block your program if no LF is received.
friedrich_h 6:cf8611463f79 54 * Params: pointer to char array for the return,
friedrich_h 6:cf8611463f79 55 * int containing the length of the char array
friedrich_h 6:cf8611463f79 56 * pointer to int for return of chars read
friedrich_h 6:cf8611463f79 57 * Return: 1 if ok, 0 if array full but more there to read
friedrich_h 6:cf8611463f79 58 */
friedrich_h 6:cf8611463f79 59 int btbee::read_line(char * arr, const int len, int * chars_read){
friedrich_h 6:cf8611463f79 60 int pos=0;
friedrich_h 6:cf8611463f79 61 do
friedrich_h 6:cf8611463f79 62 {
friedrich_h 6:cf8611463f79 63 while(!readable()){} //wait until readable
friedrich_h 6:cf8611463f79 64 if (pos==len){return 0;}
friedrich_h 6:cf8611463f79 65 arr[pos]=getc();
friedrich_h 6:cf8611463f79 66 pos++;
friedrich_h 6:cf8611463f79 67 *chars_read = pos;
friedrich_h 6:cf8611463f79 68 }
friedrich_h 6:cf8611463f79 69 while (!(arr[pos-1]=='\n'));
friedrich_h 6:cf8611463f79 70 return 1;
friedrich_h 6:cf8611463f79 71 }