rf remote mumbi added

This commit is contained in:
Simon Stürz 2013-12-31 02:11:18 +01:00
parent 514323ce5d
commit 4f3d1c7f83
4 changed files with 109 additions and 47 deletions

View File

@ -22,9 +22,13 @@ void Gpio::run()
int timeout = 3000; int timeout = 3000;
char buf[64]; char buf[64];
bool enabled = true; bool enabled = true;
m_mutex.lock();
m_enabled = true;
m_mutex.unlock();
while(enabled){ while(enabled){
memset((void*)fdset, 0, sizeof(fdset)); memset((void*)fdset, 0, sizeof(fdset));
fdset[0].fd = STDIN_FILENO; fdset[0].fd = STDIN_FILENO;
@ -46,7 +50,6 @@ void Gpio::run()
read(fdset[1].fd, buf, 64); read(fdset[1].fd, buf, 64);
emit pinInterrupt(); emit pinInterrupt();
} }
m_mutex.lock(); m_mutex.lock();
enabled = m_enabled; enabled = m_enabled;
m_mutex.unlock(); m_mutex.unlock();

View File

@ -30,7 +30,7 @@ Radio433::~Radio433()
void Radio433::sendData(QList<int> rawData) void Radio433::sendData(QList<int> rawData)
{ {
//first we have to disable our receiver, to prevent reading the hive signal it self //first we have to disable our receiver, to prevent reading this signal
m_receiver->stop(); m_receiver->stop();
m_transmitter->setValue(LOW); m_transmitter->setValue(LOW);
@ -43,7 +43,7 @@ void Radio433::sendData(QList<int> rawData)
delayMicroseconds(delay); delayMicroseconds(delay);
} }
// reenable it // re-enable it
m_receiver->start(); m_receiver->start();
} }
@ -92,6 +92,7 @@ void Radio433::handleInterrupt()
// filter nois // filter nois
if (m_duration > 5000 && m_duration > m_timings[0] - 200 && m_duration < m_timings[0] + 200) { if (m_duration > 5000 && m_duration > m_timings[0] - 200 && m_duration < m_timings[0] + 200) {
m_repeatCount++; m_repeatCount++;
m_changeCount--; m_changeCount--;
@ -119,22 +120,10 @@ void Radio433::handleInterrupt()
}else if(m_duration > 5000){ }else if(m_duration > 5000){
m_changeCount = 0; m_changeCount = 0;
} }
if (m_changeCount > RC_MAX_CHANGES) { if (m_changeCount >= RC_MAX_CHANGES+1) {
m_changeCount = 0; m_changeCount = 0;
m_repeatCount = 0; m_repeatCount = 0;
} }
m_timings[m_changeCount++] = m_duration; m_timings[m_changeCount++] = m_duration;
m_lastTime = currentTime; m_lastTime = currentTime;
} }
void Radio433::enableReceiver()
{
qDebug() << "starting receiver";
m_receiver->start();
}
void Radio433::disableReceiver()
{
m_receiver->stop();
qDebug() << "receiver disabeld.";
}

View File

@ -32,10 +32,6 @@ private:
int micros(); int micros();
void delayMicroseconds(int pulseLength); void delayMicroseconds(int pulseLength);
void enableReceiver();
void disableReceiver();
private slots: private slots:
void handleInterrupt(); void handleInterrupt();

View File

@ -21,7 +21,7 @@ QList<DeviceClass> RfSwitch::supportedDevices() const
QList<DeviceClass> ret; QList<DeviceClass> ret;
DeviceClass deviceClassRfRemote(QUuid::createUuid()); DeviceClass deviceClassRfRemote(QUuid::createUuid());
deviceClassRfRemote.setName("RF Remote"); deviceClassRfRemote.setName("RF Remote Mumba");
QVariantList deviceParams; QVariantList deviceParams;
QVariantMap channelParam; QVariantMap channelParam;
@ -91,14 +91,88 @@ QString RfSwitch::pluginName() const
void RfSwitch::dataReceived(QList<int> rawData) void RfSwitch::dataReceived(QList<int> rawData)
{ {
qDebug() << "data received from Radio433" << rawData; // filter right here a wrong signal length
if(rawData.length() != 49){
return;
}
int delay = rawData.first()/31;
QByteArray binCode;
// new Remote -> average 314
if(delay > 300 && delay < 400){
// go trough all 48 timings (without sync signal)
for(int i = 1; i <= 48; i+=2 ){
int div;
int divNext;
// if short
if(rawData.at(i) < 700){
div = 1;
}else{
div = 3;
}
// if long
if(rawData.at(i+1) < 700){
divNext = 1;
}else{
divNext = 3;
}
// _
// if we have | |___ = 0 -> in 4 delays => 1000
// _
// if we have ___| | = 1 -> in 4 delays => 0001
if(div == 1 && divNext == 3){
binCode.append('0');
}else if(div == 3 && divNext == 1){
binCode.append('1');
}else{
return;
}
}
}
qDebug() << "bincode" << binCode;
// get the channel of the remote signal (5 channels, true=1, false=0)
QList<bool> group;
for(int i = 1; i < 10; i+=2){
if(binCode.at(i-1) == '0' && binCode.at(i) == '1'){
group << false;
}else if(binCode.at(i-1) == '0' && binCode.at(i) == '0'){
group << true;
}else {
return;
}
}
//qDebug() << "group" << group;
// get the button letter
QString button;
QByteArray buttonCode = binCode.mid(10,10);
qDebug() << "Buttoncode -> " << buttonCode;
if(buttonCode == "0001010101"){
button = "A";
}else if(buttonCode == "0100010101"){
button = "B";
}else if(buttonCode == "0101000101"){
button = "C";
}else if(buttonCode == "0101010001"){
button = "D";
}else if(buttonCode == "0101010100"){
button = "E";
}else{
return;
}
// TODO: Lets assume we found a device of class "deviceClassRfRemote"
DeviceClass deviceClassRfRemote = supportedDevices().first(); DeviceClass deviceClassRfRemote = supportedDevices().first();
// TODO: Lets assume we received group "1000" // // TODO: Lets assume we received group "1000"
QList<bool> group; // QList<bool> group;
group << true << false << false << false << false; // group << true << false << false << false << false;
Device *device = 0; Device *device = 0;
QList<Device*> deviceList = deviceManager()->findConfiguredDevices(deviceClassRfRemote); QList<Device*> deviceList = deviceManager()->findConfiguredDevices(deviceClassRfRemote);
@ -115,12 +189,12 @@ void RfSwitch::dataReceived(QList<int> rawData)
} }
} }
if (!device) { if (!device) {
qWarning() << "couldn't find any configured device for data:" << rawData; //qWarning() << "couldn't find any configured device for data:" << rawData;
return; return;
} }
// TODO: Lets assume we received button "A" "on" // TODO: Lets assume we received button "A" "on"
QString button = "A"; // QString button = "A";
bool power = true; bool power = true;
QVariantMap params; QVariantMap params;