Compare commits
27 Commits
91739586d0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80653dfe11 | ||
|
|
b737934f05 | ||
|
|
9227a8bfdb | ||
|
|
5a34e9e4e5 | ||
|
|
ef915110a7 | ||
|
|
19ead426fb | ||
|
|
2c9ea8e379 | ||
|
|
8104096c0b | ||
|
|
c4d7df8b5d | ||
|
|
03d8045990 | ||
|
|
c59b24a561 | ||
|
|
586bd3dc84 | ||
|
|
2e9c11d73b | ||
|
|
ca8d008e77 | ||
|
|
bc61d8a0bd | ||
|
|
2221f5b39d | ||
|
|
9deda461ee | ||
|
|
52d81c127d | ||
|
|
5653972b8d | ||
|
|
c441dc7a32 | ||
|
cee41ca595
|
|||
|
46df08600d
|
|||
|
07473c8a20
|
|||
|
c267155b25
|
|||
|
da3215ec5e
|
|||
|
c1b729cf52
|
|||
|
7c871a3b5c
|
BIN
HW/timer_button/3D/Tlacitko_top.SLDPRT
Normal file
BIN
HW/timer_button/3D/Tlacitko_top.SLDPRT
Normal file
Binary file not shown.
BIN
HW/timer_button/3D/Tlacitko_top.STL
Normal file
BIN
HW/timer_button/3D/Tlacitko_top.STL
Normal file
Binary file not shown.
@@ -1 +0,0 @@
|
||||
{"hostname":"spock","username":"angoosh"}
|
||||
@@ -30,8 +30,3 @@ for id in data_dict:
|
||||
print(results)
|
||||
dict(sorted(results.items(), key=lambda item: item[0]))
|
||||
print(results)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
7
SW/PC/Stopwatch/config.json
Normal file
7
SW/PC/Stopwatch/config.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"station_id": 2,
|
||||
"host": "https://beta.alkator.cz",
|
||||
"login": "station_register@alkator.cz",
|
||||
"password": "password_heslo",
|
||||
"countdown_seconds": 60
|
||||
}
|
||||
1
SW/PC/Stopwatch/log.json
Normal file
1
SW/PC/Stopwatch/log.json
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
||||
205
SW/PC/Stopwatch/main.py
Normal file
205
SW/PC/Stopwatch/main.py
Normal file
@@ -0,0 +1,205 @@
|
||||
import gi
|
||||
import threading
|
||||
import time
|
||||
import datetime
|
||||
import requests
|
||||
import json
|
||||
|
||||
gi.require_version('Gtk', '4.0')
|
||||
from queue import Queue
|
||||
from gi.repository import Gtk, Gio, Gdk
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
from usbcardreader import UsbCardReader
|
||||
|
||||
|
||||
with open('config.json', 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
|
||||
activeCards = []
|
||||
|
||||
TIME = config['countdown_seconds']
|
||||
|
||||
db = {}
|
||||
|
||||
queue_to_send = []
|
||||
|
||||
|
||||
session = requests.Session()
|
||||
|
||||
|
||||
retries = Retry(total=10,
|
||||
backoff_factor=1,
|
||||
status_forcelist=[ 500, 502, 503, 504 ])
|
||||
|
||||
session.mount('https://', HTTPAdapter(max_retries=retries))
|
||||
|
||||
|
||||
session.post(config['host'] + '/api/login', {'email':config['login'], 'password': config['password']})
|
||||
|
||||
def refreshDb():
|
||||
global db
|
||||
resp = session.get(config['host'] + '/api/racers')
|
||||
if resp.status_code == 200:
|
||||
json = resp.json()
|
||||
db = {}
|
||||
for racer in json:
|
||||
if racer["card_id"]:
|
||||
db[racer["card_id"]] = racer
|
||||
|
||||
|
||||
def refreshDbEvery3mins():
|
||||
while True:
|
||||
refreshDb()
|
||||
time.sleep(3 * 60)
|
||||
|
||||
|
||||
threading.Thread(target=refreshDbEvery3mins).start()
|
||||
|
||||
log = []
|
||||
|
||||
|
||||
with open('log.json', 'r') as f:
|
||||
log = json.loads(f.read())
|
||||
|
||||
|
||||
queue = Queue()
|
||||
|
||||
|
||||
def worker():
|
||||
while True:
|
||||
item = queue.get()
|
||||
log.append(item)
|
||||
with open('log.json', 'w') as f:
|
||||
f.write(json.dumps(log))
|
||||
response = session.post(item['url'], json=item['json'])
|
||||
print(item, response)
|
||||
|
||||
|
||||
threading.Thread(target=worker).start()
|
||||
|
||||
|
||||
def callbackOnCard(card_id):
|
||||
global win, activeCards, db
|
||||
if card_id not in db:
|
||||
refreshDb()
|
||||
if card_id in db:
|
||||
if card_id not in activeCards:
|
||||
activeCards.append(card_id)
|
||||
win.arb(db[card_id])
|
||||
print('Card is active now')
|
||||
else:
|
||||
print('Card is already active')
|
||||
else:
|
||||
print(f'Card {card_id} not found in db')
|
||||
|
||||
|
||||
class GridRow():
|
||||
def __init__(self, parent, racer, index):
|
||||
global queue_to_send
|
||||
self.id = racer['starting_number']
|
||||
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(racer["starting_number"]), 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()
|
||||
|
||||
queue.put({'url': config['host'] + '/api/station/register', 'json': {
|
||||
'card_id': racer['card_id'],
|
||||
'station_id': config['station_id'],
|
||||
'time': datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')
|
||||
}})
|
||||
|
||||
def printIndex(self, button):
|
||||
print(self.index)
|
||||
|
||||
def updateTime(self):
|
||||
t = TIME
|
||||
while t >= -10:
|
||||
if t < 0:
|
||||
mins, secs = divmod((t * -1), 60)
|
||||
timer = '-{:02d}:{:02d}'.format(mins, secs)
|
||||
else:
|
||||
mins, secs = divmod(t, 60)
|
||||
timer = '{:02d}:{:02d}'.format(mins, secs)
|
||||
self.runb.set_label(timer)
|
||||
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)
|
||||
|
||||
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()
|
||||
self.grid.attach(runlabel, 0, 0, 1, 1)
|
||||
self.grid.attach(cntlabel, 1, 0, 2, 1)
|
||||
|
||||
self.set_child(self.grid)
|
||||
|
||||
def arb(self, racer):
|
||||
self.runners.append(GridRow(self, racer, len(activeCards)))
|
||||
|
||||
def rrb(self, button):
|
||||
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 activeCards
|
||||
if len(activeCards) > 0:
|
||||
self.grid.remove_row(1)
|
||||
del activeCards[0]
|
||||
|
||||
|
||||
def on_activate(app):
|
||||
# Create window
|
||||
global win
|
||||
win = GridWindow(application=app)
|
||||
win.present()
|
||||
|
||||
UsbCardReader(callbackOnCard)
|
||||
app = Gtk.Application(application_id='com.example.App')
|
||||
app.connect('activate', on_activate)
|
||||
|
||||
app.run(None)
|
||||
4
SW/PC/Stopwatch/people.json
Normal file
4
SW/PC/Stopwatch/people.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"1": 3619716179,
|
||||
"2": 3620062547
|
||||
}
|
||||
184
SW/PC/Stopwatch/registrace.py
Normal file
184
SW/PC/Stopwatch/registrace.py
Normal file
@@ -0,0 +1,184 @@
|
||||
import sys
|
||||
import datetime
|
||||
import requests
|
||||
import threading
|
||||
import json
|
||||
from PyQt6 import QtWidgets, uic, QtGui, QtCore
|
||||
from PyQt6.QtCore import pyqtSignal as Signal, pyqtSlot as Slot
|
||||
from queue import Queue
|
||||
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
from usbcardreader import UsbCardReader
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
|
||||
with open('config.json', 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
session = requests.Session()
|
||||
session.post(config['host'] + '/api/login', {'email':config['login'], 'password': config['password']})
|
||||
|
||||
|
||||
retries = Retry(total=10,
|
||||
backoff_factor=1,
|
||||
status_forcelist=[ 500, 502, 503, 504 ],)
|
||||
|
||||
session.mount('https://', HTTPAdapter(max_retries=retries))
|
||||
|
||||
|
||||
last_card = 0
|
||||
last_time = datetime.datetime.now()
|
||||
|
||||
racers = []
|
||||
|
||||
log = []
|
||||
|
||||
|
||||
with open('log.json', 'r') as f:
|
||||
log = json.loads(f.read())
|
||||
|
||||
|
||||
queue = Queue()
|
||||
|
||||
|
||||
class Worker(QtCore.QThread):
|
||||
returned_state = Signal(str)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.returned_state.connect(self.handle_returned_state)
|
||||
self.worker_thread = threading.Thread(target=self.worker)
|
||||
self.worker_thread.start()
|
||||
|
||||
def worker(self):
|
||||
while True:
|
||||
item = queue.get()
|
||||
log.append({
|
||||
'url': item['url'],
|
||||
'json': item['json'],
|
||||
})
|
||||
with open('log.json', 'w') as f:
|
||||
f.write(json.dumps(log))
|
||||
response = session.post(item['url'], json=item['json'])
|
||||
if response.status_code == 200:
|
||||
if item.get('on_success'):
|
||||
item['on_success']()
|
||||
if item.get('message'):
|
||||
self.returned_state.emit(f'{item['message']}')
|
||||
else:
|
||||
if item.get('failed'):
|
||||
self.returned_state.emit(f'{item['failed']}')
|
||||
|
||||
print(item, response)
|
||||
def handle_returned_state(self, state):
|
||||
mb = QtWidgets.QMessageBox(text=f"{state}")
|
||||
mb.exec()
|
||||
|
||||
|
||||
worker = Worker()
|
||||
|
||||
|
||||
def register_racer():
|
||||
card_id = last_card
|
||||
index = window.racers.currentIndex()
|
||||
if not index.data():
|
||||
mb = QtWidgets.QMessageBox(text='Prosím vyberte závodníka!')
|
||||
mb.exec()
|
||||
return
|
||||
racer_id = int(index.data().split(' ')[-1])
|
||||
try:
|
||||
starting_number = max(filter(lambda r: r['starting_number'], racers), key=lambda racer: racer['starting_number'])['starting_number'] + 1
|
||||
except ValueError:
|
||||
starting_number = 1
|
||||
racer = list(filter(lambda x: x['racer_id'] == racer_id, racers))[0]
|
||||
|
||||
def register_update_racer():
|
||||
racer['card_id'] = card_id
|
||||
racer['starting_number'] = starting_number
|
||||
racer['started'] = False
|
||||
updateRacers()
|
||||
|
||||
queue.put({
|
||||
'url': config['host'] + '/api/card/register',
|
||||
'json': {'racer_id': racer_id, 'starting_number': starting_number, 'card_id': card_id, 'time': datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')},
|
||||
'message': f"Úspěšné zaregistrování závodníka {racer['first_name']} {racer['last_name']} se startovním číslem {starting_number}!",
|
||||
'failed': f"Neúspěšná registrace závodníka {racer['first_name']} {racer['last_name']}",
|
||||
'on_success': register_update_racer,
|
||||
})
|
||||
|
||||
|
||||
model = QtGui.QStandardItemModel()
|
||||
|
||||
def updateRacers():
|
||||
model.clear()
|
||||
for racer in racers:
|
||||
if racer['starting_number'] or racer['card_id']:
|
||||
continue
|
||||
item = QtGui.QStandardItem(f"{racer['last_name']} {racer['first_name']} {racer['date_of_birth']} {racer['racer_id']}")
|
||||
model.appendRow(item)
|
||||
|
||||
|
||||
updateRacers()
|
||||
|
||||
|
||||
def reload_racers():
|
||||
global racers
|
||||
response = session.get(config['host'] + '/api/racers')
|
||||
|
||||
racers = response.json()
|
||||
updateRacers()
|
||||
|
||||
|
||||
reload_racers()
|
||||
|
||||
|
||||
def findByCard(card_id):
|
||||
for racer in racers:
|
||||
if racer['card_id'] == card_id:
|
||||
return racer
|
||||
|
||||
|
||||
def updateLastCard(card_id):
|
||||
global last_card, last_time
|
||||
if card_id == last_card and datetime.datetime.now() - last_time < datetime.timedelta(seconds=15):
|
||||
return
|
||||
time = last_time = datetime.datetime.now()
|
||||
last_card = card_id
|
||||
window.lastCard.setText(str(card_id))
|
||||
|
||||
racer = findByCard(card_id)
|
||||
if racer:
|
||||
if racer['started']:
|
||||
def finish_update_racer():
|
||||
racer['card_id'] = None
|
||||
queue.put({
|
||||
'url': config['host'] + '/api/card/unregister',
|
||||
'json': {'racer_id': racer['racer_id'], 'starting_number': racer['starting_number'], 'card_id': card_id, 'time': time.strftime('%d.%m.%Y %H:%M:%S.%f')},
|
||||
'message': f"Úspěšné odhlášení závodníka {racer['starting_number']}!",
|
||||
'failed': f"Neúspěšné odhlášení karty závodníka {racer['starting_number']}",
|
||||
'on_success': finish_update_racer,
|
||||
})
|
||||
else:
|
||||
def start_update_racer():
|
||||
racer['started'] = True
|
||||
queue.put({
|
||||
'url': config['host'] + '/api/station/register',
|
||||
'json': {'card_id': card_id, 'time': time.strftime('%d.%m.%Y %H:%M:%S.%f'), 'station_id': 1},
|
||||
'message': f"Úspěšné odstartování závodníka {racer['starting_number']}!",
|
||||
'failed': f"Núspěšné odstartování závodníka {racer['starting_number']}, prosím registraci opakujte!",
|
||||
'on_success': start_update_racer,
|
||||
})
|
||||
|
||||
|
||||
UsbCardReader(updateLastCard)
|
||||
|
||||
|
||||
|
||||
|
||||
window = uic.loadUi("registrace.ui")
|
||||
window.racers.setModel(model)
|
||||
window.register_racer.clicked.connect(register_racer)
|
||||
window.reload_racers.clicked.connect(reload_racers)
|
||||
window.show()
|
||||
|
||||
|
||||
app.exec()
|
||||
61
SW/PC/Stopwatch/registrace.ui
Normal file
61
SW/PC/Stopwatch/registrace.ui
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Frame</class>
|
||||
<widget class="QFrame" name="Frame">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>315</width>
|
||||
<height>289</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Registrace závodníků</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="register_racer">
|
||||
<property name="text">
|
||||
<string>Registrovat</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLineEdit" name="lastCard"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>číslo karty</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="5">
|
||||
<widget class="QListView" name="racers"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="reload_racers">
|
||||
<property name="text">
|
||||
<string>Obnovit Závodníky</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
51
SW/PC/Stopwatch/rfid_read.py
Normal file
51
SW/PC/Stopwatch/rfid_read.py
Normal file
@@ -0,0 +1,51 @@
|
||||
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
|
||||
|
||||
# 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
|
||||
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:
|
||||
receivedDigit = 0
|
||||
|
||||
# Append the digit to the number
|
||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
||||
|
||||
# Check if the received character is CRLF
|
||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
||||
print('cardNumber:', receivedNumber)
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except:
|
||||
pass
|
||||
|
||||
time.sleep(0.001) # Let CTRL+C actually exit
|
||||
2
SW/PC/Stopwatch/run.sh
Executable file
2
SW/PC/Stopwatch/run.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
GTK_THEME=Adwaita:light python ./main.py
|
||||
110
SW/PC/Stopwatch/start_finish_stopwatch.py
Normal file
110
SW/PC/Stopwatch/start_finish_stopwatch.py
Normal file
@@ -0,0 +1,110 @@
|
||||
import threading
|
||||
import time
|
||||
import usb.core
|
||||
import usb.util
|
||||
import requests
|
||||
import json
|
||||
import datetime
|
||||
|
||||
DEBUG = False
|
||||
|
||||
if DEBUG == True:
|
||||
index = 2
|
||||
else:
|
||||
index = 1
|
||||
activeCards = []
|
||||
|
||||
TIME = 600
|
||||
|
||||
USB_IF = 0 # Interface
|
||||
USB_TIMEOUT = 5 # Timeout in ms
|
||||
USB_VENDOR = 0xffff # Vendor-ID:
|
||||
USB_PRODUCT = 0x0035 # Product-ID
|
||||
|
||||
with open('people.json', 'r') as f:
|
||||
db = json.load(f)
|
||||
|
||||
try:
|
||||
times = {}
|
||||
with open('times.json', 'r') as f:
|
||||
times_json = json.load(f)
|
||||
for i in times_json:
|
||||
times[i] = {}
|
||||
times[i]['start'] = datetime.datetime.strptime(times_json[i]['start'],"%d/%m/%Y, %H:%M:%S")
|
||||
try:
|
||||
times[i]['end'] = datetime.datetime.strptime(times_json[i]['end'],"%d/%m/%Y, %H:%M:%S")
|
||||
times[i]['duration'] = times[i]['end'] - times[i]['start']
|
||||
except:
|
||||
print(i, "Not finished yet")
|
||||
print(times)
|
||||
except Exception as e: print(e)
|
||||
#except:
|
||||
# times = {}
|
||||
# times_json = {}
|
||||
|
||||
class UsbCardReader():
|
||||
def __init__(self, **kargs):
|
||||
# Find the HID device by vendor/product ID
|
||||
self.dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
|
||||
# Get and store the endpoint
|
||||
self.endpoint = self.dev[0][(0,0)][0]
|
||||
if self.dev.is_kernel_driver_active(USB_IF) is True:
|
||||
self.dev.detach_kernel_driver(USB_IF)
|
||||
# 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:
|
||||
control = self.dev.read(self.endpoint.bEndpointAddress, self.endpoint.wMaxPacketSize, USB_TIMEOUT)
|
||||
if (control[2] != 40) & (control[2] != 0):
|
||||
receivedDigit = control[2] - 29
|
||||
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:
|
||||
db = json.load(f)
|
||||
for i in db:
|
||||
if db[i] == receivedNumber:
|
||||
print("Runner:", i)
|
||||
print(db)
|
||||
runner_found = False
|
||||
for j in times:
|
||||
if j == i:
|
||||
runner_found = True
|
||||
times[j]['end'] = datetime.datetime.now()
|
||||
times[j]['duration'] = times[j]['end'] - times[j]['start']
|
||||
times_json[j]['end'] = times[j]['end'].strftime("%d/%m/%Y, %H:%M:%S")
|
||||
times_json[j]['duration'] = str(times[j]['duration'])
|
||||
if runner_found == False:
|
||||
times[i] = {}
|
||||
times[i]['start'] = datetime.datetime.now()
|
||||
times_json[i] = {}
|
||||
times_json[i]['start'] = times[i]['start'].strftime("%d/%m/%Y, %H:%M:%S")
|
||||
with open("times.json", 'w') as f:
|
||||
f.write(json.dumps(times_json, indent = 4))
|
||||
print(times)
|
||||
except Exception as e: print(e)
|
||||
receivedNumber = 0
|
||||
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except:
|
||||
pass
|
||||
|
||||
time.sleep(0.001)
|
||||
|
||||
UsbCardReader()
|
||||
20
SW/PC/Stopwatch/style.css
Normal file
20
SW/PC/Stopwatch/style.css
Normal file
@@ -0,0 +1,20 @@
|
||||
#lightgrid {
|
||||
background-color: #F0F0F0;
|
||||
}
|
||||
|
||||
#darkgrid {
|
||||
background-color: #D0D0D0;
|
||||
}
|
||||
|
||||
#lredgrid {
|
||||
background-color: #FF8888;
|
||||
}
|
||||
|
||||
#dredgrid {
|
||||
background-color: #FF6666;
|
||||
}
|
||||
|
||||
#gridlabel {
|
||||
font-size: 16pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
12
SW/PC/Stopwatch/times.json
Normal file
12
SW/PC/Stopwatch/times.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"1": {
|
||||
"start": "25/02/2025, 18:06:16",
|
||||
"end": "25/02/2025, 18:06:31",
|
||||
"duration": "0:00:14.553644"
|
||||
},
|
||||
"2": {
|
||||
"start": "25/02/2025, 18:15:08",
|
||||
"end": "25/02/2025, 18:15:27",
|
||||
"duration": "0:00:19.543765"
|
||||
}
|
||||
}
|
||||
52
SW/PC/Stopwatch/usbcardreader.py
Normal file
52
SW/PC/Stopwatch/usbcardreader.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import usb.core
|
||||
import usb.util
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
USB_IF = 0 # Interface
|
||||
USB_TIMEOUT = 5 # Timeout in ms
|
||||
USB_VENDOR = 0xffff # Vendor-ID:
|
||||
USB_PRODUCT = 0x0035 # Product-ID
|
||||
|
||||
|
||||
class UsbCardReader:
|
||||
def __init__(self, callback):
|
||||
#fn called on found card
|
||||
self.callback = callback
|
||||
# Find the HID device by vendor/product ID
|
||||
self.dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
|
||||
# Get and store the endpoint
|
||||
self.endpoint = self.dev[0][(0,0)][0]
|
||||
if self.dev.is_kernel_driver_active(USB_IF) is True:
|
||||
self.dev.detach_kernel_driver(USB_IF)
|
||||
# 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):
|
||||
receivedNumber = 0
|
||||
|
||||
while True:
|
||||
control = None
|
||||
try:
|
||||
control = self.dev.read(self.endpoint.bEndpointAddress, self.endpoint.wMaxPacketSize, USB_TIMEOUT)
|
||||
if (control[2] != 40) and (control[2] != 0):
|
||||
receivedDigit = control[2] - 29
|
||||
if receivedDigit == 10:
|
||||
receivedDigit = 0
|
||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
||||
|
||||
if ( control[0] == 0 ) and ( control[2] == 40 ) and ( not receivedNumber == 0 ):
|
||||
self.callback(receivedNumber)
|
||||
receivedNumber = 0
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
except:
|
||||
receivedNumber = 0
|
||||
pass
|
||||
|
||||
time.sleep(0.001)
|
||||
84
SW/PC/Stopwatch/zapis_zavodniku.py
Normal file
84
SW/PC/Stopwatch/zapis_zavodniku.py
Normal file
@@ -0,0 +1,84 @@
|
||||
import time
|
||||
import usb.core
|
||||
import usb.util
|
||||
import requests
|
||||
import json
|
||||
import threading
|
||||
|
||||
USB_IF = 0 # Interface
|
||||
USB_TIMEOUT = 5 # Timeout in ms
|
||||
USB_VENDOR = 0xffff # Vendor-ID:
|
||||
USB_PRODUCT = 0x0035 # Product-ID
|
||||
|
||||
activeCards = {}
|
||||
|
||||
try:
|
||||
with open('people.json', 'r') as f:
|
||||
activeCards = json.load(f)
|
||||
except:
|
||||
print("No people.json found")
|
||||
|
||||
class UsbCardReader():
|
||||
def __init__(self, **kargs):
|
||||
# Find the HID device by vendor/product ID
|
||||
self.dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
|
||||
# Get and store the endpoint
|
||||
self.endpoint = self.dev[0][(0,0)][0]
|
||||
if self.dev.is_kernel_driver_active(USB_IF) is True:
|
||||
self.dev.detach_kernel_driver(USB_IF)
|
||||
# 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:
|
||||
control = self.dev.read(self.endpoint.bEndpointAddress, self.endpoint.wMaxPacketSize, USB_TIMEOUT)
|
||||
if (control[2] != 40) & (control[2] != 0):
|
||||
receivedDigit = control[2] - 29
|
||||
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
|
||||
for i in activeCards:
|
||||
if activeCards[i] == self.receivedNumber:
|
||||
cardPresent = True
|
||||
break
|
||||
if cardPresent == False:
|
||||
assign=threading.Thread(target=self.assign)
|
||||
assign.start()
|
||||
else:
|
||||
print("Naramek jiz zaregistrovan")
|
||||
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")
|
||||
reader.read()
|
||||
@@ -90,7 +90,6 @@ def main():
|
||||
elif rw == '':
|
||||
s.write('r\r'.encode())
|
||||
read(s)
|
||||
|
||||
else:
|
||||
print('Invalid option')
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ BRIGHTNESS = 0.2 # Adjust the brightness (0.0 - 1.0)
|
||||
|
||||
led_strip = neopixel.NeoPixel(Pin(ws_pin), led_num)
|
||||
|
||||
push_button = Pin(24,Pin.IN,Pin.PULL_UP)
|
||||
push_button = Pin(24, Pin.IN, Pin.PULL_UP)
|
||||
buzzer = Pin(3, Pin.OUT)
|
||||
led = Pin(25, Pin.OUT)
|
||||
|
||||
pushbutton_pressed = 0
|
||||
blink_interrupted = 0
|
||||
@@ -80,19 +82,24 @@ def blink_and_beep(times):
|
||||
blink_delay = 0.2
|
||||
|
||||
#insert beep
|
||||
buzzer.value(1)
|
||||
for i in range(0, times):
|
||||
set_neopixel_color(255, 0, 0)
|
||||
buzzer.value(0)
|
||||
time.sleep(blink_delay)
|
||||
set_neopixel_color(0, 0, 0)
|
||||
buzzer.value(1)
|
||||
time.sleep(blink_delay)
|
||||
if pushbutton_pressed == 1:
|
||||
pushbutton_pressed = 0
|
||||
blink_interrupted = 1
|
||||
i = times
|
||||
buzzer.value(0)
|
||||
return
|
||||
buzzer.value(0)
|
||||
|
||||
ten_min_timer = 0
|
||||
ten_min_timer_led_index = 0
|
||||
ten_min_timer_led_index = 11
|
||||
def count_10_min():
|
||||
global ten_min_timer, ten_min_timer_led_index, pushbutton_pressed, blink_interrupted
|
||||
|
||||
@@ -107,7 +114,7 @@ def count_10_min():
|
||||
if (ten_min_timer % 60) == 0:
|
||||
if ten_min_timer_led_index == 10:
|
||||
pushbutton_pressed = 0
|
||||
blink_and_beep(60)
|
||||
blink_and_beep(15)
|
||||
if blink_interrupted == 1:
|
||||
blink_interrupted = 0
|
||||
return
|
||||
@@ -135,6 +142,22 @@ def button_callback(push_button):
|
||||
set_neopixel_color(0,0,0)
|
||||
push_button.irq(trigger=Pin.IRQ_FALLING, handler=button_callback)
|
||||
|
||||
green = (0, 255, 0)
|
||||
green = set_neopixel_brightness(green)
|
||||
led_strip[0] = green
|
||||
led_strip[2] = green
|
||||
led_strip[4] = green
|
||||
led_strip[6] = green
|
||||
led_strip[8] = green
|
||||
led_strip.write()
|
||||
|
||||
led_state = False
|
||||
while True:
|
||||
count_10_min()
|
||||
time.sleep(1)
|
||||
if led_state:
|
||||
led.low()
|
||||
led_state = False
|
||||
else:
|
||||
led.high()
|
||||
led_state = True
|
||||
@@ -406,4 +406,3 @@ class PN532:
|
||||
_COMMAND_INDATAEXCHANGE, params=params, response_length=1
|
||||
)
|
||||
return response[0] == 0x00
|
||||
|
||||
|
||||
Reference in New Issue
Block a user