b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <lynq/lynq-adc.h> |
| 5 | |
| 6 | void handle_adc(const char* adc_name, int adc_type) |
| 7 | { |
| 8 | if (adc_name == NULL) |
| 9 | { |
| 10 | printf("Error: adc_name is a null pointer\n"); |
| 11 | return; |
| 12 | } |
| 13 | int adc_value = qser_adc_show((ADC_CHANNEL_E)adc_type); |
| 14 | if (adc_value < 0) |
| 15 | { |
| 16 | printf("Error: Failed to get the value of %s\n", adc_name); |
| 17 | return; |
| 18 | } |
| 19 | printf("%s value: %d mV\n", adc_name, adc_value); |
| 20 | } |
| 21 | |
| 22 | int main(int argc, char *argv[]) |
| 23 | { |
| 24 | if (argc != 2) |
| 25 | { |
| 26 | printf("Usage: %s <ADC0|ADC1|ADC2>\n", argv[0]); |
| 27 | return -1; |
| 28 | } |
| 29 | |
| 30 | if (strcmp(argv[1], "ADC0") == 0) |
| 31 | { |
| 32 | handle_adc("ADC0", ADC0); |
| 33 | } |
| 34 | else if (strcmp(argv[1], "ADC1") == 0) |
| 35 | { |
| 36 | handle_adc("ADC1", ADC1); |
| 37 | } |
| 38 | else if (strcmp(argv[1], "ADC2") == 0) |
| 39 | { |
| 40 | handle_adc("ADC2", ADC2); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | printf("Please enter valid parameters: ADC0|ADC1|ADC2\n"); |
| 45 | return -1; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |