add glob to find i2c adc device path

This commit is contained in:
cuu 2021-05-28 12:26:30 +08:00
parent 9c0e674f78
commit a3530fd6cf
3 changed files with 29 additions and 5 deletions

View File

@ -119,7 +119,7 @@
#define KELVIN 1
#define CELSIUS 0
#define ADC_FILE "/sys/class/i2c-dev/i2c-1/device/1-0054/iio:device1/in_voltage_raw"
#define ADC_FILE_PAT "/sys/bus/iio/devices/iio:device*/in_voltage_raw"
#define HEAT_TIME 300 // heat time,better not greater than 1000,300-1000 0-f

View File

@ -3,6 +3,7 @@
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <glob.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
@ -24,6 +25,9 @@ static unsigned int printer_vps_time;
static uint8_t printer_vps_last_status;
static uint8_t printer_temp_check;
static char adc_file_path[128];
void printer_send_data8(uint8_t w)
{
/*
@ -135,6 +139,9 @@ uint8_t header_init() {
printer_vps_time = 0;
printer_vps_last_status = IS_PAPER;
printer_temp_check= 0;
glob_file(ADC_FILE_PAT);
}
@ -345,11 +352,11 @@ void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_
return;
}
uint16_t read_adc() {
uint16_t read_adc(char*adc_file) {
long ret;
char c[16];
FILE *fptr;
if ((fptr = fopen(ADC_FILE, "r")) == NULL) {
if ((fptr = fopen(adc_file, "r")) == NULL) {
printf("Error! ADC File cannot be opened\n");
// Program exits if the file pointer returns NULL.
return 0;
@ -377,7 +384,7 @@ uint16_t temperature() {
while(Sample<=NumSamples)
{
//ADCSamples += analogRead(THERMISTORPIN); //stm32
ADCSamples += read_adc();
ADCSamples += read_adc(adc_file_path);
Sample++;
}
//Thermistor Resistance at x Kelvin
@ -397,6 +404,22 @@ uint16_t temperature() {
//return (uint16_t)(0);
}
int glob_file(char*av) {
glob_t globlist;
if (glob(av, GLOB_PERIOD|GLOB_NOSORT, NULL, &globlist) == GLOB_NOSPACE || glob(av, GLOB_PERIOD|GLOB_NOSORT, NULL, &globlist) == GLOB_NOMATCH)
return -1;
if (glob(av, GLOB_PERIOD|GLOB_NOSORT, NULL, &globlist) == GLOB_ABORTED)
return 1;
if(globlist.gl_pathc > 0) {
strcpy(adc_file_path,globlist.gl_pathv[0]);
}
return 0;
}
#endif

View File

@ -26,8 +26,9 @@ void print_dots_8bit_split(CONFIG*cfg,uint8_t *Array, uint8_t characters);
void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_num);
uint16_t read_adc();
uint16_t read_adc(char*);
uint16_t temperature();
int glob_file(char*);
uint8_t print_lines8(CONFIG*);