Sivusto ei tue käyttämääsi selainta. Suosittelemme selaimen päivittämistä uudempaan versioon.

Bash scripting

I may write a Python version of scanning the DiscoHAT I/O pins when time permits. Here is the script in bash that worked for the lamp switch on/off and for the doorbell.

#!/bin/bash

LAMP=`/usr/local/bin/gpio read 7`
PREVLAMP=$LAMP
DING=`/usr/local/bin/gpio read 15`
PREVDING=$DING

while [ 1 ]; do
LAMP=`/usr/local/bin/gpio read 7`
if [ "$LAMP" != "$PREVLAMP" ]; then
  echo lamp
  python /opt/arsenik/lamp.py
fi
PREVLAMP=$LAMP
DING=`/usr/local/bin/gpio read 15`
if [ "$DING" != "$PREVDING" ]; then
  if [ "$DING" = "0" ]; then
    echo ding
    python /opt/arsenik/ding.py
  fi
fi
PREVDING=$DING
sleep 0.1
done

Python scripting

Python is called here for controlling the QLC+ through the OSC interface.

The first python script is for toggling the state of the lamp (lamp.py):

#!/usr/bin/env python

import liblo, sys

# send all messages to port 7770 on the local machine
try:
    target = liblo.Address(7770)
except liblo.AddressError, err:
    print str(err)
    sys.exit()

# send message "/foo/message1" with int, float and string arguments
liblo.send(target, "/foo/message1", 1)

The second script is for the doorbell (ding.py):

#!/usr/bin/env python

import liblo, sys

# send all messages to port 7770 on the local machine
try:
    target = liblo.Address(7770)
except liblo.AddressError, err:
    print str(err)
    sys.exit()

# send message "/foo/message1" with int, float and string arguments
liblo.send(target, "/foo/ding", 1)

As you can see it does not really matter what you send to the liblo interface as long as it is different for every button. In QLC+ you click on the button and open properties to "learn" the external OSC commands.

Controlling dbus applications

QLC+ is not the only program supporting remote commands. A very nice music player called Clementine can also be controlled in python.

Here we ask for the title and the artist:

 

import dbus

# Clementine lives on the Session bus
session_bus = dbus.SessionBus()

# Get Clementine's player object, and then get an interface from that object,
# otherwise we'd have to type out the full interface name on every method call.
player = session_bus.get_object('org.mpris.clementine', '/Player')
iface = dbus.Interface(player, dbus_interface='org.freedesktop.MediaPlayer')

# Call a method on the interface
metadata = iface.GetMetadata()
print metadata["title"]
print metadata["artist"]

 

 

We could also ask it to play the next tune by:

 

iface.Next()

 

Developer

Karri Kaksonen

info@DiscoHAT.com