summaryrefslogtreecommitdiff
path: root/arduino_libs/SerialManager/SerialManager.h
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2011-12-19 18:20:33 +0000
committerTim Redfern <tim@eclectronics.org>2011-12-19 18:20:33 +0000
commite9a73bbb3c14af340999f70146747787785f4fee (patch)
treea125452f7d641673286542497da051b810427880 /arduino_libs/SerialManager/SerialManager.h
initial commit
Diffstat (limited to 'arduino_libs/SerialManager/SerialManager.h')
-rwxr-xr-xarduino_libs/SerialManager/SerialManager.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/arduino_libs/SerialManager/SerialManager.h b/arduino_libs/SerialManager/SerialManager.h
new file mode 100755
index 0000000..f1474c5
--- /dev/null
+++ b/arduino_libs/SerialManager/SerialManager.h
@@ -0,0 +1,62 @@
+/*
+ SerialManager.h - Library for doing packetized serial comm with Arduinos.
+ Created by Sigurdur Orn, May 23, 2010.
+ siggi@mit.edu
+ */
+
+#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 UCSRA2 UCSR2A
+ #define UCSRA3 UCSR3A
+#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
+