.

Dependents:  

Revision:
4:288253c4da29
Child:
5:69857f8b6931
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RCin.cpp	Wed Oct 17 13:02:19 2018 +0000
@@ -0,0 +1,87 @@
+#include "RCin.h"
+
+
+using namespace std;
+
+RCin::RCin(PinName pin) : pwm1(pin){
+    pwm1.fall(callback(this, &RCin::fall_edge));
+    pwm1.rise(callback(this, &RCin::rise_edge));
+    loc_ti.start();
+    loc_ti.reset();
+    }
+
+uint8_t RCin::map_CH5_2_Flightmode(uint16_t pwm){
+    if(pwm >620 && pwm < 720)
+        return LOITER;
+    else if(pwm >720 && pwm < 850)
+        return AUTO;
+    else if(pwm >870 && pwm < 970)
+        return RTL;
+    else if(pwm >1000 && pwm < 1100)
+        return STABILIZED;
+    else if(pwm >1100 && pwm < 1200)
+        return ACRO;
+    else if(pwm >1200 && pwm < 1350)
+        return LAND;
+    else
+        return STABILIZED;
+}
+
+
+void RCin::map_Channels(void){
+    CH1_2_PM1.setup(600.0,1400.0,-1.0,1.0);
+    CH2_2_PM1.setup(1400.0,600.0,-1.0,1.0);
+    CH3_2_PM1.setup(600.0,1400.0,-1.0,1.0);
+    CH4_2_PM1.setup(600.0,1400.0,-1.0,1.0);
+    }
+
+void RCin::rise_edge(void)
+    {
+     loc_ti.reset();
+     }
+void RCin::fall_edge(void)
+   {
+        uint32_t time_us = loc_ti.read_us();
+        if(time_us > 2500){
+        if(cou<200)
+            cou++;
+        chnr = 0;
+        }
+        else
+        {
+            pwms[++chnr] = time_us;
+            test_pwms[cou][chnr-1]=time_us;
+            switch(chnr){
+                case 1:
+                    this->PM1[1]=this->CH1_2_PM1((float)pwms[1]);
+                    break;
+                case 2:
+                    this->PM1[2]=this->CH2_2_PM1((float)pwms[2]);
+                    break;
+                case 3:
+                    this->PM1[3]=this->CH3_2_PM1((float)pwms[3]);
+                    break;
+                case 4:
+                    this->PM1[4]=this->CH4_2_PM1((float)pwms[4]);
+                    break;
+                default: break;
+                }
+        }
+    }
+bool RCin::isAlive(void){
+        if(pwms[3]>550)
+            return true;
+        else 
+            return false;
+}
+
+
+uint8_t RCin::get_flightmode(void){
+    if(isAlive())
+        return map_CH5_2_Flightmode(pwms[5]);
+    else 
+        return 0;
+    }
+
+
+