bluetooth
Fork of btbee by
btbee.cpp@3:6d8cebc874fb, 2013-05-17 (annotated)
- Committer:
- jomkippur
- Date:
- Fri May 17 11:14:20 2013 +0000
- Revision:
- 3:6d8cebc874fb
- Parent:
- 2:12c38a710982
whatever
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 | |
jomkippur | 3:6d8cebc874fb | 3 | |
jomkippur | 3:6d8cebc874fb | 4 | // declaration in btbee.h, changing the the class btbee |
jomkippur | 3:6d8cebc874fb | 5 | // from here with btbee:: ... |
jomkippur | 3:6d8cebc874fb | 6 | |
jomkippur | 3:6d8cebc874fb | 7 | // public member functions?? |
jomkippur | 3:6d8cebc874fb | 8 | // inherits mbed::Stream?? |
jomkippur | 3:6d8cebc874fb | 9 | |
jomkippur | 3:6d8cebc874fb | 10 | |
ngoldin | 0:e7cb710c8900 | 11 | btbee::btbee(PinName respin, PinName tx, PinName rx) : |
ngoldin | 0:e7cb710c8900 | 12 | Serial(tx, rx) , reset_out(respin) |
ngoldin | 0:e7cb710c8900 | 13 | { |
ngoldin | 2:12c38a710982 | 14 | reset_out.write(1); |
ngoldin | 2:12c38a710982 | 15 | baud(DEFAULT_BAUD); |
jomkippur | 3:6d8cebc874fb | 16 | //baud in Serial class, |
jomkippur | 3:6d8cebc874fb | 17 | // set the baud rate of the serial port?? |
jomkippur | 3:6d8cebc874fb | 18 | |
ngoldin | 0:e7cb710c8900 | 19 | } |
ngoldin | 0:e7cb710c8900 | 20 | |
ngoldin | 0:e7cb710c8900 | 21 | btbee::btbee( ) : |
ngoldin | 0:e7cb710c8900 | 22 | Serial(p28,p27), reset_out(p26) |
ngoldin | 0:e7cb710c8900 | 23 | { |
ngoldin | 0:e7cb710c8900 | 24 | reset_out.write(1); |
ngoldin | 2:12c38a710982 | 25 | baud(DEFAULT_BAUD); |
ngoldin | 0:e7cb710c8900 | 26 | } |
ngoldin | 0:e7cb710c8900 | 27 | |
ngoldin | 0:e7cb710c8900 | 28 | void btbee::reset(void){ |
ngoldin | 0:e7cb710c8900 | 29 | reset_out.write(0); |
ngoldin | 0:e7cb710c8900 | 30 | wait(0.01); |
ngoldin | 0:e7cb710c8900 | 31 | reset_out.write(1); |
ngoldin | 0:e7cb710c8900 | 32 | } |
ngoldin | 0:e7cb710c8900 | 33 | |
ngoldin | 2:12c38a710982 | 34 | void btbee::at_baud(void){ |
ngoldin | 2:12c38a710982 | 35 | baud(AT_BAUD); |
ngoldin | 2:12c38a710982 | 36 | } |
ngoldin | 2:12c38a710982 | 37 | |
ngoldin | 2:12c38a710982 | 38 | void btbee::factory_baud(void){ |
ngoldin | 2:12c38a710982 | 39 | baud(FACTORY_BAUD); |
ngoldin | 2:12c38a710982 | 40 | } |
ngoldin | 2:12c38a710982 | 41 | |
ngoldin | 2:12c38a710982 | 42 | void btbee::default_baud(void){ |
ngoldin | 2:12c38a710982 | 43 | baud(DEFAULT_BAUD); |
ngoldin | 2:12c38a710982 | 44 | } |
ngoldin | 1:56f437e4d9e0 | 45 | |
ngoldin | 1:56f437e4d9e0 | 46 | /* Read from the serial as long as it is readable. |
ngoldin | 1:56f437e4d9e0 | 47 | * Params: pointer to char array for the return, |
ngoldin | 1:56f437e4d9e0 | 48 | * int containing the length of the char array |
ngoldin | 1:56f437e4d9e0 | 49 | * pointer to int for return of chars read |
ngoldin | 1:56f437e4d9e0 | 50 | * Return: 1 if ok, 0 if array full but more there to read |
ngoldin | 1:56f437e4d9e0 | 51 | */ |
ngoldin | 1:56f437e4d9e0 | 52 | int btbee::read_all(char * arr, const int len, int * chars_read){ |
ngoldin | 1:56f437e4d9e0 | 53 | int pos=0; |
ngoldin | 1:56f437e4d9e0 | 54 | while (readable()){ |
ngoldin | 1:56f437e4d9e0 | 55 | if (pos==len){return 0;} |
ngoldin | 1:56f437e4d9e0 | 56 | arr[pos]=getc(); |
ngoldin | 1:56f437e4d9e0 | 57 | pos++; |
ngoldin | 1:56f437e4d9e0 | 58 | *chars_read = pos; |
ngoldin | 1:56f437e4d9e0 | 59 | } |
ngoldin | 1:56f437e4d9e0 | 60 | return 1; |
ngoldin | 1:56f437e4d9e0 | 61 | } |
ngoldin | 1:56f437e4d9e0 | 62 |