fix spaces
This commit is contained in:
@@ -15,7 +15,7 @@ if DEBUG == True:
|
||||
index = 2
|
||||
else:
|
||||
index = 1
|
||||
activeCards = []
|
||||
activeCards = []
|
||||
|
||||
TIME = 600
|
||||
|
||||
@@ -38,16 +38,16 @@ class UsbCardReader():
|
||||
# Claim the device
|
||||
usb.util.claim_interface(self.dev, USB_IF)
|
||||
self.receivedNumber = 0
|
||||
|
||||
|
||||
cardread=threading.Thread(target=self.read)
|
||||
cardread.start()
|
||||
|
||||
|
||||
def read(self):
|
||||
global win, activeCards, db
|
||||
|
||||
|
||||
print("Waiting for card")
|
||||
receivedNumber = 0
|
||||
|
||||
|
||||
while True:
|
||||
control = None
|
||||
try:
|
||||
@@ -57,7 +57,7 @@ class UsbCardReader():
|
||||
if receivedDigit == 10:
|
||||
receivedDigit = 0
|
||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
||||
|
||||
|
||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
||||
try:
|
||||
with open('people.json', 'r') as f:
|
||||
@@ -71,12 +71,12 @@ class UsbCardReader():
|
||||
print("Card is active now")
|
||||
except Exception as e: print(e)
|
||||
receivedNumber = 0
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
time.sleep(0.001)
|
||||
|
||||
class GridRow():
|
||||
@@ -84,32 +84,32 @@ class GridRow():
|
||||
self.id = runner
|
||||
self.index = index
|
||||
self.parent = parent
|
||||
|
||||
|
||||
self.grid = Gtk.Grid()
|
||||
|
||||
|
||||
if index % 2 == 0:
|
||||
self.grid.set_name("lightgrid")
|
||||
else:
|
||||
self.grid.set_name("darkgrid")
|
||||
|
||||
|
||||
self.runid = Gtk.Label(label=str(runner), name="gridlabel")
|
||||
self.runid.set_justify(2)
|
||||
self.runid.set_width_chars(10)
|
||||
|
||||
|
||||
self.runb = Gtk.Label(label='00:00', name="gridlabel")
|
||||
self.runb.set_hexpand(1)
|
||||
|
||||
|
||||
self.grid.attach(self.runid, 0, 0, 1, 1)
|
||||
self.grid.attach(self.runb, 1, 0, 1, 1)
|
||||
|
||||
|
||||
parent.grid.attach(self.grid, 0, index, 2, 1)
|
||||
|
||||
|
||||
countdown=threading.Thread(target=self.updateTime)
|
||||
countdown.start()
|
||||
|
||||
|
||||
def printIndex(self, button):
|
||||
print(self.index)
|
||||
|
||||
|
||||
def updateTime(self):
|
||||
t = TIME
|
||||
while t >= -10:
|
||||
@@ -120,35 +120,35 @@ class GridRow():
|
||||
mins, secs = divmod(t, 60)
|
||||
timer = '{:02d}:{:02d}'.format(mins, secs)
|
||||
self.runb.set_label(timer)
|
||||
time.sleep(1)
|
||||
time.sleep(1)
|
||||
t -= 1
|
||||
if t == 10:
|
||||
if self.grid.get_name() == "lightgrid":
|
||||
self.grid.set_name("lredgrid")
|
||||
else:
|
||||
self.grid.set_name("dredgrid")
|
||||
|
||||
|
||||
GridWindow.remRow(self.parent)
|
||||
|
||||
class GridWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self, **kargs):
|
||||
super().__init__(**kargs, title='Alkator Clock')
|
||||
|
||||
|
||||
css_provider = Gtk.CssProvider()
|
||||
css_provider.load_from_file(Gio.File.new_for_path("style.css"))
|
||||
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||
|
||||
button1 = Gtk.Button(label='addrow')
|
||||
button2 = Gtk.Button(label='rmrow')
|
||||
|
||||
|
||||
button1.connect("clicked", self.arb)
|
||||
button2.connect("clicked", self.rrb)
|
||||
|
||||
|
||||
runlabel = Gtk.Label(label="ID", name="gridlabel")
|
||||
runlabel.set_justify(2)
|
||||
cntlabel = Gtk.Label(label="Countdown", name="gridlabel")
|
||||
cntlabel.set_justify(2)
|
||||
|
||||
|
||||
self.runners = []
|
||||
|
||||
self.grid = Gtk.Grid()
|
||||
@@ -162,23 +162,23 @@ class GridWindow(Gtk.ApplicationWindow):
|
||||
self.grid.attach(cntlabel, 1, 0, 2, 1)
|
||||
|
||||
self.set_child(self.grid)
|
||||
|
||||
|
||||
def arb(self, personId):
|
||||
global index
|
||||
self.runners.append(GridRow(self, personId, index))
|
||||
index += 1
|
||||
|
||||
|
||||
def rrb(self, button):
|
||||
global index
|
||||
self.remRow()
|
||||
|
||||
|
||||
def addRow(self, runner, index):
|
||||
runid = Gtk.Label(label=str(runner))
|
||||
runb = Gtk.Button(label='time_placeholder')
|
||||
|
||||
|
||||
self.grid.attach(runid, 0, index, 1, 1)
|
||||
self.grid.attach(runb, 1, index, 1, 1)
|
||||
|
||||
|
||||
def remRow(self):
|
||||
global index, activeCards
|
||||
if index > 1:
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
import usb.core
|
||||
import usb.util
|
||||
import time
|
||||
import requests
|
||||
import usb.core
|
||||
import usb.util
|
||||
import time
|
||||
import requests
|
||||
import json
|
||||
|
||||
USB_IF = 0 # Interface
|
||||
USB_TIMEOUT = 5 # Timeout in MS
|
||||
USB_VENDOR = 0xffff # Vendor-ID:
|
||||
USB_PRODUCT = 0x0035 # Product-ID
|
||||
|
||||
|
||||
USB_IF = 0 # Interface
|
||||
USB_TIMEOUT = 5 # Timeout in MS
|
||||
USB_VENDOR = 0xffff # Vendor-ID:
|
||||
USB_PRODUCT = 0x0035 # Product-ID
|
||||
|
||||
# Find the HID device by vender/product ID
|
||||
dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
|
||||
|
||||
# Get and store the endpoint
|
||||
endpoint = dev[0][(0,0)][0]
|
||||
|
||||
if dev.is_kernel_driver_active(USB_IF) is True:
|
||||
dev.detach_kernel_driver(USB_IF)
|
||||
|
||||
# Claim the device
|
||||
usb.util.claim_interface(dev, USB_IF)
|
||||
|
||||
receivedNumber = 0
|
||||
while True:
|
||||
control = None
|
||||
|
||||
try:
|
||||
# Read a character from the device
|
||||
dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
|
||||
|
||||
# Get and store the endpoint
|
||||
endpoint = dev[0][(0,0)][0]
|
||||
|
||||
if dev.is_kernel_driver_active(USB_IF) is True:
|
||||
dev.detach_kernel_driver(USB_IF)
|
||||
|
||||
# Claim the device
|
||||
usb.util.claim_interface(dev, USB_IF)
|
||||
|
||||
receivedNumber = 0
|
||||
while True:
|
||||
control = None
|
||||
|
||||
try:
|
||||
# Read a character from the device
|
||||
control = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, USB_TIMEOUT)
|
||||
# Here you have to analyze what's coming in.
|
||||
# In my case you had to check the first byte (command)
|
||||
if (control[2] != 40) & (control[2] != 0):
|
||||
# Convert ascii to a number, there's probably better ways to do so.
|
||||
receivedDigit = control[2] - 29
|
||||
|
||||
if receivedDigit == 10:
|
||||
|
||||
if receivedDigit == 10:
|
||||
receivedDigit = 0
|
||||
|
||||
|
||||
# Append the digit to the number
|
||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
||||
|
||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
||||
|
||||
# Check if the received character is CRLF
|
||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
||||
print('cardNumber:', receivedNumber)
|
||||
except KeyboardInterrupt:
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except:
|
||||
pass
|
||||
|
||||
time.sleep(0.001) # Let CTRL+C actually exit
|
||||
except:
|
||||
pass
|
||||
|
||||
time.sleep(0.001) # Let CTRL+C actually exit
|
||||
|
||||
@@ -12,7 +12,7 @@ if DEBUG == True:
|
||||
index = 2
|
||||
else:
|
||||
index = 1
|
||||
activeCards = []
|
||||
activeCards = []
|
||||
|
||||
TIME = 600
|
||||
|
||||
@@ -53,16 +53,16 @@ class UsbCardReader():
|
||||
# Claim the device
|
||||
usb.util.claim_interface(self.dev, USB_IF)
|
||||
self.receivedNumber = 0
|
||||
|
||||
|
||||
cardread=threading.Thread(target=self.read)
|
||||
cardread.start()
|
||||
|
||||
|
||||
def read(self):
|
||||
global activeCards, db, times, times_json
|
||||
|
||||
|
||||
print("Waiting for card")
|
||||
receivedNumber = 0
|
||||
|
||||
|
||||
while True:
|
||||
control = None
|
||||
try:
|
||||
@@ -72,7 +72,7 @@ class UsbCardReader():
|
||||
if receivedDigit == 10:
|
||||
receivedDigit = 0
|
||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
||||
|
||||
|
||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
||||
try:
|
||||
with open('people.json', 'r') as f:
|
||||
@@ -99,12 +99,12 @@ class UsbCardReader():
|
||||
print(times)
|
||||
except Exception as e: print(e)
|
||||
receivedNumber = 0
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
time.sleep(0.001)
|
||||
|
||||
UsbCardReader()
|
||||
@@ -29,12 +29,12 @@ class UsbCardReader():
|
||||
# Claim the device
|
||||
usb.util.claim_interface(self.dev, USB_IF)
|
||||
self.receivedNumber = 0
|
||||
|
||||
|
||||
def read(self):
|
||||
global activeCards
|
||||
|
||||
|
||||
print("Priloz kartu")
|
||||
|
||||
|
||||
while True:
|
||||
control = None
|
||||
try:
|
||||
@@ -44,7 +44,7 @@ class UsbCardReader():
|
||||
if receivedDigit == 10:
|
||||
receivedDigit = 0
|
||||
self.receivedNumber = 10 * self.receivedNumber + receivedDigit
|
||||
|
||||
|
||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not self.receivedNumber == 0 )):
|
||||
try:
|
||||
cardPresent = False
|
||||
@@ -60,24 +60,24 @@ class UsbCardReader():
|
||||
self.receivedNumber = 0
|
||||
print("Priloz kartu")
|
||||
except Exception as e: print(e)
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
time.sleep(0.001)
|
||||
|
||||
def assign(self):
|
||||
global activeCards
|
||||
|
||||
|
||||
n = input("Cislo zavodnika: ")
|
||||
activeCards[str(n)] = self.receivedNumber
|
||||
with open('people.json', 'w') as f:
|
||||
f.write(json.dumps(activeCards, indent = 4))
|
||||
self.receivedNumber = 0
|
||||
print("Ulozeno, priloz kartu")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
reader = UsbCardReader()
|
||||
print("Zapis zavodniku ready")
|
||||
|
||||
Reference in New Issue
Block a user