mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-08-12 09:57:01 +00:00
ESP-IDF Robot Controls
This commit is contained in:
@@ -802,6 +802,35 @@ void app_main(void)
|
||||
/* Toggle the LED state */
|
||||
gpio_set_level(BLINK_GPIO, s_led_state);
|
||||
s_led_state = !s_led_state;
|
||||
|
||||
|
||||
|
||||
// ADC
|
||||
adc_ret = adc_continuous_read(handle, result, EXAMPLE_READ_LEN, &ret_num, 0);
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGI("TASK", "ret is %x, ret_num is %"PRIu32" bytes", ret, ret_num);
|
||||
for (int i = 0; i < ret_num; i += SOC_ADC_DIGI_RESULT_BYTES) {
|
||||
adc_digi_output_data_t *p = (adc_digi_output_data_t*)&result[i];
|
||||
uint32_t chan_num = EXAMPLE_ADC_GET_CHANNEL(p);
|
||||
uint32_t data = EXAMPLE_ADC_GET_DATA(p);
|
||||
/* Check the channel number validation, the data is invalid if the channel num exceed the maximum channel */
|
||||
if (chan_num < SOC_ADC_CHANNEL_NUM(EXAMPLE_ADC_UNIT)) {
|
||||
ESP_LOGI(TAG, "Unit: %s, Channel: %"PRIu32", Value: %"PRIx32, unit, chan_num, data);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Invalid data [%s_%"PRIu32"_%"PRIx32"]", unit, chan_num, data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Because printing is slow, so every time you call `ulTaskNotifyTake`, it will immediately return.
|
||||
* To avoid a task watchdog timeout, add a delay here. When you replace the way you process the data,
|
||||
* usually you don't need this delay (as this task will block for a while).
|
||||
*/
|
||||
vTaskDelay(1);
|
||||
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||
//We try to read `EXAMPLE_READ_LEN` until API returns timeout, which means there's no available data
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user