Library to use remote control Spektrum AR6210
AR6210.cpp@1:25aad26619fb, 2013-11-24 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
Joram | 0:9a1f7660704d | 1 | #include "mbed.h" |
Joram | 0:9a1f7660704d | 2 | #include "AR6210.h" |
Joram | 0:9a1f7660704d | 3 | // Original code: https://mbed.org/users/BlazeX/code/AR8000/ |
Joram | 0:9a1f7660704d | 4 | // Modified by Joram Querner for Spektrum AR6210 |
Joram | 0:9a1f7660704d | 5 | |
Joram | 0:9a1f7660704d | 6 | AR6210::AR6210() : |
Joram | 1:25aad26619fb | 7 | ChInt0(InterruptIn(p5)), // throttle |
Joram | 1:25aad26619fb | 8 | ChInt1(InterruptIn(p6)), // aileron |
Joram | 0:9a1f7660704d | 9 | ChInt2(InterruptIn(p7)), // elevator |
Joram | 1:25aad26619fb | 10 | ChInt3(InterruptIn(p8)), // rudder |
Joram | 0:9a1f7660704d | 11 | ChInt4(InterruptIn(p9)), // gear |
Joram | 0:9a1f7660704d | 12 | ChInt5(InterruptIn(p10)) // aux |
Joram | 0:9a1f7660704d | 13 | {} |
Joram | 0:9a1f7660704d | 14 | |
Joram | 0:9a1f7660704d | 15 | void AR6210::init() |
Joram | 0:9a1f7660704d | 16 | { |
Joram | 0:9a1f7660704d | 17 | Time.start(); |
Joram | 0:9a1f7660704d | 18 | |
Joram | 0:9a1f7660704d | 19 | for(int i= 0; i < 6; i++) { |
Joram | 0:9a1f7660704d | 20 | LastRise[i]= 0; |
Joram | 0:9a1f7660704d | 21 | dTime[i]= 1000; |
Joram | 0:9a1f7660704d | 22 | } |
Joram | 0:9a1f7660704d | 23 | |
Joram | 0:9a1f7660704d | 24 | ChInt0.mode(PullDown); ChInt0.rise<AR6210>(this, &AR6210::Rise0); ChInt0.fall<AR6210>(this, &AR6210::Fall0); |
Joram | 0:9a1f7660704d | 25 | ChInt1.mode(PullDown); ChInt1.rise<AR6210>(this, &AR6210::Rise1); ChInt1.fall<AR6210>(this, &AR6210::Fall1); |
Joram | 0:9a1f7660704d | 26 | ChInt2.mode(PullDown); ChInt2.rise<AR6210>(this, &AR6210::Rise2); ChInt2.fall<AR6210>(this, &AR6210::Fall2); |
Joram | 0:9a1f7660704d | 27 | ChInt3.mode(PullDown); ChInt3.rise<AR6210>(this, &AR6210::Rise3); ChInt3.fall<AR6210>(this, &AR6210::Fall3); |
Joram | 0:9a1f7660704d | 28 | ChInt4.mode(PullDown); ChInt4.rise<AR6210>(this, &AR6210::Rise4); ChInt4.fall<AR6210>(this, &AR6210::Fall4); |
Joram | 0:9a1f7660704d | 29 | ChInt5.mode(PullDown); ChInt5.rise<AR6210>(this, &AR6210::Rise5); ChInt5.fall<AR6210>(this, &AR6210::Fall5); |
Joram | 0:9a1f7660704d | 30 | |
Joram | 0:9a1f7660704d | 31 | update(); |
Joram | 0:9a1f7660704d | 32 | } |
Joram | 0:9a1f7660704d | 33 | |
Joram | 0:9a1f7660704d | 34 | void AR6210::update() |
Joram | 0:9a1f7660704d | 35 | { |
Joram | 0:9a1f7660704d | 36 | //Rohdaten �hmen |
Joram | 0:9a1f7660704d | 37 | for(int i= 0; i<6; i++) |
Joram | 0:9a1f7660704d | 38 | RawChannels[i]= dTime[i]; |
Joram | 0:9a1f7660704d | 39 | |
Joram | 1:25aad26619fb | 40 | Throttle= map(dTime[0], 1095, 1910, 0.0, 1.0); |
Joram | 1:25aad26619fb | 41 | Aileron= map(dTime[1], 1110, 1900, -1.0, 1.0); |
Joram | 1:25aad26619fb | 42 | Elevator= map(dTime[2], 1100, 1900, -1.0, 1.0); |
Joram | 1:25aad26619fb | 43 | Rudder= map(dTime[3], 1105, 1895, -1.0, 1.0); |
Joram | 0:9a1f7660704d | 44 | |
Joram | 1:25aad26619fb | 45 | Gear= map(dTime[4], 1095, 1910, 0.0, 1.0); |
Joram | 1:25aad26619fb | 46 | Aux= map(dTime[5], 1095, 1910, 0.0, 1.0); |
Joram | 1:25aad26619fb | 47 | } |
Joram | 1:25aad26619fb | 48 | |
Joram | 1:25aad26619fb | 49 | float AR6210::map(int x, int in_min, int in_max, float out_min, float out_max) |
Joram | 1:25aad26619fb | 50 | { |
Joram | 1:25aad26619fb | 51 | float returnValue = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
Joram | 1:25aad26619fb | 52 | if (returnValue < out_min) |
Joram | 1:25aad26619fb | 53 | return out_min; |
Joram | 1:25aad26619fb | 54 | if (returnValue > out_max) |
Joram | 1:25aad26619fb | 55 | return out_max; |
Joram | 1:25aad26619fb | 56 | |
Joram | 1:25aad26619fb | 57 | return returnValue; |
Joram | 0:9a1f7660704d | 58 | } |