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

change max print pts with battery level

cuu 3 éve
szülő
commit
0824e292fd

+ 4 - 1
Code/thermal_printer/config.h

@@ -123,6 +123,8 @@
 
 #define HEAT_TIME 100 // heat time,better not greater than 1000,300-1000 0-f
 
+#define BAT_CAP "/sys/class/power_supply/axp20x-battery/capacity"
+
 #define int16               uint16_t
 #define int8                uint8_t
 
@@ -206,7 +208,8 @@ typedef struct _CONFIG
   uint8_t density:4; //0-f,300+density*46 HEAT_TIME
 
   uint16_t wordgap:10;//1023 max
-  
+  uint8_t max_pts;// max pts in print_dots_8bit_split
+
   Margin margin;
   FONT*font;
   ImageCache *img;

+ 1 - 0
Code/thermal_printer/devterm_thermal_printer.c

@@ -119,6 +119,7 @@ void init_printer(){
   g_config.density = 0;
 
   g_config.feed_pitch = 2;
+  g_config.max_pts = 1;
   
 }
 

+ 27 - 2
Code/thermal_printer/printer.c

@@ -252,13 +252,13 @@ void print_dots_8bit_split(CONFIG*cfg,uint8_t *Array, uint8_t characters)
 
     pts = pts + bits_number(Array[i]);
     
-    if(pts > MAX_PRINT_PTS) {
+    if(pts > cfg->max_pts) {
       memset(temp,0,48);
       memcpy(temp,_array,i);
       print_dots_8bit(cfg,temp,characters,0);
       pts = bits_number(_array[i]);
       memset(_array,0,i);
-    }else if(pts==MAX_PRINT_PTS) {
+    }else if(pts==cfg->max_pts) {
       memset(temp,0,48);
       memcpy(temp,_array,i+1);      
       print_dots_8bit(cfg,temp,characters,0);
@@ -423,6 +423,28 @@ int glob_file(char*av) {
 
 #endif
 
+int bat_cap_to_pts(CONFIG*cfg) {
+  int pts;
+  long ret;
+  char c[12];
+  FILE *fptr;
+  if ((fptr = fopen(BAT_CAP, "r")) == NULL) {
+    printf("Error! Battery File cannot be opened\n");
+    // Program exits if the file pointer returns NULL.
+    return 0;
+  }
+
+  fscanf(fptr, "%[^\n]", c);
+  //printf("Data from the file:%s\n", c);
+  fclose(fptr);
+
+  ret = strtol(c, NULL, 10);
+  
+  pts = (int)round( (float)ret/10.0 ) + 1;
+  return pts;
+}
+
+
 
 uint8_t print_lines8(CONFIG*cfg) {
   uint8_t i,j,k;
@@ -454,6 +476,8 @@ uint8_t print_lines8(CONFIG*cfg) {
   
   row = 0;
   rv = IsPaper();
+  
+  cfg->max_pts = bat_cap_to_pts(cfg);
 
   data = (uint8_t*)malloc(sizeof(uint8_t)*(pad+1));
   i=0;
@@ -583,6 +607,7 @@ uint8_t print_image8(CONFIG*cfg){
   addr = 0;
   
   rv = IsPaper();
+  cfg->max_pts = bat_cap_to_pts(cfg);
   while(y < height )
   {
     x=0;

+ 2 - 2
Code/thermal_printer/printer.h

@@ -3,8 +3,8 @@
 
 #include "config.h"
 
-#define PRINT_SPLIT 6 // max points printed at the same time, 384/PRINT_SPLIT==96
-#define MAX_PRINT_PTS 24
+//#define PRINT_SPLIT 6 // max points printed at the same time, 384/PRINT_SPLIT==96
+//#define MAX_PRINT_PTS 2
 
 void printer_send_data8(uint8_t);