Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
FtControlSetReceiver.h
- Committer:
- humlet
- Date:
- 2013-03-18
- Revision:
- 2:1ae8bb468515
- Parent:
- 1:3904ef8c606e
- Child:
- 3:038f86bac6cc
File content as of revision 2:1ae8bb468515:
#ifndef FTCONTROLSETRECEIVER_H
#define FTCONTROLSETRECEIVER_H
#include "FtControlSetMessage.h"
#include "InterruptIn.h"
#include "FunctionPointer.h"
#include "Timeout.h"
using namespace mbed;
/// Receiver interface for the fischertechnik IR control set
///
/// 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>
/// The ft IR remote control uses some kind of <A HREF="http://www.sbprojects.com/knowledge/ir/rcmm.php"> RC-MM Protocol </A>.
/// When any of the controls is applied the remote control sends updates at a rate of 1/90ms~12Hz.
/// Each message delivers the complete remote control status encoded into 30 bits.
/// The structure of the message is can be seen in FtControlSetMessage.h.
/// The protocol uses Pulse Distance Modulation (PDM) with two bits (dibit) per pulse, hence four different
/// distances. A transmission consists of 16 pulses (15 distances) for a total of 30 bits.
///
/// 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 onnected directly to the mebed: GND, VCC->3.3V and the signal line to any of the numbered mbed gpios.
class FtControlSetReceiver
{
InterruptIn m_pulseIRQ;
uint32_t m_rxBuffer;
uint32_t m_nPulses;
uint32_t m_timeOfLastEdge;
uint8_t m_nOnes;
uint32_t m_errorCount;
uint8_t m_nGracefullyIgnoredErrors;
FtControlSetMessage m_lastMessage;
FunctionPointer m_callBack;
Timeout m_messageTimeout;
Timeout m_receiveTimeout;
//static const uint32_t c_pulseLengthLimits[5];
static const uint32_t c_pulseLengthDelta = 100;//101;
static const uint32_t c_pulseLengthOffset = 795;//793;
static const uint32_t c_maxPulseTime = c_pulseLengthOffset+7*c_pulseLengthDelta/2;
static const uint32_t c_messageTimeout[2];
static const uint8_t c_errorsToBeGracefullyIgnored = 3;
void pulseISR();
void messageTimeoutISR();
void recoverISR();
void messageReceived(FtControlSetMessage::Status status);
void handleReceiveError();
public:
uint32_t msgCnt;
/// Create a receiver
/// @parameter in: The pin the IR detector's message line is connected to
FtControlSetReceiver(PinName in);
/// get the last received message
FtControlSetMessage getLastMessage()const {
return m_lastMessage;
};
/// get number of receive errors
uint32_t getErrorCount()const {
return m_errorCount;
}
/// hook a call back into the receiver ISR e.g. for sending a RTOS message.
/// called on each update or receive error
void setCallBack(const FunctionPointer& callBack) {
m_callBack=callBack;
};
};
#endif