Skip to content

Commit

Permalink
Fix writing keymap and use logging
Browse files Browse the repository at this point in the history
  • Loading branch information
david0 committed Nov 20, 2020
1 parent bfb5702 commit 6e3a54c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ USE ON YOUR OWN RISK.

./remap.py keymaps/taurus_k320


After running I have to activate the profile on my keyboard using `Fn`+ `MR`(F12)
32 changes: 21 additions & 11 deletions remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
import hid # pip install hidapi
from struct import pack, unpack
import csv
import logging

VENDOR_ID = 0x2f68
PRODUCT_ID = 0x0082 # DURGOD Taurus K320:
TIMEOUT = 200

KEEPALIVE = b"\x00\x03\x07\xE3"
RESET = b"\x00\x03\x05\x80\x04\xff".ljust(64, b"\x00")
KEEPALIVE = b"\x03\x07\xE3"
RESET = b"\x03\x05\x80\x04\xff".ljust(64, b"\x00")

N = 8
WRITE = b"\x00\x03\x05\x81\x0f\x00\x00"
WRITE_RESP = b"\x83\x05\x81\x0f\x00\x00\x00h"
WRITE = b"\x03\x05\x81\x0f"
WRITE_RESP = b"\x83\x05\x81\x0f"

SAVE = b"\x00\x03\x05\x82"
DISCONNECT = b"\x00\x03\x19\x88" # Disconnect? is sent on application exit
SAVE = b"\x03\x05\x82"
DISCONNECT = b"\x03\x19\x88" # Disconnect? is sent on application exit

KEYNAMES = dict()
KEYNAMES[0x28] = 'Enter'
Expand Down Expand Up @@ -48,6 +49,10 @@
KEYNAMES[0x47] = 'Roll'
KEYNAMES[0x48] = 'Roll'


logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger("wire")

# f1-f12
for i in range(0,12):
KEYNAMES[0x3A+i] = "f%d" % (i+1)
Expand All @@ -68,16 +73,19 @@ def connect():


def send(device, data):
if device.write(data.ljust(64, b"\x00")) < 0:
logger.info("send %s", tohex(data))
if device.write(b'\x00' + data.ljust(64, b"\x00")) < 0:
raise "Write failed"

resp = device.read(64, timeout_ms=500)
print("<-", end="")
resp = bytearray(resp).rstrip(b'\x00')
print(resp)
logger.info("recv %s", tohex(resp))
return resp


def tohex(data):
return ' '.join(map(lambda x: "%02x" % x, data))


def reprogram(keymap):
device = connect()
Expand All @@ -86,8 +94,8 @@ def reprogram(keymap):
send(device, RESET)

for i, d in enumerate(keymap):
resp = send(device, b''.join([WRITE, pack('b', i), d]))
if resp != bytearray(WRITE_RESP):
resp = send(device, b''.join([WRITE, pack('b', i), b'\x00\x00', d]))
if resp[0:4] != WRITE_RESP:
raise Exception(f"Bad response f{resp}")

send(device, SAVE)
Expand All @@ -114,10 +122,12 @@ def print_keymap(keymap):

print("")


def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i:i + n]


def read_keymap(path):
keymap = []
with open(path) as f:
Expand Down

0 comments on commit 6e3a54c

Please sign in to comment.