Card Reader Module PseudoCode
CardReader Module (State Machine)
static local variable currentState
InitCardReader
local variable = tapeSensor1 //corresponds to tape sensor reading black in D
local variable = tapeSensor2 //corresponds to tape sensor reading filled in P
local variable = tapeSensor3 //corresponds to tape sensor reading white before SPDL
//AD initialization in global hardware Init.
Initialize currentState as GameStopped
Return true
End of InitCardReader
RunCardReader
States: CARD_READER_INIT, NO_CARD, VALID_CARD
Events Read: ES_INIT, ES_CARD_READ, ES_CARD_REMOVED
Events Posted: ES_CARD_READ, ES_CARD_REMOVED
Switch statement between following states:
If currentState is CARD_READER_INIT
If EventType is ES_INIT
nextState is NO_CARD
End if
End if
If currentState is NO_CARD
If EventType is ES_CARD_READ
nextState is VALID_CARD
post event ES_CARD_READ to PostList00
End if
End if
If currentState is VALID_CARD
If EventType is ES_CARD_REMOVED
nextState is NO_CARD
post event ES_CARD_REMOVED to PostList00
End if
End if
save nextState to currentState
End of RunCardReader
check4Card
Read tape sensor pins and save to currentCardState
If currentCardState is not equal to lastCardState
If tape sensor is reading SPDL card
post ES_CARD_READ to CardReader module
Else
post ES_CARD_REMOVED to CardReader module
End if
End if
Save currentCardState to lastCardState
End of check4Card
static local variable currentState
InitCardReader
local variable = tapeSensor1 //corresponds to tape sensor reading black in D
local variable = tapeSensor2 //corresponds to tape sensor reading filled in P
local variable = tapeSensor3 //corresponds to tape sensor reading white before SPDL
//AD initialization in global hardware Init.
Initialize currentState as GameStopped
Return true
End of InitCardReader
RunCardReader
States: CARD_READER_INIT, NO_CARD, VALID_CARD
Events Read: ES_INIT, ES_CARD_READ, ES_CARD_REMOVED
Events Posted: ES_CARD_READ, ES_CARD_REMOVED
Switch statement between following states:
If currentState is CARD_READER_INIT
If EventType is ES_INIT
nextState is NO_CARD
End if
End if
If currentState is NO_CARD
If EventType is ES_CARD_READ
nextState is VALID_CARD
post event ES_CARD_READ to PostList00
End if
End if
If currentState is VALID_CARD
If EventType is ES_CARD_REMOVED
nextState is NO_CARD
post event ES_CARD_REMOVED to PostList00
End if
End if
save nextState to currentState
End of RunCardReader
check4Card
Read tape sensor pins and save to currentCardState
If currentCardState is not equal to lastCardState
If tape sensor is reading SPDL card
post ES_CARD_READ to CardReader module
Else
post ES_CARD_REMOVED to CardReader module
End if
End if
Save currentCardState to lastCardState
End of check4Card