Code: Select all
class stateChange():
'''
@class stateChange
@brief an event of changing state
'''
state: Union[bool,int,float,str]
lastState: Union[bool,int,float,str]
time: perf_counter
ch_name:str
def __init__( self,
state:Union[bool,int,float,str],
lastState:Union[bool,int,float,str],
ch_name:str) -> None:
self.state = state
self.lastState = lastState
self.time = perf_counter()
self.ch_name = ch_name
class customPhidgetsClass():
channelMap:list #list of the names I've assigned to each channel
stateChanges:queue #queue object for storing all state changes, to be parsed separately
channels:list[Phidget] #list of phidget objects (digitaInput in this case)
def onStateChange_Din(self,phidget:DigitalInput,state):
try:
channelName = self.channelMap[phidget.getChannel()]
except KeyError:
raise Exception("Input {} was not expected\
to be mapped".format(phidget.getChannel()))
#add state change to queue
self.stateChanges.append(stateChange(state=state,
lastState=self.channels[channelName].state,
ch_name=channelName))
self.channels[channelName].state = state