def __init__(self):
     cec.init()
     self.devices = cec.list_devices()
     self.rec_controller = ReceiverController(self.devices)
     self.tv_controller = TvController(self.devices[0], self.rec_controller)
     self.player_callback = None
     cec.add_callback(self.__event_callback, cec.EVENT_COMMAND)
     cec.add_callback(log_cb, cec.EVENT_LOG)
예제 #2
0
파일: tv.py 프로젝트: philburr/slideshow
    def __init__(self):
        cec.init()
        # Force TV to turn on/off
        self.scheduled_state = self.__should_be_on()
        self.current_state = not self.scheduled_state

        self.tv = cec.Device(cec.CECDEVICE_TV)
        cec.add_callback(self.__response_handler, cec.EVENT_COMMAND)

        self.running = True
        self.thr = threading.Thread(target = self.__check_tv)
        self.thr.start()
def init():
    cec.init()
    global tv
    tv = cec.Device(0)
    global on
    try:
        if tv.is_on():
            on = 1  # avoids polling the tv all the time and causing libCEC errors.
        else:
            on = 0
    except:
        on = 0
    cec.add_callback(listener, cec.EVENT_LOG)
예제 #4
0
 def init_cec(self):
     """Method to init cec adapter. Return True if cec initiated successfully"""
     if (self.initiated): return
     adapter = cec.list_adapters()
     if len(adapter) >= 1:
         try:
             cec.init()
             self.adapter = adapter.pop()
             self.devices = cec.list_devices()
             self.initiated = True
             cec.add_callback(cb, cec.EVENT_ALL & ~cec.EVENT_LOG)
             cec.add_callback(log_cb, cec.EVENT_LOG)
         except:
             self.initiated = False
예제 #5
0
def main():
    """ Inits cec and listens for remote keystrokes
    """
    print('Initializing CEC, please wait...')
    print('If this takes too long ensure the device is not already in use')
    cec.init()
    cec.add_callback(print_keycode, 2)
    print('CEC device initialized, press remote keys or hit ^C to quit')

    try:
        while True:
            sleep(1)
    except KeyboardInterrupt:
        exit(0)
예제 #6
0
 def init_cec(self):
     """Method to init cec adapter. Return True if cec initiated successfully"""
     if self.initiated:
         return
     adapter = cec.list_adapters()
     if len(adapter) >= 1:
         try:
             cec.init()
             self.adapter = adapter.pop()
             self.devices = cec.list_devices()
             self.initiated = True
             cec.add_callback(cb, cec.EVENT_ALL & ~cec.EVENT_LOG)
             cec.add_callback(log_cb, cec.EVENT_LOG)
         except:
             self.initiated = False
예제 #7
0
# Callback test; just to see if callbacks are working.

from __future__ import print_function
from time import sleep
import cec

print("Loaded CEC from", cec.__file__)

def cb(event, *args):
    print("Got event", event, "with data", args)

# arguments: iils
def log_cb(event, level, time, message):
    print("CEC Log message:", message)

cec.add_callback(cb, cec.EVENT_ALL & ~cec.EVENT_LOG)
cec.add_callback(log_cb, cec.EVENT_LOG)
print("Callback added")
sleep(2)

if cec.HAVE_CEC_ADAPTER_DESCRIPTOR:
    print("CEC has cec_adapter_descriptor");
else:
    print("CEC does not have cec_adapter_descriptor");

print("Initializing CEC library")
cec.init()

print("Creating Device object for TV")
tv = cec.Device(0)
print("Turning on TV")
예제 #8
0
 def configure_cec(self):
     self.turn_off_tvservice()
     cec.init()
     cec.add_callback(self.cec_callback, cec.EVENT_ALL)
예제 #9
0

def cec_key_press(event, cmd, value, *args):
    global order, player

    print(cmd, value)
    if value > 0:
        if cmd == 1:
            order = order - 1
        if cmd == 2:
            order = order + 1
        t_channel_stopper.set()
        player.quit()


