diff options
| author | Tim Redfern <tim@eclectronics.org> | 2011-12-19 18:20:33 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2011-12-19 18:20:33 +0000 |
| commit | e9a73bbb3c14af340999f70146747787785f4fee (patch) | |
| tree | a125452f7d641673286542497da051b810427880 /arduino_libs/SerialManager/.svn/text-base/SerialManager.h.svn-base | |
initial commit
Diffstat (limited to 'arduino_libs/SerialManager/.svn/text-base/SerialManager.h.svn-base')
| -rwxr-xr-x | arduino_libs/SerialManager/.svn/text-base/SerialManager.h.svn-base | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/arduino_libs/SerialManager/.svn/text-base/SerialManager.h.svn-base b/arduino_libs/SerialManager/.svn/text-base/SerialManager.h.svn-base new file mode 100755 index 0000000..dcbdba6 --- /dev/null +++ b/arduino_libs/SerialManager/.svn/text-base/SerialManager.h.svn-base @@ -0,0 +1,63 @@ +/* + SerialManager.h - Library for doing packetized serial comm with Arduinos. + Created by Sigurdur Orn, May 23, 2010. + */ +#ifndef SerialManager_h +#define SerialManager_h + +#include "ByteBuffer.h" +#include "WProgram.h" + +typedef void (*voidFuncPtr)(ByteBuffer*); + +#if defined(__AVR_ATmega8__) + #define UCSRA UCSRA + #define UDRE UDRE +#else + #define UCSRA UCSR0A + #define UDRE UDRE0 +#endif + +#if defined(__AVR_ATmega1280__) + #define UCSRA1 UCSR1A + #define UDRE1 UDRE1 + #define UCSRA2 UCSR2A + #define UDRE2 UDRE2 + #define UCSRA3 UCSR3A + #define UDRE3 UDRE3 +#endif + + +class SerialManager +{ +public: + SerialManager(unsigned int in_buf_size, unsigned int out_buf_size); + void init(int serial_port, int baud_rate); + void setPacketHandler(void (*rx_func)(ByteBuffer*)); + + void update(); + bool isBusySending(); + + int sendSerialByte(byte b); + int sendSerialPacket(ByteBuffer* packet); + int sendRawSerial(ByteBuffer* packet); + +private: + void handleIncomingByte(byte incoming); + void handlePacketDefault(ByteBuffer* packet); + + voidFuncPtr handlePacketFunction; + + byte _serial_port; + ByteBuffer* incoming_buffer; + ByteBuffer* outgoing_buffer; + ByteBuffer* temp_buffer; + byte serial_in_checksum; + byte byte1; + byte byte2; + byte byte3; + byte byte4; +}; + +#endif + |
