Receiver interface for the fischertechnik IR control set

Dependencies:   NeedfulThings

Receiver interface for the fischertechnik IR control set.

An mbed port of the code found on this ft community WIKI page The ft IR remote control uses some kind of RC-MM Protocol . When any of the controls is applied the remote control sends updates at a rate of at 1/120ms or 1/90ms depending on the senders frequency setting. Each message delivers the complete remote control status encoded into 30 bits. The structure of the message can be seen in FtControlSetMessage.h.

I assume that the ft control set works fine with standard 38kHz IR detectors. I have used a CHQ0038 from a broken DVD Player. It can be connected directly to the mbed: GND, VCC->3.3V and the signal line to any of the numbered mbed gpios.

The PDM timing of the ft IR control set isn't that exact. Thus receive errors occur quite frequently. I am observing an error rate somewhere between 3% and 5%. This driver "ignores" up to 3 consecutive receive errors, i.e. it just indicates an error but still provides the last correctly received message, before it resets the message to zero after the fourth error.

Committer:
humlet
Date:
Mon Mar 25 21:50:27 2013 +0000
Revision:
6:3cce31050c90
Parent:
3:038f86bac6cc
just added NeedfulThings lib dependency; (hopefully)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
humlet 1:3904ef8c606e 1 #ifndef FTCONTROLSETSIGNAL_H
humlet 1:3904ef8c606e 2 #define FTCONTROLSETSIGNAL_H
humlet 1:3904ef8c606e 3
humlet 1:3904ef8c606e 4 #include <cstdint>
humlet 1:3904ef8c606e 5 #include "mbed.h"
humlet 1:3904ef8c606e 6
humlet 1:3904ef8c606e 7 /// interface class that translates the raw message of ft IR remote control
humlet 3:038f86bac6cc 8 /// @note just a wrapper arround an evil bitfield, not really portable, ... but they are so handy
humlet 1:3904ef8c606e 9 class FtControlSetMessage
humlet 1:3904ef8c606e 10 {
humlet 3:038f86bac6cc 11 union {
humlet 3:038f86bac6cc 12 // message structure: 30 payload bits plus 2 status bit added by receiver ISR plus
humlet 3:038f86bac6cc 13 struct {
humlet 3:038f86bac6cc 14 unsigned status:2; // @see Status
humlet 3:038f86bac6cc 15 unsigned tail:1; // should be 0
humlet 3:038f86bac6cc 16 unsigned parity:1; // set if parity even
humlet 3:038f86bac6cc 17 unsigned leftXDir:1; // direction left x
humlet 3:038f86bac6cc 18 unsigned leftYDir:1; // direction left y
humlet 3:038f86bac6cc 19 unsigned rightXDir:1; // direction right x
humlet 3:038f86bac6cc 20 unsigned rightYDir:1; // direction right y
humlet 3:038f86bac6cc 21 unsigned leftXSpd:4; // speed left x
humlet 3:038f86bac6cc 22 unsigned leftYSpd:4; // speed left y
humlet 3:038f86bac6cc 23 unsigned rightXSpd:4; // speed right x
humlet 3:038f86bac6cc 24 unsigned rightYSpd:4; // speed right y
humlet 3:038f86bac6cc 25 unsigned onBut:1; // ON button
humlet 3:038f86bac6cc 26 unsigned offBut:1; // OFF button
humlet 3:038f86bac6cc 27 unsigned switch1:1; // switch 1
humlet 3:038f86bac6cc 28 unsigned switch2:1; // switch 1
humlet 3:038f86bac6cc 29 unsigned header:4; // should be 8;
humlet 1:3904ef8c606e 30 };
humlet 1:3904ef8c606e 31 uint32_t m_rawMessage;
humlet 1:3904ef8c606e 32 };
humlet 1:3904ef8c606e 33
humlet 1:3904ef8c606e 34 public:
humlet 1:3904ef8c606e 35
humlet 1:3904ef8c606e 36 /// Status enum returned by getStatus().
humlet 1:3904ef8c606e 37 enum Status {/// everything is fine
humlet 2:1ae8bb468515 38 OK=0, /// wrong header ID
humlet 2:1ae8bb468515 39 FrameKO, /// parity error
humlet 2:1ae8bb468515 40 ParityKO
humlet 2:1ae8bb468515 41 //ReceiveKO=1,/// message was corrupted: Wrong number of pulses or bad timing
humlet 1:3904ef8c606e 42 } ;
humlet 1:3904ef8c606e 43
humlet 1:3904ef8c606e 44 /// Constructor from raw 32bit message
humlet 1:3904ef8c606e 45 FtControlSetMessage(uint32_t rawMessage):m_rawMessage(rawMessage) {};
humlet 1:3904ef8c606e 46
humlet 1:3904ef8c606e 47 /// get x position of left control stick [-15,15]
humlet 1:3904ef8c606e 48 int32_t getLeftX()const {
humlet 1:3904ef8c606e 49 return leftXDir?leftXSpd:-leftXSpd;
humlet 1:3904ef8c606e 50 };
humlet 1:3904ef8c606e 51 /// get y position of left control stick [-15,15]
humlet 1:3904ef8c606e 52 int32_t getLeftY()const {
humlet 1:3904ef8c606e 53 return leftYDir?leftYSpd:-leftYSpd;
humlet 1:3904ef8c606e 54 };
humlet 1:3904ef8c606e 55 /// get x position of right control stick [-15,15]
humlet 1:3904ef8c606e 56 int32_t getRightX()const {
humlet 1:3904ef8c606e 57 return rightXDir?rightXSpd:-rightXSpd;
humlet 1:3904ef8c606e 58 };
humlet 1:3904ef8c606e 59 /// get y position of right control stick [-15,15]
humlet 1:3904ef8c606e 60 int32_t getRightY()const {
humlet 1:3904ef8c606e 61 return rightYDir?rightYSpd:-rightYSpd;
humlet 1:3904ef8c606e 62 };
humlet 1:3904ef8c606e 63 /// get state of the ON button
humlet 1:3904ef8c606e 64 bool getOnButton()const {
humlet 1:3904ef8c606e 65 return onBut;
humlet 1:3904ef8c606e 66 };
humlet 1:3904ef8c606e 67 /// get state of the OFF button
humlet 1:3904ef8c606e 68 bool getOffButton()const {
humlet 1:3904ef8c606e 69 return offBut;
humlet 1:3904ef8c606e 70 };
humlet 1:3904ef8c606e 71 /// get state of switch 1 (Frequency setting)
humlet 1:3904ef8c606e 72 bool getSwitch1()const {
humlet 1:3904ef8c606e 73 return switch1;
humlet 1:3904ef8c606e 74 };
humlet 1:3904ef8c606e 75 /// get state of switch 2 (Receiver ID)
humlet 1:3904ef8c606e 76 bool getSwitch2()const {
humlet 1:3904ef8c606e 77 return switch2;
humlet 1:3904ef8c606e 78 };
humlet 1:3904ef8c606e 79 /// get Status of this message, see Status
humlet 1:3904ef8c606e 80 Status getStatus()const {
humlet 1:3904ef8c606e 81 return static_cast<Status>(status);
humlet 1:3904ef8c606e 82 };
humlet 1:3904ef8c606e 83
humlet 1:3904ef8c606e 84 /// get message in raw format
humlet 1:3904ef8c606e 85 uint32_t getRawMessage()const {
humlet 1:3904ef8c606e 86 return m_rawMessage;
humlet 1:3904ef8c606e 87 };
humlet 1:3904ef8c606e 88 };
humlet 1:3904ef8c606e 89
humlet 1:3904ef8c606e 90 #endif