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 18 22:00:53 2013 +0000
Revision:
2:1ae8bb468515
Parent:
1:3904ef8c606e
Child:
3:038f86bac6cc
work, still needs some docu;

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