def restart_player(*args):
    global player

    player = OMXPlayer("udp://localhost:1234")
    player.exitEvent = restart_player


cec.init()
cec.add_callback(cec_key_press, cec.EVENT_KEYPRESS)

t_channel_stopper = threading.Event()
t_channel = threading.Thread(target=stream_channel, args=(t_channel_stopper, ))
t_channel.start()

player = OMXPlayer("udp://localhost:1234")
player.exitEvent = restart_player
예제 #10
0
                print("Ignoring key up event")
                return
        last_event = (code, ts, duration)
        
        keysym = KEYMAP.get(code)
        if keysym is None:
            print(f"Unrecognized code: {code}")
            return
        print("executing keysym " + keysym)
        subprocess.check_output(["xdotool", "key", keysym])
    except Exception as e:
        print("Error executing command: " + str(e))


if __name__ == "__main__":
    try:
        subprocess.check_output(["xdotool", "--help"])
    except Exception as e:
        print("Impossible to call xdotool: " + str(e))
        sys.exit(1)
    cec.init()
    cec.add_callback(handler, cec.EVENT_KEYPRESS)
    os.environ["DISPLAY"] = ":0"
    os.environ["XAUTHORITY"] = "/home/pi/.Xauthority"
    print("Remote control python script running")
    httpd = HTTPServer(('', 8484), Server)
    httpd.serve_forever()
    


예제 #11
0
 def setupUi(self, Form):
     self.kanavalista = []
     self.nytsoi = []
     self.laskuri = 0
     self.leffaToistuu = False  #kun leffa pyörii
     Form.setObjectName("Form")
     Form.resize(400, 300)
     Form.setStyleSheet("background-color:rgb(41, 85, 74); border: none;")
     self.label = QtWidgets.QLabel(Form)
     self.label.setGeometry(QtCore.QRect(30, 10, 261, 31))
     self.label.setStyleSheet("color: rgb(255, 255, 255);\n"
                              "font: 26pt \"Ubuntu Mono\";")
     self.label.setObjectName("label")
     self.listWidgetKanavalista = QtWidgets.QListWidget(Form)
     self.listWidgetMovielista = QtWidgets.QListWidget(Form)
     self.listWidgetMovielista.setStyleSheet(
         "QListView{background-color:rgb(41, 85, 74); font: 22pt \"Ubuntu Mono\"; color: white;}QListView::item:selected{background-color: rgb(75,153,134); color: yellow;};"
     )
     self.listWidgetMovielista.setHorizontalScrollBarPolicy(
         QtCore.Qt.ScrollBarAlwaysOff)
     self.listWidgetMovielista.hide()
     self.listWidgetKanavalista.setObjectName("listWidget")
     self.listWidgetKanavalista.setViewMode(QtWidgets.QListWidget.IconMode)
     self.retranslateUi(Form)
     QtCore.QMetaObject.connectSlotsByName(Form)
     self.listWidgetKanavalista.setStyleSheet(
         "QListView{font: 16pt \"Ubuntu Mono\"; color: white;}QListView::item:selected{background-color: rgb(75,153,134); color: yellow;}"
     )
     self.listWidgetKanavalista.setVerticalScrollBarPolicy(
         QtCore.Qt.ScrollBarAlwaysOff)
     self.label.move(20, 0)
     monitor = QtWidgets.QDesktopWidget().screenGeometry(
         0)  # Jos useampi monitori käytössä
     self.listWidgetKanavalista.setGeometry(
         QtCore.QRect(100, 30,
                      monitor.width() - 100,
                      monitor.height() - 10))
     self.listWidgetMovielista.setGeometry(
         QtCore.QRect(100, 30,
                      monitor.width() - 100,
                      monitor.height() - 30))
     Form.move(monitor.left(), monitor.top())
     Form.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint
                         | QtCore.Qt.CustomizeWindowHint
                         | QtCore.Qt.FramelessWindowHint)
     Form.showMaximized()
     self.listWidgetKanavalista.setIconSize(QtCore.QSize(200, 120))
     self.listWidgetKanavalista.setResizeMode(QtWidgets.QListWidget.Adjust)
     self.listWidgetKanavalista.setAttribute(
         QtCore.Qt.WA_TranslucentBackground)
     self.listWidgetKanavalista.clicked['QModelIndex'].connect(
         self.klikattuKanava)
     self.listWidgetKanavalista.activated['QModelIndex'].connect(
         self.klikattuKanava)
     self.listWidgetMovielista.clicked['QModelIndex'].connect(
         self.klikattuMovie)
     self.listWidgetMovielista.activated['QModelIndex'].connect(
         self.klikattuMovie)
     self.lueKanavat()
     self.listWidgetKanavalista.setFocus()
     self.listWidgetKanavalista.setCurrentRow(0)
     cec.add_callback(self.nappainPainettu, cec.EVENT_KEYPRESS)
     cec.init()
     self.valvoTimer = QtCore.QTimer()
     self.valvoTimer.setInterval(500)
     self.valvoTimer.timeout.connect(self.recurring_timer)
     self.valvoTimer.start()

