Function CheckJoystickEvents():
- Initialize ReturnVal to false.
- If QueryGameFSM() equals Wait4Input:
- Read joystick X and Y positions into joystickVals array using ADC_MultiRead().
- Assign joystickX = joystickVals[0] and joystickY = joystickVals[1].
- Check if joystick is within CENTER_THRESHOLD of CENTER_VALUE for both axes:
- If true, set directionRead to 0 (neutral position detected).
- If directionRead is 0 (neutral position previously detected):
- Check for upward movement:
- If joystickY < CENTER_VALUE - THRESHOLD:
- Set ThisEvent.EventType to JOYSTICK_UP.
- Set ThisEvent.EventParam to joystickY.
- Post ThisEvent to all services using ES_PostAll().
- Set directionRead to 1 (movement event in progress).
- Print "Up".
- Check for downward movement:
- If joystickY > CENTER_VALUE + THRESHOLD:
- Set ThisEvent.EventType to JOYSTICK_DOWN.
- Set ThisEvent.EventParam to joystickY.
- Post ThisEvent to all services using ES_PostAll().
- Set directionRead to 1.
- Print "Down".
- Check for leftward movement:
- If joystickX < CENTER_VALUE - THRESHOLD:
- Set ThisEvent.EventType to JOYSTICK_LEFT.
- Set ThisEvent.EventParam to joystickX.
- Post ThisEvent to all services using ES_PostAll().
- Set directionRead to 1.
- Print "Left".
- Check for rightward movement:
- If joystickX > CENTER_VALUE + THRESHOLD:
- Set ThisEvent.EventType to JOYSTICK_RIGHT.
- Set ThisEvent.EventParam to joystickX.
- Post ThisEvent to all services using ES_PostAll().
- Set directionRead to 1.
- Print "Right".
- Return ReturnVal (true if an event was detected and posted).