NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Revision:
27:9e546fa47c33
Parent:
21:c2a2e7cbabdd
Child:
28:ba6ca9f4def4
--- a/RC/RC_Channel.cpp	Tue Nov 27 19:49:38 2012 +0000
+++ b/RC/RC_Channel.cpp	Wed Nov 28 12:29:02 2012 +0000
@@ -1,18 +1,22 @@
 #include "RC_Channel.h"
 #include "mbed.h"
 
-RC_Channel::RC_Channel(PinName mypin) : myinterrupt(mypin)
+RC_Channel::RC_Channel(PinName mypin, int index) : myinterrupt(mypin)
 {
-    time = -100; // start value to see if there was any value yet
+    RC_Channel::index = index;
+    time = -101; // start value to see if there was any value yet
+    
+    loadCalibrationValue(&scale, "SCALE");
+    loadCalibrationValue(&offset, "OFFSET");
+    
     myinterrupt.rise(this, &RC_Channel::rise);
     myinterrupt.fall(this, &RC_Channel::fall);
     timeoutchecker.attach(this, &RC_Channel::timeoutcheck, 1);
-    
 }
 
 int RC_Channel::read()
 {
-    return time;
+    return scale * (float)(time) + offset; // calibration of the readings
 }
 
 void RC_Channel::rise()
@@ -25,7 +29,7 @@
     timer.stop();
     int tester = timer.read_us();
     if(tester >= 1000 && tester <=2000)
-        time = (tester-70)-1000;  // TODO: skalierung mit calibrierung (speichern....)
+        time = tester-1000;  // we want only the signal from 1000 on
     timer.reset();
     timer.start();
 }
@@ -34,4 +38,28 @@
 {
     if (timer.read() > 0.3)
         time = -100;
+}
+
+void RC_Channel::saveCalibrationValue(float * value, char * fileextension)
+{
+    char path[40];
+    sprintf(path, "/local/FlyBed/RC_%d_%s", index, fileextension);
+    FILE *fp = fopen(path, "w");
+    if (fp != NULL) {
+        fprintf(fp, "%f", value);
+        fclose(fp);
+    } else
+        value = 0;
+}
+
+void RC_Channel::loadCalibrationValue(float * value, char * fileextension)
+{
+    char path[40];
+    sprintf(path, "/local/FlyBed/RC_%d_%s", index, fileextension);
+    FILE *fp = fopen(path, "r");
+    if (fp != NULL) {
+        fscanf(fp, "%f", value);
+        fclose(fp);
+    } else
+        value = 0;
 }
\ No newline at end of file