#include "lirc.h" #include #include #include "lirc_client.h" #include #include /** * Constructor. Connects to the LIRCd socket */ Lirc::Lirc(Config* conf):QObject(){ config = conf; sockfd = lirc_init("irfc",1); if(sockfd != -1){ qDebug("LIRCD socket opened with descriptor %d",sockfd); //make non blocking fcntl(sockfd,F_SETFL,O_NONBLOCK); //attach notifier to socket sn = new QSocketNotifier( sockfd, QSocketNotifier::Read); QObject::connect( sn, SIGNAL(activated(int)), this, SLOT(dataReceived()) ); }else{ qWarning("Opening lircd socket failed - no remote control support"); } }; /** * Deconstructor. Deinitializes the lirc library. */ Lirc::~Lirc(){ lirc_deinit(); ::close(sockfd); qDebug("lirc destructed"); } /** * SLOT. Gets called on new data at the socket. Reads all pending data with * lirc_nextcode(). Calls checkButton(). */ void Lirc::dataReceived(){ char *code; while(lirc_nextcode(&code)==0){ if(code==NULL) return; checkButton(QString(code)); free(code); } } /** * Emits the apropriate signals for pressed LIRC buttons */ void Lirc::checkButton(QString code){ int rpt = code.section(' ',1,1).toInt(NULL,16); QString btn = code.section(' ',2,2); QString act = config->getLIRCbutton(btn); /* if( rpt % config->getOption("irrepeat").toInt() != 0){ //skip repeat return; } */ qDebug("repeat %d",rpt); if(rpt > 0 && rpt <= config->getOption("irrepeat").toInt() ){ //skip first repeat(s) to avoid jumps on first touch return; } if(act.isEmpty()){ qDebug("LIRC button [%s]: no action defined",btn.latin1()); return; } qDebug("LIRC button [%s]: %s",btn.latin1(),act.latin1()); if(act == "down"){ emit move(1); }else if(act == "up"){ emit move(-1); }else if(act == "fastup"){ emit move(-5); }else if(act == "fastdown"){ emit move(5); }else if(act == "back"){ emit back(); }else if(act == "select"){ emit select(); } }