def get_random_number():
    """Fetch data from the ANU Quantum Random Numbers JSON API"""
    url = URL + '?' + urlencode({
        'type': 'uint16',
        'length': 1,
        'size': 1,
    })
    data = json.loads(urlopen(url, timeout=5).read())
    assert data['success'] is True
    return data['data'][0]


if __name__ == "__main__":
    cec.add_callback(keyPressEventHandler, 2)
    cec.init()
    cec.set_active_source()

    subprocess.call(['figlet', '-c', 'Namechooser\n3000'])
    while (True):
        while (not buttonPressed):
            pass

        keep_spinning = True
        sys.stdout.write("Splitting photon beam... ")

        t = threading.Thread(target=spin_bar)
        t.start()
        try:
            rnm = get_random_number()
예제 #13
0
파일: cb_test.py 프로젝트: yawad/python-cec
from time import sleep
import cec

print("Loaded CEC from", cec.__file__)


def cb(event, *args):
    print("Got event", event, "with data", args)


# arguments: iils
def log_cb(event, level, time, message):
    print("CEC Log message:", message)


cec.add_callback(cb, cec.EVENT_ALL & ~cec.EVENT_LOG)
cec.add_callback(log_cb, cec.EVENT_LOG)
print("Callback added")
sleep(2)

if cec.HAVE_CEC_ADAPTER_DESCRIPTOR:
    print("CEC has cec_adapter_descriptor")
else:
    print("CEC does not have cec_adapter_descriptor")

print("Initializing CEC library")
cec.init()

print("Creating Device object for TV")
tv = cec.Device(0)
print("Turning on TV")
예제 #14
0
# callback for HDMI-CEC
def cec_cb(*args):
    if len(args) != 2:
        return  # only respond to the right command

    source = args[0]
    params = args[1]

    if params["opcode"] != 0x82:
        return  # only respond to 0x82, which is "active source"

    logging.info(f"received CEC from {source} with params {params}")

    device = cec_devices[source]
    logging.info(f"device {device.osd_string} became active")

    # activate seq if exists
    if device.osd_string in CEC_SEQUENCES:
        CEC_SEQUENCES[device.osd_string]()


if use_cec:
    cec.add_callback(cec_cb, cec.EVENT_ALL)


@app.route("/")
def index():
    context = {"picture_modes": TV.get_picture_mode()}
    return render_template("index.html", **context)
def setupCECCallback():
    GPIO.setup(36, GPIO.OUT)
    cec.init('RPI')
    cec.add_callback(cb, cec.EVENT_ALL)