From cac8b5f1a4bebc1a46dc3cfd369974be24c5993e Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Wed, 30 Aug 2017 12:47:41 +0200 Subject: Move constants into class as well --- loopertrx.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'loopertrx.py') diff --git a/loopertrx.py b/loopertrx.py index cbbef1e..3296c47 100755 --- a/loopertrx.py +++ b/loopertrx.py @@ -21,19 +21,19 @@ import argparse import usb.core import usb.util -LOOPER_VID = 0x0483 -LOOPER_PID = 0x572a -ENDPOINT_IN = 0x81 -ENDPOINT_OUT = 0x01 +class USBLooper(): + VID = 0x0483 + PID = 0x572a -COMMAND_SIZE = 0xfe -COMMAND_DATA = 0xff + ENDPOINT_IN = 0x81 + ENDPOINT_OUT = 0x01 + COMMAND_SIZE = 0xfe + COMMAND_DATA = 0xff -class USBLooper(): def __init__(self): - self.dev = usb.core.find(idVendor=LOOPER_VID, idProduct=LOOPER_PID) + self.dev = usb.core.find(idVendor=self.VID, idProduct=self.PID) if not self.dev: raise FileNotFoundError("Device not found.") if self.dev.is_kernel_driver_active(0): @@ -59,35 +59,35 @@ class USBLooper(): return header def ack_data(self): - self.dev.read(ENDPOINT_IN, 32) + self.dev.read(self.ENDPOINT_IN, 32) def get_size(self): - header = self.command_header(COMMAND_SIZE, 5, 0x00, 0x01) - self.dev.write(ENDPOINT_OUT, header) - length = self.dev.read(ENDPOINT_IN, 100) + header = self.command_header(self.COMMAND_SIZE, 5, 0x00, 0x01) + self.dev.write(self.ENDPOINT_OUT, header) + length = self.dev.read(self.ENDPOINT_IN, 100) self.ack_data() if length[0] == 1: return 0 return length[1] + (length[2] << 8) + (length[3] << 16) + (length[4] << 24) def submit_data_len(self, size, tag=None): - header = self.command_header(COMMAND_SIZE, 5, 0x00, 0x00, tag) + header = self.command_header(self.COMMAND_SIZE, 5, 0x00, 0x00, tag) data_size = struct.pack('