/*InitUltrasonic*/ // Initialize echo and trigger pins // Initialize input capture on echo pins to highest priority and detect every edge /*PostUltrasonic*/ // Allows external code to post an event to this queue /*RunUltrasonic*/ //ES_INIT event // Initialize a one-third second timer //ES_TIMEOUT event // Clear trigger pins // Initialize a one-third second timer //EV_ECHO event // Convert echo pulse width to distance in centimeters // If calculated distance is closer than a nearness threshold and near sent flag not set Set near sent flag Post object is near event to motor // If calculated distance is farther than a farness threshold and far sent flag not set Set far sent flag Post object is far event to motor //EV_REAR_ECHO event // Same as EV_ECHO event handler with rear sensor specific flags /*IC3 Handler*/ Input capture for front ultrasonic sensor // Set front trigger pin // Read input capture buffer // If timer interrupt set and input capture value is less than 0x8000 // Increment rollover // Clear timer interrupt // Calculate pulse width // If falling edge // Post EV_ECHO event to UltrasonicService with calculated pulse width // Clear input capture interrupt /*IC4 Handler*/ Input capture for rear ultrasonic sensor // Same as IC3 Handler but posts EV_REAR_ECHO and sets rear trigger pin