feat(apds9960): 手势原始数据读取

This commit is contained in:
Ivan Li 2023-03-08 23:02:48 +08:00
parent e426829aa6
commit 33e08edeed

View File

@ -238,7 +238,7 @@ void apds_9960_fetch(void* arg) {
uint16_t green_raw;
uint16_t blue_raw;
uint16_t clear_raw;
uint8_t gesture_fifo_level_raw;
uint8_t byte_buffer;
uint8_t gesture_status_raw;
uint8_t status_raw;
char red_str[10];
@ -267,6 +267,15 @@ void apds_9960_fetch(void* arg) {
ESP_LOGD(APDS_9960_TAG, "Status: %2x", status_raw);
}
error = apds_9960_read_byte(APDS_9960_REG_GFLVL, &byte_buffer);
if (error != ESP_OK) {
ESP_LOGW(APDS_9960_TAG, "read APDS_9960_REG_GFLVL failed. %d", error);
}
if (byte_buffer == 0) {
sprintf(status_str, "LVL: %4d", byte_buffer);
display_print8_str(0, 4, status_str);
}
// // clear
// error = apds_9960_read_word(APDS_9960_REG_CDATAL, &clear_raw);
// if (error != ESP_OK) {
@ -318,9 +327,6 @@ void apds_9960_auto_fetch() {
void apds_9960_read_gesture() {
ESP_LOGI(APDS_9960_TAG, "apes_9960_gesture_fetch");
if (is_apds_9960_online == 0) {
return;
}
uint8_t byte_buffer;
esp_err_t error;
uint32_t gesture_values_raw_arr[32];
@ -350,7 +356,7 @@ void apds_9960_read_gesture() {
error = apds_9960_read_bytes_len(
APDS_9960_REG_GFIFO_U, (uint8_t*)gesture_values_raw_arr, byte_buffer * 4);
apds_9960_write(APDS_9960_REG_GCONF4, 0x06);
if (error != ESP_OK) {
ESP_LOGW(APDS_9960_TAG, "read APDS_9960_REG_GFIFO(len: %d) failed. % d",
byte_buffer * 4, error);
@ -393,33 +399,31 @@ void apds_9960_int_handler(void* arg) {
}
void apds_9960_int_evt_handler() {
if (is_apds_9960_online == 0) {
return;
}
ESP_ERROR_CHECK(apds_9960_write_empty(APDS_9960_REG_AICLEAR));
// enable gesture interrupt
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_GCONF4, 0x06));
esp_err_t error;
uint8_t status_raw;
while (xQueueReceive(apds_9960_int_evt_queue, NULL, portMAX_DELAY)) {
error = apds_9960_read_byte(APDS_9960_REG_STATUS, &status_raw);
ESP_ERROR_RETRY(apds_9960_read_byte(APDS_9960_REG_STATUS, &status_raw), 10);
ESP_ERROR_RETRY(apds_9960_write_empty(APDS_9960_REG_AICLEAR), 10);
if (error != ESP_OK) {
ESP_LOGW(APDS_9960_TAG,
"[apds_9960_int_evt_handler] read status failed. %d", error);
continue;
}
ESP_LOGW(
ESP_LOGI(
APDS_9960_TAG, "[apds_9960_int_evt_handler] status %d%d%d%d %d%d%d%d",
(status_raw >> 7) & 1, (status_raw >> 6) & 1, (status_raw >> 5) & 1,
(status_raw >> 4) & 1, (status_raw >> 3) & 1, (status_raw >> 2) & 1,
(status_raw >> 1) & 1, status_raw & 1);
if (status_raw & APDS_9960_PINT) {
apds_9960_read_proximity();
} else {
ESP_LOGW(APDS_9960_TAG, "Proximity interrupt not set. %x",
status_raw & APDS_9960_PINT);
}
if (status_raw & APDS_9960_GINT) {
apds_9960_read_gesture();
}
vTaskDelay(10 / portTICK_PERIOD_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
@ -449,21 +453,29 @@ void apds_9960_init() {
apds_9960_write(APDS_9960_REG_CONTROL, APDS_9960_CONTROL_VALUE));
// enable gesture interrupt
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_GCONF4, 0x03));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_GCONF4, 0x06));
// 累积的手势数据达到 4 组时触发中断
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_GCONF1, 0x40));
// Gesture Enter Threshold
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_GPENTH, 20));
// Gesture Exit Threshold
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_GEXTH, 10));
// Gesture Drive Strength
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_GCONF2, 0x40));
// set wait time
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_WTIME, 171));
// set interrupt persistence
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_PERS, 0x44));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_PILT, 40));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_PIHT, 200));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_PILT, 0x80));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_PIHT, 0x40));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_CONFIG2, 0x80));
// // enable sleep after interrupt
// ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_CONFIG3, 0x10));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_ENABLE, 0b00101101));
ESP_ERROR_CHECK(apds_9960_write(APDS_9960_REG_ENABLE, 0b01101101));
apds_9960_int_evt_queue = xQueueCreate(10, NULL);
xTaskCreate(apds_9960_int_evt_handler, "apds_9960_gesture_fetch", 2048, NULL,