Forráskód Böngészése

add glob to find i2c adc device path

cuu 3 éve
szülő
commit
a3530fd6cf

+ 1 - 1
Code/thermal_printer/config.h

@@ -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
 

+ 26 - 3
Code/thermal_printer/printer.c

@@ -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
 

+ 2 - 1
Code/thermal_printer/printer.h

@@ -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*);