|
|
@ -68,6 +68,56 @@ class SerialInput(BaseInput):
|
|
|
|
|
|
|
|
|
|
|
|
_add_input("Serial", SerialInput)
|
|
|
|
_add_input("Serial", SerialInput)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BeopardySerialInput(BaseInput):
|
|
|
|
|
|
|
|
def __init__(self, app, device, baudrate=9600, bytesize=8, parity='N', stopbits=1):
|
|
|
|
|
|
|
|
super(BeopardySerialInput, self).__init__(app)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
self._serial = serial.Serial(device, baudrate, bytesize, parity, stopbits)
|
|
|
|
|
|
|
|
except serial.SerialException as e:
|
|
|
|
|
|
|
|
raise InputException("Error: %s" % e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# playerDict
|
|
|
|
|
|
|
|
self._playerDict = {
|
|
|
|
|
|
|
|
'a': 1,
|
|
|
|
|
|
|
|
'b': 2,
|
|
|
|
|
|
|
|
'c': 3,
|
|
|
|
|
|
|
|
'd': 4,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(" >> serial %s initialized with rate %s %s%s%s" % (device, baudrate, bytesize, parity, stopbits))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
c = self._serial.read(1)
|
|
|
|
|
|
|
|
#print("serial: read ", c)
|
|
|
|
|
|
|
|
if len(c) == 1 and c in self._playerDict:
|
|
|
|
|
|
|
|
#print("sending button event ", c, " ", self._playerDict[c])
|
|
|
|
|
|
|
|
self._sendButtonEvent(self._playerDict[c])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@QtCore.Slot(bool)
|
|
|
|
|
|
|
|
def buzzersOpen(self, isOpen):
|
|
|
|
|
|
|
|
self._serial.write("ABCD")
|
|
|
|
|
|
|
|
#print("serial: ABCD")
|
|
|
|
|
|
|
|
if isOpen:
|
|
|
|
|
|
|
|
# buzzers are open now
|
|
|
|
|
|
|
|
self._serial.write("R")
|
|
|
|
|
|
|
|
#print("serial: R")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# tell them that buttons are closed now
|
|
|
|
|
|
|
|
self._serial.write("r")
|
|
|
|
|
|
|
|
#print("serial: r")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@QtCore.Slot(int)
|
|
|
|
|
|
|
|
def playerGotQuestion(self, playerNo):
|
|
|
|
|
|
|
|
if not (playerNo >= 1 and playerNo <= 4):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._serial.write(chr(ord('a') + (playerNo-1)))
|
|
|
|
|
|
|
|
#print("serial: ", chr(ord('a') + (playerNo-1)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_add_input("BeopardySerial", BeopardySerialInput)
|
|
|
|
|
|
|
|
|
|
|
|
class FifoInput(BaseInput):
|
|
|
|
class FifoInput(BaseInput):
|
|
|
|
def __init__(self, app, fifoPath, debug=False):
|
|
|
|
def __init__(self, app, fifoPath, debug=False):
|
|
|
|
super(FifoInput, self).__init__(app)
|
|
|
|
super(FifoInput, self).__init__(app)
|
|
|
|