Initial Fork

Dependencies:   CRC16

Dependents:   eBot_Firmware_V1

Fork of SWSPI by Dave Van Wagner

Committer:
Throwbot
Date:
Sun Oct 05 12:21:30 2014 +0000
Revision:
2:c13831ca234c
Parent:
1:faa9f74488ba
Bluetooth lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Throwbot 1:faa9f74488ba 1 #include "HC05.h"
Throwbot 2:c13831ca234c 2 #include <stdarg.h>
Throwbot 1:faa9f74488ba 3
Throwbot 1:faa9f74488ba 4 HC05::HC05(PinName tx_pin, PinName rx_pin, PinName en_pin):
Throwbot 2:c13831ca234c 5 MODSERIAL(tx_pin, rx_pin),
Throwbot 1:faa9f74488ba 6 on_switch(en_pin)
Throwbot 1:faa9f74488ba 7 {
Throwbot 2:c13831ca234c 8 //wait_ms(5000); //mark
Throwbot 2:c13831ca234c 9 on_switch = 0;
Throwbot 2:c13831ca234c 10 }
Throwbot 2:c13831ca234c 11 void HC05::start(){
Throwbot 1:faa9f74488ba 12 on_switch = 1;
Throwbot 1:faa9f74488ba 13 }
Throwbot 2:c13831ca234c 14 int HC05::printfCRC ( const char * format, ... ){
Throwbot 2:c13831ca234c 15
Throwbot 2:c13831ca234c 16 va_list argptr; /* Set up the variable argument list here */
Throwbot 2:c13831ca234c 17 va_start(argptr, format);
Throwbot 2:c13831ca234c 18 int ret = sprintf(buffer,format, argptr);
Throwbot 2:c13831ca234c 19 va_end(argptr); /* Signify end of processing of variable arguments */
Throwbot 2:c13831ca234c 20
Throwbot 2:c13831ca234c 21 int i = 0;
Throwbot 2:c13831ca234c 22 while(i < BUFFER_SIZE && buffer[i]){
Throwbot 2:c13831ca234c 23 putc(buffer[i]);
Throwbot 2:c13831ca234c 24 i++;
Throwbot 2:c13831ca234c 25 }
Throwbot 2:c13831ca234c 26 unsigned short checksum = calculateCRC16(buffer,i);
Throwbot 2:c13831ca234c 27
Throwbot 2:c13831ca234c 28 //printf(" %d %d ", checksum >> 8, checksum & 0xFF);
Throwbot 2:c13831ca234c 29
Throwbot 2:c13831ca234c 30 for( int j = 0; j < 4; j++)
Throwbot 2:c13831ca234c 31 putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F);
Throwbot 2:c13831ca234c 32
Throwbot 2:c13831ca234c 33 //putc(checksum & 0xFF);
Throwbot 2:c13831ca234c 34 putc('\r');
Throwbot 2:c13831ca234c 35 putc('\n');
Throwbot 2:c13831ca234c 36
Throwbot 2:c13831ca234c 37 return ret;
Throwbot 2:c13831ca234c 38 }
Throwbot 2:c13831ca234c 39
Throwbot 2:c13831ca234c 40 void HC05::printBufferCRC(){
Throwbot 2:c13831ca234c 41 int i = 0;
Throwbot 2:c13831ca234c 42 while(i < BUFFER_SIZE && buffer[i]){
Throwbot 2:c13831ca234c 43 putc(buffer[i]);
Throwbot 2:c13831ca234c 44 i++;
Throwbot 2:c13831ca234c 45 }
Throwbot 2:c13831ca234c 46 unsigned short checksum = calculateCRC16(buffer,i);
Throwbot 2:c13831ca234c 47
Throwbot 2:c13831ca234c 48 //printf(" %d %d ", checksum >> 8, checksum & 0xFF);
Throwbot 2:c13831ca234c 49
Throwbot 2:c13831ca234c 50 for( int j = 0; j < 4; j++)
Throwbot 2:c13831ca234c 51 putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F);
Throwbot 2:c13831ca234c 52
Throwbot 2:c13831ca234c 53 //putc(checksum & 0xFF);
Throwbot 2:c13831ca234c 54 putc('\r');
Throwbot 2:c13831ca234c 55 putc('\n');
Throwbot 2:c13831ca234c 56 }
Throwbot 2:c13831ca234c 57 //void HCO5::stop(){
Throwbot 2:c13831ca234c 58 // on_switch = 0;
Throwbot 2:c13831ca234c 59 //}