motion Module

Files:

Interface

Function: CheckMotionEvents
Arguments: None.
Returns: Constant indicating directional event, POWER_OFF, or NO_EVENT.
Reads the location of each hand, and returns a directional event. If the power is off, returns POWER_OFF. If there is no direction, returns NO_EVENT.

Function: HandleMotionEvents
Arguments: event: constant indicating directional event.
Returns: Nothing.
Takes the motion event and sends the appropriate signal to the Atari.

Function: HandleCheatEvents
Arguments: event: constant indicating directional event.
Returns: Nothing.
Takes the motion event and keeps track of the cheat status. Once the cheat is entered, activates the cheat fans.

Pseudo-Code

CheckMotionEvents(Returns a constant indicating the direction event, no event, or
                  Atari power off.)
  initialize the static variable last_button to NO_EVENT
  initialize the static variable last_time to 0

  if the Atari power is off:
    return POWER_OFF
  endif

  for each hand:
    get and store the value of each sensor on that hand
    if the left sensor is covered:
      set the current hand direction to LEFT
    else if the right sensor is covered:
      set the current hand direction to RIGHT
    else if the front sensor is covered:
      set the current hand direction to UP
    else if the back sensor is uncovered:
      set the current hand direction to DOWN
    endif
  endfor

  store the direction returned from NormalControls(left hand direction,
                                                   right hand direction)
  if the direction is DOWN and
     the current time - last_time is less than BACKWARDS_WAIT:
    return last_button
  else:
    set last_time to the current time
    set last_button to the current direction
    return the direction
  endif
NormalControls(Takes constants indicating the direction of the left and right hands,
               respectively.)
  if both directions are UP:
    return UP
  else if both directions are RIGHT:
    return RIGHT
  else if both directions are LEFT:
    return LEFT
  else if both directions are DOWN:
    return DOWN
  else if the left direction is LEFT and the right direction is RIGHT:
    return BUTTON
  else:
    return NO_EVENT
  endif
HandleMotionEvents(Takes a constant indicating the direction event, no event, or
                   Atari power off.)
  initialize the static variable last_button to NO_EVENT

  if last_button is the passed-in event:
    return
  endif

  if last_button is not NO_EVENT:
    turn the last_button OFF
  if the event is not NO_EVENT or POWER_OFF
    turn the button represented by the event ON
  endif

  set last_button equal to event
HandleCheatEvents(Takes a constant indicating the direction event, no event, or
                   Atari power off.)
  initialize the static variable last_event to NO_EVENT
  initialize the static variable step to 0
  initialize the static variable last_time to 0

  if the power is OFF:
    set step to 0
    turn off the fans
    return
  endif

  if the passed-in event is NO_EVENT or the last_event is the same as event or step
     equals 3:
    return
  endif

  if step is 0:
    store DOWN as the next move
    set last_time to the current time
  else if step is 1:
    store RIGHT as the next move
  else if step is 2:
    store UP as the next move
  endif

  if the current time minus last_time is less than CHEAT_TIMEOUT and the event is
     the same as the next move:
    increment step
  else:
    set step to 0
  endif

  if step is 3:
    turn on the fans
  endif

  set last_event to event