summarylogtreecommitdiffstats
path: root/k780swap
blob: ae975aa60617bda693c68455dcc1c06e202a2c63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/env python
# switch k780 logitech keyboard Fn keys
import sys
import time
import usb.core

unifying=0xc52b
activate = len(sys.argv) == 1

IFACE=2
# find keyboard
dev = usb.core.find(idVendor=0x046d, idProduct=unifying)

if dev is None:
  raise ValueError('Keyboard not found')

reattach = dev.is_kernel_driver_active(IFACE)
if reattach:
    dev.detach_kernel_driver(IFACE)

# set the right interface

cfg = dev[0]
iface = cfg[(IFACE,0)]

dev.set_interface_altsetting(iface)

# send frame

ON=[16, 2, 12, 26, 0, 0, 0]
OFF=[16, 2, 12, 28, 1, 0, 0]

dev.ctrl_transfer(33, 9, 528, 2, ON if activate else OFF)

# have to wait (Why ??) and sometimes repeat !

if activate:
    time.sleep(10)
else:
    time.sleep(1)

dev.reset()
if reattach:
    dev.attach_kernel_driver(IFACE)