bluetooth

Dependents:   newlib

Fork of btbee by Nikolas Goldin

Committer:
ngoldin
Date:
Thu May 16 14:01:24 2013 +0000
Revision:
2:12c38a710982
Parent:
1:56f437e4d9e0
Child:
3:6d8cebc874fb
added default and at baud commands

Who changed what in which revision?

UserRevisionLine numberNew 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 2:12c38a710982 6 reset_out.write(1);
ngoldin 2:12c38a710982 7 baud(DEFAULT_BAUD);
ngoldin 0:e7cb710c8900 8 }
ngoldin 0:e7cb710c8900 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 }
ngoldin 0:e7cb710c8900 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 }
ngoldin 0:e7cb710c8900 22
ngoldin 2:12c38a710982 23 void btbee::at_baud(void){
ngoldin 2:12c38a710982 24 baud(AT_BAUD);
ngoldin 2:12c38a710982 25 }
ngoldin 2:12c38a710982 26
ngoldin 2:12c38a710982 27 void btbee::factory_baud(void){
ngoldin 2:12c38a710982 28 baud(FACTORY_BAUD);
ngoldin 2:12c38a710982 29 }
ngoldin 2:12c38a710982 30
ngoldin 2:12c38a710982 31 void btbee::default_baud(void){
ngoldin 2:12c38a710982 32 baud(DEFAULT_BAUD);
ngoldin 2:12c38a710982 33 }
ngoldin 1:56f437e4d9e0 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 }
ngoldin 1:56f437e4d9e0 51