Multiple Keyboards with RaspberryPi and OSC

Aus hyperdramatik
Zur Navigation springen Zur Suche springen

Installation

Python3

$ sudo apt-get update
$ sudo apt-get install python3 python3-dev python3-pip gcc

Python EvDev

Über das Python EvDev Package können wir auf Linux' input event interface zugreifen.
$ sudo apt-get install raspberrypi-kernel-headers
$ sudo pip install evdev

Python OSC

$sudo apt-get install python-osc

Code

import sys
import evdev
import argparse
import time
import os

from pythonosc import osc_message_builder
from pythonosc import udp_client
from threading import Thread


ip = "192.168.234.102"
port = 12345
station = "crisprlogin"


class MyThread(Thread):
    def __init__(self, val):
        Thread.__init__(self)
        self.val = val
        self.s = ""
    def run(self):
        print("starting thread:")
        print(self.val.fn)
        while(1):
            for event in self.val.read_loop():
                if event.type == evdev.ecodes.EV_KEY:
                    if(evdev.categorize(event).keystate):
                        if(evdev.categorize(event).keycode == "KEY_ENTER"):
                            client = udp_client.SimpleUDPClient(ip, port)
                            client.send_message("/"+station+self.val.fn[self.va$
                            print ("send osc message id#", end='')
                            print (self.s)
                            self.s=""
                        else:
                            self.s = self.s + evdev.categorize(event).keycode[4]


if __name__ == "__main__":
    devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
    for device in devices:
        mythread = MyThread(evdev.InputDevice(device.fn))
        mythread.start()
        time.sleep(0.1)

  • Noch herausfinden: Python findet die Headers nicht, wenn man das Script auf dem Desktop speichert. Speichert man sein Script in Documents, läuft es problemlos...

Script beim Start des Raspis ausführen

http://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/


  • Das Raspi soll natürlich auch nicht in Ruhezustand gehen... Die Lösung:

Open a root terminal in raspberry Pi. Now you need to edit your script that's starting X. In the default build with lightdm.

Open "lightdm.conf" file located in,

/etc/lightdm/lightdm.conf

Add below line in to SeatDefault section.

[SeatDefaults]

xserver-command=X -s 0 -dpms

Restart your Raspberry Pi.