-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,039 additions
and
496 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* Berryboot -- CEC listener thread | ||
* | ||
* Copyright (c) 2012, Floris Bos | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
|
||
#include "ceclistener.h" | ||
#include <QDebug> | ||
#include <QWSServer> | ||
|
||
#ifdef RASPBERRY_CEC_SUPPORT | ||
extern "C" { | ||
#include <interface/vmcs_host/vc_cecservice.h> | ||
#include <interface/vchiq_arm/vchiq_if.h> | ||
#include <interface/vmcs_host/vc_tvservice.h> | ||
} | ||
#endif | ||
|
||
int CecListener::keyPressed = 0; | ||
|
||
CecListener::CecListener(QObject *parent) : | ||
QThread(parent) | ||
{ | ||
keyPressed=0; | ||
} | ||
|
||
CecListener::~CecListener() | ||
{ | ||
_waitcond.wakeAll(); | ||
if (!wait(2000)) | ||
{ | ||
qDebug() << "CEC thread did not stop gracefully"; | ||
terminate(); | ||
} | ||
} | ||
|
||
/* Not sure if any of the vchi functions are blocking, but running them in a seperate thread just in case */ | ||
void CecListener::run() | ||
{ | ||
#ifdef RASPBERRY_CEC_SUPPORT | ||
VCHI_INSTANCE_T vchiq; | ||
VCHI_CONNECTION_T *conn; | ||
QMutex mutex; | ||
mutex.lock(); | ||
|
||
qDebug() << "CecListener thread started"; | ||
if (vchi_initialise(&vchiq)) | ||
{ | ||
qDebug() << "Error during vchi_initialise()"; | ||
return; | ||
} | ||
if (vchi_connect(NULL, 0, vchiq)) | ||
{ | ||
qDebug() << "Error connecting to vchi"; | ||
return; | ||
} | ||
if (vc_vchi_tv_init(vchiq, &conn, 1)) | ||
{ | ||
qDebug() << "Error during vc_vchi_tv_init()"; | ||
return; | ||
} | ||
TV_GET_STATE_RESP_T tvstate; | ||
vc_tv_get_state(&tvstate); | ||
|
||
if (!(tvstate.state & (VC_HDMI_STANDBY | VC_HDMI_HDMI))) | ||
{ | ||
qDebug() << "Not in HDMI mode"; | ||
return; | ||
} | ||
|
||
vc_vchi_cec_init(vchiq, &conn, 1); | ||
vc_cec_set_osd_name("PINN"); | ||
vc_cec_register_callback(_cec_callback, this); | ||
|
||
qDebug() << "CecListener done initializing"; | ||
/* Wait until we are signaled to quit */ | ||
_waitcond.wait(&mutex); | ||
|
||
vc_vchi_cec_stop(); | ||
#endif | ||
} | ||
|
||
/*static*/ void CecListener::_cec_callback(void *userptr, uint32_t reason, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4) | ||
{ | ||
static_cast<CecListener *>(userptr)->cec_callback(reason, param1, param2, param3, param4); | ||
} | ||
|
||
void CecListener::cec_callback(uint32_t reason, uint32_t param1, uint32_t, uint32_t, uint32_t) | ||
{ | ||
#ifdef RASPBERRY_CEC_SUPPORT | ||
if (CEC_CB_REASON(reason) == VC_CEC_BUTTON_PRESSED) | ||
{ | ||
int c = 0; | ||
int cec_buttoncode = CEC_CB_OPERAND1(param1); | ||
keyPressed=1; | ||
|
||
emit keyPress(cec_buttoncode); | ||
} | ||
#else | ||
qDebug() << "CEC:" << reason << param1; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef CECLISTENER_H | ||
#define CECLISTENER_H | ||
|
||
/* Berryboot -- CEC handling thread | ||
* | ||
* Copyright (c) 2012, Floris Bos | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <QThread> | ||
#include <QWaitCondition> | ||
#include <QMutex> | ||
#include <stdint.h> | ||
|
||
|
||
|
||
class CecListener : public QThread | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit CecListener(QObject *parent = 0); | ||
virtual ~CecListener(); | ||
static int hasKeyPressed() {return(keyPressed);} | ||
static int clearKeyPressed() {keyPressed=0;} | ||
|
||
signals: | ||
void keyPress(int key); | ||
public slots: | ||
|
||
protected: | ||
virtual void run(); | ||
static void _cec_callback(void *userptr, uint32_t reason, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4); | ||
void cec_callback(uint32_t reason, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4); | ||
|
||
QWaitCondition _waitcond; | ||
static int keyPressed; | ||
}; | ||
|
||
#endif // CECLISTENER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.