Skip to content

Initial APDS Gesture Sensor Code Module commit

Jonathan Doctolero requested to merge apdsModule into FollowMeVideoGame

Gesture Sensor Code Module based on APDS-9960:

Gesture Sensor is initialized at startup in entry_point() via sensors_init(). To obtain gesture data use #include "apds.h" and use apds__get_gesture() to return a apds_gesture_s type.

Example

void get_gesture_task(void *params) {
  apds__gesture_s userInput = ERROR;

  while (1) {
    userInput = apds__get_gesture();
    if (userInput != ERROR) {
      printf("userInput = %c\n", userInput);
    }
    vTaskDelay(1000);
  }
}

A task polls to check if a gesture event occured. If so, it'll print 'U', 'D', 'L', 'R', 'N', or 'F' according to the gesture that was detected and then sleep for 1 second. If no gesture event occured, then the task will sleep for 1 second.

  • Example Use Case:

    If there was a valid gesture detected, then send the user input to a queue. Another task will read from that queue and change states according to the user input, if there is no data on the queue, then don't change states.

Detailed Explanation how the Gesture Sensor Code Module works

  1. APDS-9960 will update its Gesture Status Register (GSTATUS: 0xAF) if there is valid data in the gesture FIFOs for Up, Down, Left, and Right IR photodiodes on the sensor.
  2. Bit 0 of GSTATUS will be 1 if there is valid data, else 0 if there is no gesture data collected.
  3. If GSTATUS[0] == 1, then read the FIFO level from the Gesture FIFO Level Register (GFLVL: 0xAE). Values in GFLVL will be between 0 and 32, inclusively. The value indicates how many sets of bytes are in the FIFO to be read. For example, if GFLVl == 32, then you have to read 32*4 bytes from the FIFO registers.
  4. Start I2C read of GFLVL*4 bytes starting at Gesture FIFO Up Register (GFIFO_U: 0xFC). Save the data to an array to be processed. Data is represented in values 0 to 255, as seen in Fig 1 below.
  5. Gesture data is set up in pairs: Up-Down and Left-Right. Therefore, check which pair has the largest difference.
  6. Then check which photodiode of the pair has the smallest value. That photodiode was passed over first. Record that photodiode in an array.
  7. Once all the raw gesture data is processed and you have a series of photodiodes saved in an array. Process that photodiode array. Photodiode array is represented in the second to last line of Fig 1 below.
  8. At the first index, check if the next photodiode is part of the pair. For example: photodiode_array[0] == U and photodiode_array[1] == D, then the gesture that occured was a swipe down. Return 'D' for down.

Screen_Shot_2021-11-23_at_6.47.11_PM

Fig 1. Data printout on Telemetry showing a Down gesture occured.

Screen_Shot_2021-11-23_at_7.05.29_PM

Fig 2. From Avago APDS-9960 Datasheet: Shows the values vs time of the photodiode for up, down, left, right. The photodiode opposite of the direction of motion will receive more IR light compared to the photodiode closest to the start of the motion.

Edited by Jonathan Doctolero

Merge request reports