* EventCheckers.c * This file contains the event checkers for the Mummy DDM. Pre-Defined Module Constants: BEARD_INIT_VAL 1950 // initial value for beard potentiometer location BEARD_TOL 60 // uncertainty in beard potentiometer digital reading BEARD_00 1 // beard position 1 BEARD_01 488 // beard position 2 BEARD_10 976 // beard position 3 BEARD_11 1464 // beard position 4 BEARD_20 1952 // beard position 5 BEARD_21 2440 // beard position 6 Module data: lastButton1State = 0; // last button 1 state lastButton2State = 0; // last button 2 state lastButton3State = 0; // last button 3 state lastButton4State = 0; // last button 4 state lastButton5State = 0; // last button 5 state lastButton6State = 0; // last button 6 state lastBeardState = BEARD_INIT_VAL; // last beard state lastHall1AState = 1; // last Hall 1A state lastHall1BState = 1; // last Hall 1B state lastHall2AState = 1; // last Hall 2A state lastHall2BState = 1; // last Hall 2B state lastWireState = 0; // last state of first half of Udjat wire * Checks if any of the game’s 6 buttons have been pressed (rising edges) or released (falling edges), * Code is copied an pasted 6 times, one for each integer: 1, 2, 3, 4, 5, 6 CheckButtonXEvents Param: uint8_t called currentButtonXState; Return: bool called returnVal 1) Assume that no buttons have been pressed or released by setting returnVal to false 2) isolate the state of pin connected to the button of interest and assign to a var called currentButton1State 3) Check for button pin different from last time if currentButton1State is different than the lastButtonXState) returnVal = true if the button was pressed post an ES_Event to the MummySM of type = ButtonPressed, param = button# = X else the button was released post an ES_Event to the MummySM of type = ButtonReleased, param = button# = X end if end if set the lastButtonXState = to the currentButtonXState return returnVal end CheckButtonXEvents * Checks if the beard has been rotated to a valid position. CheckBeardEvents Param: uint8_t called currentBeardState; Return: bool called returnVal 1) Assume that no buttons have been pressed or released by setting returnVal to false 2) get the Analog-to-Digital (ADC) value from beard potentiometer and set equal to currentBeardState 3) check for relevant events related to a change in the BeardState if the currentBeard State is less than or greater than the lastBeardState +/- the tolerance BEARD_TOL, an event has been detected if the currentBeard State is between positions 1 & 2 the beard has just been rotated into section 0 of the dial post an ES_Event to the MummySM of type = BeardRotated, param = section# = 0 set returnVal to true because an event was detected else if the currentBeard State is between positions 3 & 4 the beard has just been rotated into section 1 of the dial post an ES_Event to the MummySM of type = BeardRotated, param = section# = 1 set returnVal to true because an event was detected else if the currentBeard State is between positions 5 & 6 the beard has just been rotated into section 2 of the dial post an ES_Event to the MummySM of type = BeardRotated, param = section# = 2 set returnVal to true because an event was detected end if set lastBeardState to currentBeardState since the potentiometer was rotated end if 4) return returnVal end CheckBeardEvents * Checks if events have occurred at the starting Hall effect sensors (1A and 1B). * Analogous function for middle/end Hall effect sensors (2A and 2B). CheckStartHallEvents Param: uint8_t called currentHall1AState, uint8_t called currentHall1BState, and uint8_t called currentWireState, Return: bool called returnVal = false; 1) isolate the state of pin connected to Hall Effect sensor 1A and assign to a var called currentHall1AState 2) isolate the state of pin connected to Hall Effect sensor 1B and assign to a var called currentHall1BState 3) isolate the state of pin connected to the Wire touch game and assign to a var called currentWireState 4) check for relevant events if 1A state OR 1B state has changed if 1A has magnet in proximity AND 1B has magnet in proximity AND loop not touching wire //the first stage of the game has been beaten post an ES_Event to the MummySM of type = StartHallsFall, param = 1 set returnVal to true because an event was detected end if end if 5) set lastHall1AState to currentHall1AState 6) set lastHall1BState to currentHall1BState; 7) return returnVal; end CheckStartHallEvents * Checks if loop has touched the wire in the wire loop game. CheckWireTouchEvents Param: uint8_t called currentWireState; Return: bool called returnVal = false; 1) isolate the state of pin connected to the Wire touch game and assign to a var called currentWireState 2) check for relevant events if the wire state has changed if the wire state just went from low to high post an ES_Event to PostWireTouchDB of type = WireTouchDB, param = 1 to create a debouncing event set returnVal to true because an event was detected end if end if 3) set lastWireState to currentWireState; 4) return returnVal end CheckWireTouchEvents