Helmut Schmücker / FtControlSet

Dependencies:   NeedfulThings

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FtControlSetMessage.h Source File

FtControlSetMessage.h

00001 #ifndef FTCONTROLSETSIGNAL_H
00002 #define FTCONTROLSETSIGNAL_H
00003 
00004 #include <cstdint>
00005 #include "mbed.h"
00006 
00007 /// interface class that translates the raw message of ft IR remote control
00008 /// @note just a wrapper arround an evil bitfield, not really portable, ... but they are so handy
00009 class FtControlSetMessage
00010 {
00011     union { 
00012         //  message structure: 30 payload bits plus 2 status bit added by receiver ISR plus 
00013         struct { 
00014             unsigned status:2;      // @see Status
00015             unsigned tail:1;        // should be 0
00016             unsigned parity:1;      // set if parity even
00017             unsigned leftXDir:1;    // direction left x
00018             unsigned leftYDir:1;    // direction left y
00019             unsigned rightXDir:1;   // direction right x
00020             unsigned rightYDir:1;   // direction right y
00021             unsigned leftXSpd:4;    // speed left x
00022             unsigned leftYSpd:4;    // speed left y
00023             unsigned rightXSpd:4;   // speed right x
00024             unsigned rightYSpd:4;   // speed right y
00025             unsigned onBut:1;       // ON button
00026             unsigned offBut:1;      // OFF button
00027             unsigned switch1:1;     // switch 1
00028             unsigned switch2:1;     // switch 1
00029             unsigned header:4;      // should be 8;
00030         };
00031         uint32_t m_rawMessage;
00032     };
00033 
00034 public:
00035 
00036     /// Status enum returned by getStatus().
00037     enum Status {/// everything is fine
00038         OK=0,       /// wrong header ID
00039         FrameKO,  /// parity error
00040         ParityKO  
00041         //ReceiveKO=1,/// message was corrupted: Wrong number of pulses or bad timing
00042     } ;
00043 
00044     /// Constructor from raw 32bit message
00045     FtControlSetMessage(uint32_t rawMessage):m_rawMessage(rawMessage) {};
00046 
00047     /// get x position of left control stick [-15,15]
00048     int32_t getLeftX()const {
00049         return leftXDir?leftXSpd:-leftXSpd;
00050     };
00051     /// get y position of left control stick [-15,15]
00052     int32_t getLeftY()const {
00053         return leftYDir?leftYSpd:-leftYSpd;
00054     };
00055     /// get x position of right control stick [-15,15]
00056     int32_t getRightX()const {
00057         return rightXDir?rightXSpd:-rightXSpd;
00058     };
00059     /// get y position of right control stick [-15,15]
00060     int32_t getRightY()const {
00061         return rightYDir?rightYSpd:-rightYSpd;
00062     };
00063     /// get state of the ON button
00064     bool getOnButton()const {
00065         return onBut;
00066     };
00067     /// get state of the OFF button
00068     bool getOffButton()const {
00069         return offBut;
00070     };
00071     /// get state of switch 1 (Frequency setting)
00072     bool getSwitch1()const {
00073         return switch1;
00074     };
00075     /// get state of switch 2 (Receiver ID)
00076     bool getSwitch2()const {
00077         return switch2;
00078     };
00079     /// get Status of this message, see Status
00080     Status getStatus()const {
00081         return static_cast<Status>(status);
00082     };
00083 
00084     /// get message in raw format
00085     uint32_t getRawMessage()const {
00086         return m_rawMessage;
00087     };
00088 };
00089 
00090 #endif