Using Luxafor with Linux

xster
xster
Jan 30, 2016 · 1 min read

Luxafor makes a nice busy status indicator light for the office. Unfortunately it only provides software for Windows and Mac. But it’s not hard at all to get it working on Ubuntu with PyUSB.

1- You need PyUSB installed

pip install pyusb

2- PyUSB basically lets you do anything you want with the USB device including some pretty dangerous stuff so it’s naturally open to super users. It’d be really annoying to have to sudo every light control though, so we’ll open this one particular device to your user. Create a luxafor.rules file in /etc/udev/rules.d/ and put in:

SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="f372" MODE="0664", OWNER="[your user name]"

3- Reload udev with

sudo udevadm control --reload
sudo udevadm trigger

4- Create a Python script, say light.py, to make this easier to control

import argparse
import usb.core
def main():parser = argparse.ArgumentParser(description='Change Luxafor colour')
parser.add_argument('colour', choices=['green', 'yellow', 'red', 'blue', 'white', 'off'], help='colour to change to')
args = parser.parse_args()
colour_codes = {'green': 71, 'yellow': 89, 'red': 82, 'blue':66, 'white': 87, 'off': 79}
dev = usb.core.find(idVendor=0x04d8, idProduct=0xf372)if dev is None:
print('Not connected')
return
try:
dev.detach_kernel_driver(0)
except usb.core.USBError:
pass
try:
dev.set_configuration()
except usb.core.USBError:
print("Did you give Luxafor USB permission to your user?")
return
dev.set_configuration()
dev.write(1, [0, 0])
dev.write(1, [0, colour_codes[args.colour]])
if __name__ == '__main__':
main()

5- Control the colour with

python light.py green

xster

Collection of tech tips and learnings

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store