Initial Fork
Dependencies: CRC16
Fork of SWSPI by
Revision 2:c13831ca234c, committed 2014-10-05
- Comitter:
- Throwbot
- Date:
- Sun Oct 05 12:21:30 2014 +0000
- Parent:
- 1:faa9f74488ba
- Child:
- 3:e2d77a394590
- Commit message:
- Bluetooth lib
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CRC16.lib Sun Oct 05 12:21:30 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/EmLa/code/CRC16/#d59e43c83800
--- a/HC05.cpp Thu May 08 19:10:52 2014 +0000 +++ b/HC05.cpp Sun Oct 05 12:21:30 2014 +0000 @@ -1,8 +1,59 @@ #include "HC05.h" +#include <stdarg.h> HC05::HC05(PinName tx_pin, PinName rx_pin, PinName en_pin): - Serial(tx_pin, rx_pin), + MODSERIAL(tx_pin, rx_pin), on_switch(en_pin) { + //wait_ms(5000); //mark + on_switch = 0; +} +void HC05::start(){ on_switch = 1; } +int HC05::printfCRC ( const char * format, ... ){ + + va_list argptr; /* Set up the variable argument list here */ + va_start(argptr, format); + int ret = sprintf(buffer,format, argptr); + va_end(argptr); /* Signify end of processing of variable arguments */ + + int i = 0; + while(i < BUFFER_SIZE && buffer[i]){ + putc(buffer[i]); + i++; + } + unsigned short checksum = calculateCRC16(buffer,i); + + //printf(" %d %d ", checksum >> 8, checksum & 0xFF); + + for( int j = 0; j < 4; j++) + putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F); + + //putc(checksum & 0xFF); + putc('\r'); + putc('\n'); + + return ret; + } + +void HC05::printBufferCRC(){ + int i = 0; + while(i < BUFFER_SIZE && buffer[i]){ + putc(buffer[i]); + i++; + } + unsigned short checksum = calculateCRC16(buffer,i); + + //printf(" %d %d ", checksum >> 8, checksum & 0xFF); + + for( int j = 0; j < 4; j++) + putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F); + + //putc(checksum & 0xFF); + putc('\r'); + putc('\n'); + } +//void HCO5::stop(){ +// on_switch = 0; +//} \ No newline at end of file
--- a/HC05.h Thu May 08 19:10:52 2014 +0000 +++ b/HC05.h Sun Oct 05 12:21:30 2014 +0000 @@ -2,14 +2,26 @@ #define HC05_H #include "mbed.h" +#include "rtos.h" +#include "MODSERIAL.h" +#include "CRC16.h" -class HC05 : public Serial +#define BUFFER_SIZE 512 + +class HC05 : public MODSERIAL, public Mutex, public CRC16 { private: public: - HC05(PinName tx_pin, PinName rx_pin, PinName en_pin); + char buffer[BUFFER_SIZE]; + + DigitalOut on_switch; - DigitalOut on_switch; + HC05(PinName tx_pin, PinName rx_pin, PinName en_pin); + int printfCRC( const char * format, ... ); + void printBufferCRC(); + void start(); + void stop(); + }; #endif