fix spaces

This commit is contained in:
Martin Quarda 2025-03-25 08:11:28 +01:00
parent cee41ca595
commit c441dc7a32
9 changed files with 112 additions and 119 deletions

View File

@ -16,7 +16,7 @@ results = {}
with open(FILE,'r') as f:
file_content = f.read()
data_dict = json.loads(file_content)
for id in data_dict:
laps = int(data_dict[id]['laps'])
time = 0
@ -26,12 +26,7 @@ for id in data_dict:
print(data_dict[id]['name'],time)
data_dict[id]['total_time'] = time
results[data_dict[id]['name']] = time
print(results)
dict(sorted(results.items(), key=lambda item: item[0]))
print(results)

View File

@ -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:

View File

@ -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

View File

@ -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()

View File

@ -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")

View File

@ -46,17 +46,17 @@ def read(ser):
lap += 1
data_dict[data[0]]['laps'] = lap
data_dict[data[0]]['time'] = get_seconds()
except:
data_dict[data[0]] = {'name': data[1]}
data_dict[data[0]]['time'] = get_seconds()
data_dict[data[0]]['laps'] = 0
data_json = json.dumps(data_dict, indent=4)
print(data_json)
with open(JSON_PATH, 'w') as file:
file.write(data_json)
def write(ser):
while True:
data = input('ID:')
@ -77,10 +77,10 @@ def write(ser):
def main():
s = serial.Serial(port="/dev/ttyACM3", parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=1)
s.flush()
rw = input('Read or Write tags? [R/w]')
rw = rw.lower()
if rw == 'w':
s.write('w\r'.encode())
write(s)
@ -90,12 +90,11 @@ def main():
elif rw == '':
s.write('r\r'.encode())
read(s)
else:
print('Invalid option')
if __name__ == "__main__":
if __name__ == "__main__":
main()

View File

@ -56,13 +56,13 @@ def loop_neopixel():
led_strip.fill(color)
led_strip.write()
time.sleep(1)
neopix_loop_dot_pos = 0
def neopixel_loop_dot():
global neopix_loop_dot_pos
color = (255, 0, 0)
black = (0, 0, 0)
color = set_neopixel_brightness(color)
led_strip[neopix_loop_dot_pos] = black
neopix_loop_dot_pos += 1
@ -71,16 +71,16 @@ def neopixel_loop_dot():
led_strip[neopix_loop_dot_pos] = color
led_strip.write()
time.sleep(0.2)
def lightup_led(index, color):
led_strip[index] = color
led_strip.write()
def blink_and_beep(times):
global pushbutton_pressed, blink_interrupted
blink_delay = 0.2
#insert beep
buzzer.value(1)
for i in range(0, times):
@ -97,20 +97,20 @@ def blink_and_beep(times):
buzzer.value(0)
return
buzzer.value(0)
ten_min_timer = 0
ten_min_timer_led_index = 11
def count_10_min():
global ten_min_timer, ten_min_timer_led_index, pushbutton_pressed, blink_interrupted
red = (255, 0, 0)
red = set_neopixel_brightness(red)
green = (0, 255, 0)
green = set_neopixel_brightness(green)
if ten_min_timer_led_index == 11:
return
if (ten_min_timer % 60) == 0:
if ten_min_timer_led_index == 10:
pushbutton_pressed = 0
@ -128,7 +128,7 @@ def count_10_min():
return
lightup_led(ten_min_timer_led_index, red)
ten_min_timer_led_index += 1
ten_min_timer += 1
def button_callback(push_button):

View File

@ -406,4 +406,3 @@ class PN532:
_COMMAND_INDATAEXCHANGE, params=params, response_length=1
)
return response[0] == 0x00

View File

@ -84,12 +84,12 @@ def read_nfc_loop():
# Try again if no card is available.
if uid is not None:
break
set_neopixel_color(255,255,0)
ntag_string = 'Data: '
sys.stdout.write('Reading ntag \r')
leds_on = 0
for page in range(20,40):
try:
@ -105,7 +105,7 @@ def read_nfc_loop():
if leds_on > 7:
leds_on = 7
led_strip.write()
if ntag2xx_page is not None:
for char in ntag2xx_page:
ntag_string += chr(char)
@ -115,11 +115,11 @@ def read_nfc_loop():
except:
sys.stdout.write('Error reading card\r')
return 1
set_neopixel_color(0,255,0)
sys.stdout.write(ntag_string + '\r')
time.sleep(3)
return 0
#print('PAGE ',page,': ',[chr(x) for x in ntag2xx_page])
@ -138,14 +138,14 @@ def write_nfc_loop(data):
# Try again if no card is available.
if uid is not None:
break
set_neopixel_color(255,255,0)
sys.stdout.write('Erasing card\r')
for page in range(20,41):
content_erase = b'\x00\x00\x00\x00'
pn532.ntag2xx_write_block(page, content_erase)
sys.stdout.write('Writing card\r')
for page in range(20,20 + pages):
content_slice = bytearray(4)
@ -157,7 +157,7 @@ def write_nfc_loop(data):
#content_slice.append(content[i + 4 * (page - 20)])
print(content_slice)
pn532.ntag2xx_write_block(page, content_slice)
sys.stdout.write('Write done\r')
set_neopixel_color(0,255,0)