From 46944be3ce2659277792e3d197c362182c918a9b Mon Sep 17 00:00:00 2001 From: cuu Date: Thu, 27 May 2021 13:28:13 +0800 Subject: [PATCH] minor mod for trackball add read_adc to read temperature for thermal_printer --- Code/devterm_keyboard/devterm_keyboard.ino | 2 +- Code/devterm_keyboard/trackball.h | 6 +++--- Code/thermal_printer/config.h | 5 +++-- Code/thermal_printer/printer.c | 23 +++++++++++++++++++++- Code/thermal_printer/printer.h | 1 + 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Code/devterm_keyboard/devterm_keyboard.ino b/Code/devterm_keyboard/devterm_keyboard.ino index 133a389..aeba312 100644 --- a/Code/devterm_keyboard/devterm_keyboard.ino +++ b/Code/devterm_keyboard/devterm_keyboard.ino @@ -5,7 +5,7 @@ #include -#define SER_NUM_STR "20210517" +#define SER_NUM_STR "20210515" USBHID HID; DEVTERM dev_term; diff --git a/Code/devterm_keyboard/trackball.h b/Code/devterm_keyboard/trackball.h index a6ec1fa..289fa2b 100644 --- a/Code/devterm_keyboard/trackball.h +++ b/Code/devterm_keyboard/trackball.h @@ -5,9 +5,9 @@ #include "keys_io_map.h" -#define BOUNCE_INTERVAL 30 -#define BASE_MOVE_PIXELS 5 -#define EXPONENTIAL_BOUND 15 +#define BOUNCE_INTERVAL 100 +#define BASE_MOVE_PIXELS 3 +#define EXPONENTIAL_BOUND 10 #define EXPONENTIAL_BASE 1.2 #define BTN_PIN KEY0 diff --git a/Code/thermal_printer/config.h b/Code/thermal_printer/config.h index 94f2ed7..aa91b11 100644 --- a/Code/thermal_printer/config.h +++ b/Code/thermal_printer/config.h @@ -112,14 +112,15 @@ #define BCoefficent 3950 #define RthNominal 30000 #define TempNominal 25 -#define ADCResolution 4096 +#define ADCResolution 1024 #define SeriesResistor 30000 - #define NumSamples 10 #define KELVIN 1 #define CELSIUS 0 +#define ADC_FILE "/sys/class/i2c-dev/i2c-1/device/1-0054/iio:device1/in_voltage_raw" + #define HEAT_TIME 300 // heat time,better not greater than 1000,300-1000 0-f #define int16 uint16_t diff --git a/Code/thermal_printer/printer.c b/Code/thermal_printer/printer.c index 2e72e35..ca9fff8 100644 --- a/Code/thermal_printer/printer.c +++ b/Code/thermal_printer/printer.c @@ -333,6 +333,26 @@ void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_ return; } +uint16_t read_adc() { + long ret; + char c[16]; + FILE *fptr; + 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; + } + fscanf(fptr, "%[^\n]", c); + //printf("Data from the file:\n%s", c); + fclose(fptr); + + ret = strtol(c, NULL, 10); + //printf("the number ret %d\n",ret); + + return (uint16_t)ret; +} + + uint16_t temperature() { @@ -344,7 +364,8 @@ uint16_t temperature() { while(Sample<=NumSamples) { - ADCSamples += analogRead(THERMISTORPIN); + //ADCSamples += analogRead(THERMISTORPIN); //stm32 + ADCSamples += read_adc(); Sample++; } //Thermistor Resistance at x Kelvin diff --git a/Code/thermal_printer/printer.h b/Code/thermal_printer/printer.h index 2f226e1..82a8c38 100644 --- a/Code/thermal_printer/printer.h +++ b/Code/thermal_printer/printer.h @@ -26,6 +26,7 @@ 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 temperature(); uint8_t print_lines8(CONFIG*);