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 0:a3a07eb0c1dd 1 #ifndef FTCONTROLSETRECEIVER_H
humlet 0:a3a07eb0c1dd 2 #define FTCONTROLSETRECEIVER_H
humlet 0:a3a07eb0c1dd 3
humlet 1:3904ef8c606e 4 #include "FtControlSetMessage.h"
humlet 0:a3a07eb0c1dd 5 #include "InterruptIn.h"
humlet 0:a3a07eb0c1dd 6 #include "FunctionPointer.h"
humlet 0:a3a07eb0c1dd 7 #include "Timeout.h"
humlet 0:a3a07eb0c1dd 8
humlet 0:a3a07eb0c1dd 9 using namespace mbed;
humlet 0:a3a07eb0c1dd 10
humlet 0:a3a07eb0c1dd 11 /// Receiver interface for the fischertechnik IR control set
humlet 0:a3a07eb0c1dd 12 ///
humlet 0:a3a07eb0c1dd 13 /// An mbed port of the code found on this <A HREF="http://www.ftcommunity.de/wiki.php?action=show&topic_id=36">ft community WIKI page</a>
humlet 0:a3a07eb0c1dd 14 /// The ft IR remote control uses some kind of <A HREF="http://www.sbprojects.com/knowledge/ir/rcmm.php"> RC-MM Protocol </A>.
humlet 0:a3a07eb0c1dd 15 /// When any of the controls is applied the remote control sends updates at a rate of 1/90ms~12Hz.
humlet 1:3904ef8c606e 16 /// Each message delivers the complete remote control status encoded into 30 bits.
humlet 1:3904ef8c606e 17 /// The structure of the message is can be seen in FtControlSetMessage.h.
humlet 0:a3a07eb0c1dd 18 /// The protocol uses Pulse Distance Modulation (PDM) with two bits (dibit) per pulse, hence four different
humlet 0:a3a07eb0c1dd 19 /// distances. A transmission consists of 16 pulses (15 distances) for a total of 30 bits.
humlet 1:3904ef8c606e 20 ///
humlet 1:3904ef8c606e 21 /// I assume that the ft control set works fine with standard 38kHz IR detectors. I have used a CHQ0038 from a broken DVD Player.
humlet 1:3904ef8c606e 22 /// It can be onnected directly to the mebed: GND, VCC->3.3V and the signal line to any of the numbered mbed gpios.
humlet 0:a3a07eb0c1dd 23 class FtControlSetReceiver
humlet 0:a3a07eb0c1dd 24 {
humlet 0:a3a07eb0c1dd 25 InterruptIn m_pulseIRQ;
humlet 1:3904ef8c606e 26
humlet 0:a3a07eb0c1dd 27 uint32_t m_rxBuffer;
humlet 0:a3a07eb0c1dd 28 uint32_t m_nPulses;
humlet 0:a3a07eb0c1dd 29 uint32_t m_timeOfLastEdge;
humlet 1:3904ef8c606e 30 uint8_t m_nOnes;
humlet 2:1ae8bb468515 31
humlet 1:3904ef8c606e 32 uint32_t m_errorCount;
humlet 2:1ae8bb468515 33 uint8_t m_nGracefullyIgnoredErrors;
humlet 1:3904ef8c606e 34
humlet 1:3904ef8c606e 35 FtControlSetMessage m_lastMessage;
humlet 1:3904ef8c606e 36
humlet 1:3904ef8c606e 37 FunctionPointer m_callBack;
humlet 1:3904ef8c606e 38
humlet 1:3904ef8c606e 39 Timeout m_messageTimeout;
humlet 1:3904ef8c606e 40 Timeout m_receiveTimeout;
humlet 0:a3a07eb0c1dd 41
humlet 2:1ae8bb468515 42 //static const uint32_t c_pulseLengthLimits[5];
humlet 2:1ae8bb468515 43 static const uint32_t c_pulseLengthDelta = 100;//101;
humlet 2:1ae8bb468515 44 static const uint32_t c_pulseLengthOffset = 795;//793;
humlet 1:3904ef8c606e 45 static const uint32_t c_maxPulseTime = c_pulseLengthOffset+7*c_pulseLengthDelta/2;
humlet 1:3904ef8c606e 46 static const uint32_t c_messageTimeout[2];
humlet 2:1ae8bb468515 47 static const uint8_t c_errorsToBeGracefullyIgnored = 3;
humlet 2:1ae8bb468515 48
humlet 0:a3a07eb0c1dd 49 void pulseISR();
humlet 1:3904ef8c606e 50 void messageTimeoutISR();
humlet 1:3904ef8c606e 51 void recoverISR();
humlet 1:3904ef8c606e 52
humlet 2:1ae8bb468515 53 void messageReceived(FtControlSetMessage::Status status);
humlet 1:3904ef8c606e 54 void handleReceiveError();
humlet 0:a3a07eb0c1dd 55
humlet 0:a3a07eb0c1dd 56 public:
humlet 2:1ae8bb468515 57
humlet 2:1ae8bb468515 58 uint32_t msgCnt;
humlet 2:1ae8bb468515 59
humlet 0:a3a07eb0c1dd 60 /// Create a receiver
humlet 1:3904ef8c606e 61 /// @parameter in: The pin the IR detector's message line is connected to
humlet 1:3904ef8c606e 62 FtControlSetReceiver(PinName in);
humlet 0:a3a07eb0c1dd 63
humlet 1:3904ef8c606e 64 /// get the last received message
humlet 1:3904ef8c606e 65 FtControlSetMessage getLastMessage()const {
humlet 1:3904ef8c606e 66 return m_lastMessage;
humlet 1:3904ef8c606e 67 };
humlet 1:3904ef8c606e 68
humlet 1:3904ef8c606e 69 /// get number of receive errors
humlet 1:3904ef8c606e 70 uint32_t getErrorCount()const {
humlet 1:3904ef8c606e 71 return m_errorCount;
humlet 1:3904ef8c606e 72 }
humlet 1:3904ef8c606e 73
humlet 1:3904ef8c606e 74 /// hook a call back into the receiver ISR e.g. for sending a RTOS message.
humlet 0:a3a07eb0c1dd 75 /// called on each update or receive error
humlet 0:a3a07eb0c1dd 76 void setCallBack(const FunctionPointer& callBack) {
humlet 0:a3a07eb0c1dd 77 m_callBack=callBack;
humlet 0:a3a07eb0c1dd 78 };
humlet 0:a3a07eb0c1dd 79 };
humlet 0:a3a07eb0c1dd 80
humlet 0:a3a07eb0c1dd 81
humlet 0:a3a07eb0c1dd 82 #endif
humlet 0:a3a07eb0c1dd 83
humlet 0:a3a07eb0c1dd 84
humlet 0:a3a07eb0c1dd 85
humlet 0:a3a07eb0c1dd 86
humlet 0:a3a07eb0c1dd 87
humlet 0:a3a07eb0c1dd 88
humlet 0:a3a07eb0c1dd 89