Library to use remote control Spektrum AR6210

Committer:
Joram
Date:
Sun Nov 24 09:46:45 2013 +0000
Revision:
1:25aad26619fb
Parent:
0:9a1f7660704d
added mapping function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Joram 0:9a1f7660704d 1 #pragma once
Joram 0:9a1f7660704d 2 // Original code: https://mbed.org/users/BlazeX/code/AR8000/
Joram 0:9a1f7660704d 3 // Modified by Joram Querner for Spektrum AR6210
Joram 0:9a1f7660704d 4
Joram 0:9a1f7660704d 5 // Interrupt callback
Joram 0:9a1f7660704d 6 #define AR6210_RISE_FALL(Ch)\
Joram 0:9a1f7660704d 7 void Rise##Ch()\
Joram 0:9a1f7660704d 8 {\
Joram 0:9a1f7660704d 9 LastRise[Ch]= Time.read_us();\
Joram 0:9a1f7660704d 10 }\
Joram 0:9a1f7660704d 11 void Fall##Ch()\
Joram 0:9a1f7660704d 12 {\
Joram 0:9a1f7660704d 13 int dT= Time.read_us() - LastRise[Ch];\
Joram 0:9a1f7660704d 14 if(dT > 900 && dT < 2100)\
Joram 0:9a1f7660704d 15 dTime[Ch]= dT;\
Joram 0:9a1f7660704d 16 }
Joram 0:9a1f7660704d 17
Joram 0:9a1f7660704d 18
Joram 0:9a1f7660704d 19 class AR6210
Joram 0:9a1f7660704d 20 {
Joram 0:9a1f7660704d 21 private:
Joram 0:9a1f7660704d 22 InterruptIn ChInt0;
Joram 0:9a1f7660704d 23 InterruptIn ChInt1;
Joram 0:9a1f7660704d 24 InterruptIn ChInt2;
Joram 0:9a1f7660704d 25 InterruptIn ChInt3;
Joram 0:9a1f7660704d 26 InterruptIn ChInt4;
Joram 0:9a1f7660704d 27 InterruptIn ChInt5;
Joram 0:9a1f7660704d 28
Joram 0:9a1f7660704d 29 Timer Time;
Joram 0:9a1f7660704d 30 volatile int LastRise[6]; //Zeitpunkt der letzten steigende Flanke
Joram 0:9a1f7660704d 31 volatile int dTime[6]; //Pulsdauer in us [1000...2000]
Joram 0:9a1f7660704d 32
Joram 1:25aad26619fb 33 float map(int x, int in_min, int in_max, float out_min, float out_max);
Joram 1:25aad26619fb 34
Joram 0:9a1f7660704d 35 public:
Joram 0:9a1f7660704d 36 int RawChannels[6]; //Rohdaten [1000...2000]
Joram 0:9a1f7660704d 37
Joram 0:9a1f7660704d 38 //Die Steuerbefehle
Joram 0:9a1f7660704d 39 float Throttle; //0=Aus, 1=Vollgas
Joram 0:9a1f7660704d 40 float Aileron; //-1=Links, 0=Nichts, +1=Rechts
Joram 0:9a1f7660704d 41 float Elevator; //-1=Sinken, 0=Nichts, +1=Steigen
Joram 0:9a1f7660704d 42 float Rudder; //-1=Links, 0=Nichts, +1=Rechts
Joram 0:9a1f7660704d 43
Joram 0:9a1f7660704d 44 float Gear; //-1...+1 Left Trim
Joram 0:9a1f7660704d 45 float Aux; //-1...+1 Right Trim
Joram 0:9a1f7660704d 46
Joram 0:9a1f7660704d 47 //Initialisieren
Joram 0:9a1f7660704d 48 AR6210();
Joram 0:9a1f7660704d 49 void init();
Joram 0:9a1f7660704d 50 void update();
Joram 0:9a1f7660704d 51
Joram 0:9a1f7660704d 52 //Interrupt-Callbacks definieren
Joram 0:9a1f7660704d 53 AR6210_RISE_FALL(0);
Joram 0:9a1f7660704d 54 AR6210_RISE_FALL(1);
Joram 0:9a1f7660704d 55 AR6210_RISE_FALL(2);
Joram 0:9a1f7660704d 56 AR6210_RISE_FALL(3);
Joram 0:9a1f7660704d 57 AR6210_RISE_FALL(4);
Joram 0:9a1f7660704d 58 AR6210_RISE_FALL(5);
Joram 0:9a1f7660704d 59 };