EventCheckers (Pseudo code)
Global variables-
Int midTape, tapeAlign, bump, findbot (All of these are used so only one event is thrown instead of constant events) (Set to 1 to find the next event that happens and is set back to 0 once an event is posted)
CheckSPIF
if SPISR & _S12_SPIF != 0
Post SPIFSet to MasterSM
CheckTimers
If OC1Expired() is true, Post OC1Exp to MasterSM
CheckSwitch
If PTAD & BIT0HI and bump is 1
Post BumpSwitchHit to MasterSM
Set bump to 0
CheckTape
If analog reading on ADPin 1 is less than 300 and midtape is 1
Post MidTape to MasterSM
Set midTape to 0
If analog reading on ADPin 2 is less than 300 and tapeAlign is 1
Post TapeAlign to MasterSM
Set tapeAlign to 0
CheckBot
If findbot is 1
If queryShip(OurShipNumber (15)).active is true
Post botfound to MasterSM
Set findbot to 0
OC1Expired
Return true if Timer 5 in channel 0 flag is on
Else return false
requestMidTape
Set midTape to 1
requestTapeAlign
Set tapeAlign to 1
requestBump
Set bump to 1
requestFind
Set findBot to 1
Int midTape, tapeAlign, bump, findbot (All of these are used so only one event is thrown instead of constant events) (Set to 1 to find the next event that happens and is set back to 0 once an event is posted)
CheckSPIF
if SPISR & _S12_SPIF != 0
Post SPIFSet to MasterSM
CheckTimers
If OC1Expired() is true, Post OC1Exp to MasterSM
CheckSwitch
If PTAD & BIT0HI and bump is 1
Post BumpSwitchHit to MasterSM
Set bump to 0
CheckTape
If analog reading on ADPin 1 is less than 300 and midtape is 1
Post MidTape to MasterSM
Set midTape to 0
If analog reading on ADPin 2 is less than 300 and tapeAlign is 1
Post TapeAlign to MasterSM
Set tapeAlign to 0
CheckBot
If findbot is 1
If queryShip(OurShipNumber (15)).active is true
Post botfound to MasterSM
Set findbot to 0
OC1Expired
Return true if Timer 5 in channel 0 flag is on
Else return false
requestMidTape
Set midTape to 1
requestTapeAlign
Set tapeAlign to 1
requestBump
Set bump to 1
requestFind
Set findBot to 1