ppm

Dependents:   Autonomous_quadcopter

Fork of PPM by Eduard Medla

Revision:
4:380e7c35e466
Parent:
3:2d4d05f95c1a
--- a/PpmRegen.cpp	Wed Sep 27 17:05:59 2017 +0000
+++ b/PpmRegen.cpp	Thu Oct 26 15:53:52 2017 +0000
@@ -1,42 +1,51 @@
-#include "mbed.h"
 #include "PpmRegen.h"
 
-PpmRegen::PpmRegen(PinName InterruptPort, PinName roll, PinName pitch, PinName yaw, PinName throttle, PinName aux1, PinName aux2): 
-ppmPin(InterruptPort), _roll(roll), _pitch(pitch), _yaw(yaw), _throttle(throttle), _aux1(aux1), _aux2(aux2){
+PpmRegen::PpmRegen(InterruptIn* interruptPort){
+    ppmPin = interruptPort;
+    
+    last_channels[ROLL] = 0;
+    last_channels[PITCH] = 0;
+    last_channels[YAW] = 0;
+    last_channels[THROTTLE] = 0;
+    last_channels[AUX1] = 0;
+    last_channels[AUX2] = 0;
+    
     current_channel = 0;
-    first_reading = true;
     timer.start();
-    ppmPin.fall(this, &PpmRegen::fall);
+    ppmPin->fall(callback(this, &PpmRegen::fall));
 }
     
 
 void PpmRegen::getAllChannels(uint16_t all_channels[]){
     for(int i = 0; i < CHANNELS; i++){
-        all_channels[i] = channels[i];   
+        all_channels[i] = last_channels[i];   
     }           
     
 }
             
 void PpmRegen::fall(){
-    //__disable_irq();
+    __disable_irq();
     uint16_t time = timer.read_us();
     
     // we are in synchro zone
     if(time > 2500)
     {
-        if(first_reading){
-            //channel_correction();   
-            first_reading = false;     
-        }
-        
         current_channel = 0;
-        
-        _roll.pulsewidth_us(    channels[0]);
-        _pitch.pulsewidth_us(   channels[1]);
-        _yaw.pulsewidth_us(     channels[2]);
-        _throttle.pulsewidth_us(channels[3]);
-        _aux1.pulsewidth_us(    channels[4]);
-        _aux2.pulsewidth_us(    channels[5]);
+        last_channels[ROLL] = channels[ROLL];
+        last_channels[PITCH] = channels[PITCH];
+        last_channels[YAW] = channels[YAW];
+        last_channels[THROTTLE] = channels[THROTTLE];
+        last_channels[AUX1] = channels[AUX1];
+        last_channels[AUX2] = channels[AUX2];
+      
+        /*
+        _roll->pulsewidth_us(    channels[ROLL]);
+        _pitch->pulsewidth_us(   channels[PITCH]);
+        _yaw->pulsewidth_us(     channels[YAW]);
+        _throttle->pulsewidth_us(channels[THROTTLE]);
+        _aux1->pulsewidth_us(    channels[AUX1]);
+        _aux2->pulsewidth_us(    channels[AUX2]);
+        */
     }
     else
     {
@@ -46,14 +55,14 @@
     
     timer.reset();
     
-    //__enable_irq();
+    __enable_irq();
 }
 
 void PpmRegen::channel_correction(){
-    corrections[0] = 1500 - channels[0];    
-    corrections[1] = 1500 - channels[1];
-    corrections[2] = 1500 - channels[2];
-    corrections[3] = 1010 - channels[3];
-    corrections[4] = 1010 - channels[4];
-    corrections[5] = 1010 - channels[5];
+    corrections[ROLL] = 1500 - channels[ROLL];    
+    corrections[PITCH] = 1500 - channels[PITCH];
+    corrections[YAW] = 1500 - channels[YAW];
+    corrections[THROTTLE] = 1010 - channels[THROTTLE];
+    corrections[AUX1] = 1010 - channels[AUX1];
+    corrections[AUX2] = 1010 - channels[AUX2];
 }
\ No newline at end of file