Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
triff
Date:
Tue Oct 12 13:26:58 2010 +0000
Commit message:

Changed in this revision

SerialRazor.cpp Show annotated file Show diff for this revision Revisions of this file
SerialRazor.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 87f191bdb9ab SerialRazor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SerialRazor.cpp	Tue Oct 12 13:26:58 2010 +0000
@@ -0,0 +1,57 @@
+
+#include "mbed.h"
+#include "SerialRazor.h"
+
+SerialRazor::SerialRazor( size_t bufferSize, PinName tx, PinName rx ) : Serial(  tx,  rx )  {
+
+    Serial::baud(57600);
+    attach( this, &SerialRazor::handleInterrupt );
+    m_buff = (char *) malloc( bufferSize );
+    m_buffSize = bufferSize;
+}
+
+
+
+SerialRazor::~SerialRazor()
+{
+    if( m_buff )
+        free( m_buff );
+}
+
+void SerialRazor::handleInterrupt()
+{
+    
+    while( Serial::readable())
+    {
+        for(int i=0; i< m_buffSize; i++) {
+        m_buff[i] = Serial::getc();
+        if(m_buff[i] == '\n') {
+            m_buff[i] = 0;
+            sscanf(m_buff,"!ANG:%f,%f,%f", &roll, &pitch, &yaw); 
+            return;
+        } 
+        }   
+       
+    }
+}
+
+
+
+float SerialRazor::getRoll(void){
+
+    return roll;
+
+}
+
+float SerialRazor::getPitch(void){
+
+    return pitch;
+
+}
+
+float SerialRazor::getYaw(void){
+
+    return yaw;
+
+}
+
diff -r 000000000000 -r 87f191bdb9ab SerialRazor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SerialRazor.h	Tue Oct 12 13:26:58 2010 +0000
@@ -0,0 +1,29 @@
+#pragma once
+
+// This is a buffered serial reading class, using the serial interrupt introduced in mbed library version 18 on 17/11/09
+
+// In the simplest case, construct it with a buffer size at least equal to the largest message you 
+// expect your program to receive in one go.
+
+class SerialRazor : public Serial
+{
+public:
+    SerialRazor( size_t bufferSize, PinName tx, PinName rx );
+    virtual ~SerialRazor();
+    float getRoll(void);
+    float getPitch(void);
+    float getYaw(void);
+    
+
+
+private:
+    
+    void handleInterrupt();
+    float roll;
+    float pitch;
+    float yaw;    
+    char *m_buff;           
+    uint16_t m_buffSize;
+    
+
+};
\ No newline at end of file
diff -r 000000000000 -r 87f191bdb9ab main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 12 13:26:58 2010 +0000
@@ -0,0 +1,14 @@
+
+#include "mbed.h"
+#include "SerialRazor.h"
+
+Serial pc(USBTX, USBRX);
+
+int main() {
+    SerialRazor *Razor = new SerialRazor( 32, p13, p14);
+    while(1){
+        wait(0.2);
+        pc.printf("Roll: %f\n\r", Razor->getRoll());
+        }
+    
+}
diff -r 000000000000 -r 87f191bdb9ab mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 12 13:26:58 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0