Skip to content

Instantly share code, notes, and snippets.

@0x5742
Created July 8, 2015 17:43
Show Gist options
  • Select an option

  • Save 0x5742/f27c26468516f5fcbe59 to your computer and use it in GitHub Desktop.

Select an option

Save 0x5742/f27c26468516f5fcbe59 to your computer and use it in GitHub Desktop.
quick-and-dirty interface for the Griffin AirClick RF remote
#!/usr/bin/env python
import struct, os, subprocess
"""
030200?? - buttons that are currently down
01 play/pause
02 increase volume
04 decrease volume
08 next
10 previous
??000000 - same thing, apparently, but with some bit twiddling done to it.
(seems like this should indicate a change in state, but it doesn't)
"""
device = '/dev/hidraw4'
scriptdir = os.path.expanduser('~/.airclick/scripts')
scripts = [os.path.join(scriptdir, b) for b in 'play vol+ vol- next prev'.split()]
def action(btn, state):
what = ['release', 'press'][state]
os.chdir(scriptdir)
subprocess.call([scripts[btn], what])
def main():
f = open(device, 'rb')
states = [False, False, False, False, False]
while True:
# Should match 030200xxyy000000
magic, bmask = struct.unpack('>HxB4x', f.read(8))
assert magic == 0x0302, "Protocol error"
for btn in range(5):
bit = 1 << btn
new = bool(bmask & bit)
if states[btn] != new:
states[btn] = new
action(btn, new)
if __name__ == '__main__': main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment