Browse Source

indent code with clang-format, add rotation

cuu 2 years ago
parent
commit
31670a4428

+ 101 - 112
Code/thermal_printer/config.h

@@ -1,10 +1,10 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-#include <freetype2/ft2build.h>
 #include <freetype/freetype.h>
+#include <freetype2/ft2build.h>
 
-///raspberry pi CM3 
+/// raspberry pi CM3
 
 #define BCM_GPIO_28 28
 #define BCM_GPIO_29 29
@@ -25,27 +25,28 @@
 #define BCM_GPIO_44 44
 #define BCM_GPIO_45 45
 
-//PA8-12 UART1
-//#define SPI1_NSS_PIN PA4    //SPI_1 Chip Select pin is PA4. //no use in DevTerm 
+// PA8-12 UART1
+//#define SPI1_NSS_PIN PA4    //SPI_1 Chip Select pin is PA4. //no use in
+//DevTerm
 
-#define VH_PIN BCM_GPIO_40 //ENABLE_VH required,PRT_EN
+#define VH_PIN BCM_GPIO_40 // ENABLE_VH required,PRT_EN
 
-#define LATCH_PIN BCM_GPIO_36  //18
-#define PEM_PIN  BCM_GPIO_34 // 1 [PS,PAPER]
+#define LATCH_PIN BCM_GPIO_36 // 18
+#define PEM_PIN BCM_GPIO_34   // 1 [PS,PAPER]
 
 /*
-#define PEM_CTL_PIN BCM_GPIO_32 //3 VPS 
+#define PEM_CTL_PIN BCM_GPIO_32 //3 VPS
 #define ENABLE_PEM digitalWrite(PEM_CTL_PIN,HIGH)
-#define DISABLE_PEM digitalWrite(PEM_CTL_PIN,LOW) 
+#define DISABLE_PEM digitalWrite(PEM_CTL_PIN,LOW)
 */
-//DevTerm no VPS IO
-//#define PEM_CTL_PIN 
-#define ENABLE_PEM 
-#define DISABLE_PEM 
+// DevTerm no VPS IO
+//#define PEM_CTL_PIN
+#define ENABLE_PEM
+#define DISABLE_PEM
 
 // https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
-//enable SPI0 ALT0 in CM3 first
-// in /boot/config.txt 
+// enable SPI0 ALT0 in CM3 first
+// in /boot/config.txt
 // dtparam=spi=on
 // dtoverlay=spi-gpio35-39
 // then we can see GPIO38 GPIO39 in ALT0 Mode by `gpio readall`
@@ -53,74 +54,68 @@
 #define MOSI_PIN BCM_GPIO_38
 #define CLK_PIN BCM_GPIO_39
 
-
 /**
-  *@brief STB_NUMBER stand for STROBE NUMBER of lines, which means how many lines
-  *        are going to be activated
-**/
-#define STB_NUMBER        1
-
-#define STB1_PIN  BCM_GPIO_37//13
-#define STB2_PIN  STB1_PIN 
-#define STB3_PIN  STB1_PIN 
-#define STB4_PIN  STB1_PIN 
-#define STB5_PIN  STB1_PIN 
-#define STB6_PIN  STB1_PIN 
-
+ *@brief STB_NUMBER stand for STROBE NUMBER of lines, which means how many lines
+ *        are going to be activated
+ **/
+#define STB_NUMBER 1
+
+#define STB1_PIN BCM_GPIO_37 // 13
+#define STB2_PIN STB1_PIN
+#define STB3_PIN STB1_PIN
+#define STB4_PIN STB1_PIN
+#define STB5_PIN STB1_PIN
+#define STB6_PIN STB1_PIN
 
 #define PH1_PIN BCM_GPIO_28
 #define PH2_PIN BCM_GPIO_29
 #define PH3_PIN BCM_GPIO_30
 #define PH4_PIN BCM_GPIO_31
 
-///0 1 3 2 mine
-#define PA_PIN  PH1_PIN //
+/// 0 1 3 2 mine
+#define PA_PIN PH1_PIN  //
 #define PNA_PIN PH2_PIN //
-#define PB_PIN  PH3_PIN //
+#define PB_PIN PH3_PIN  //
 #define PNB_PIN PH4_PIN //
 
-
-
 //#define ENABLE1_PIN  PA13
 //#define ENABLE2_PIN  PA14
 
-#define THERMISTORPIN BCM_GPIO_35  //ADC,14
-
+#define THERMISTORPIN BCM_GPIO_35 // ADC,14
 
 #define MOTOR_ENABLE1
-#define MOTOR_ENABLE2 
+#define MOTOR_ENABLE2
+
+#define MOTOR_DISABLE1
+#define MOTOR_DISABLE2
 
-#define MOTOR_DISABLE1  
-#define MOTOR_DISABLE2 
- 
 #define ENABLE_VH digitalWrite(VH_PIN, HIGH)
 #define DISABLE_VH digitalWrite(VH_PIN, LOW)
 
 #define LATCH_ENABLE digitalWrite(LATCH_PIN, LOW)
 #define LATCH_DISABLE digitalWrite(LATCH_PIN, HIGH)
 
-#define ASK4PAPER  digitalRead(PEM_PIN)
+#define ASK4PAPER digitalRead(PEM_PIN)
 
+#define ERROR_FEED_PITCH ((uint8_t)0x01)
+#define IS_PAPER 0x00
+#define NO_PAPER 0x01
+#define HOT_PRINTER 0x02
 
-#define ERROR_FEED_PITCH  ((uint8_t) 0x01)
-#define IS_PAPER          0x00
-#define NO_PAPER          0x01
-#define HOT_PRINTER       0x02
-
-#define FORWARD           0x01
-#define BACKWARD          0x00
+#define FORWARD 0x01
+#define BACKWARD 0x00
 
 #define HOT 64
 
-#define BCoefficent       3950
-#define RthNominal        30000
-#define TempNominal       25 
-#define ADCResolution     1024
-#define SeriesResistor    30000
-#define NumSamples        1
+#define BCoefficent 3950
+#define RthNominal 30000
+#define TempNominal 25
+#define ADCResolution 1024
+#define SeriesResistor 30000
+#define NumSamples 1
 
-#define KELVIN            1
-#define CELSIUS           0
+#define KELVIN 1
+#define CELSIUS 0
 
 #define ADC_FILE_PAT "/tmp/devterm_adc"
 
@@ -129,28 +124,26 @@
 #define BAT_CAP "/sys/class/power_supply/axp20x-battery/capacity"
 #define BAT_THRESHOLD 14 // %14 battery = low power
 
-#define int16               uint16_t
-#define int8                uint8_t
-
-#define asciistart          ((uint8_t)'A')
-#define netxcharacter       ((uint8_t)24)
-#define Fontrows            ((uint8_t)24)
-#define FontColums          ((uint8_t)16)
-
-#define nextcharactercolum  ((uint8_t)Fontrows/8) // = 3
+#define int16 uint16_t
+#define int8 uint8_t
 
+#define asciistart ((uint8_t)'A')
+#define netxcharacter ((uint8_t)24)
+#define Fontrows ((uint8_t)24)
+#define FontColums ((uint8_t)16)
 
+#define nextcharactercolum ((uint8_t)Fontrows / 8) // = 3
 
 #define ASCII_TAB '\t' // Horizontal tab
-#define ASCII_LF  '\n' // Line feed,10
-#define ASCII_FF  '\f' // Form feed
-#define ASCII_CR  '\r' // Carriage return
-#define ASCII_EOT   4  // End of Transmission
-#define ASCII_DLE  16  // Data Link Escape
-#define ASCII_DC2  18  // Device control 2 //0x12
-#define ASCII_ESC  27  // Escape //0x1b
-#define ASCII_FS   28  // Field separator//0x1c
-#define ASCII_GS   29  // Group separator //0x1d
+#define ASCII_LF '\n'  // Line feed,10
+#define ASCII_FF '\f'  // Form feed
+#define ASCII_CR '\r'  // Carriage return
+#define ASCII_EOT 4    // End of Transmission
+#define ASCII_DLE 16   // Data Link Escape
+#define ASCII_DC2 18   // Device control 2 //0x12
+#define ASCII_ESC 27   // Escape //0x1b
+#define ASCII_FS 28    // Field separator//0x1c
+#define ASCII_GS 29    // Group separator //0x1d
 
 #define PRINT_STATE 0
 #define ESC_STATE 1
@@ -164,7 +157,6 @@
 
 #define BITS8 8
 
-
 #define MAX_DOTS 384
 #define PRINTER_BITS MAX_DOTS
 #define MAXPIXELS 48
@@ -178,81 +170,78 @@
 #define FONT_MODE_0 0 // Internal
 #define FONT_MODE_1 1 // External
 
-//extract bits 
-#define LAST(k,n) ((k) & ((1<<(n))-1))
-#define MID(k,m,n) LAST((k)>>(m),((n)-(m)))
-
+// extract bits
+#define LAST(k, n) ((k) & ((1 << (n)) - 1))
+#define MID(k, m, n) LAST((k) >> (m), ((n) - (m)))
 
-typedef struct _Margin{
+typedef struct _Margin {
   uint16_t width;
   uint8_t esgs;
-}Margin;
-
+} Margin;
 
 typedef struct _FONT {
 
-  uint8_t width;//in bits
+  uint8_t width; // in bits
   uint8_t height;
-  uint8_t mode;//0 internal pcf font array,1 external ttf font file
+  uint8_t mode; // 0 internal pcf font array,1 external ttf font file
   const uint8_t *data;
-  char*file;
-}FONT;
+  char *file;
+} FONT;
+
+typedef struct _ImageCache {
 
-typedef struct _ImageCache{
-  
   uint16_t idx;
   uint16_t num;
   uint16_t width;
   uint16_t height;
-  uint8_t need_print:1;
-  uint8_t revert_bits:1;//MSB OR LSB
+  uint8_t need_print : 1;
+  uint8_t revert_bits : 1;  // MSB OR LSB
   uint8_t cache[IMAGE_MAX]; // 48x192bytes(384x192 pixels) ,max
-  
-}ImageCache;
 
-typedef struct _CONFIG
-{  
+} ImageCache;
+
+typedef struct _CONFIG {
   uint8_t state;
   uint8_t line_space;
   uint8_t align;
-  uint8_t reverse; //reverse print   
+  uint8_t reverse; // reverse print
   uint8_t orient;
   uint8_t under_line;
   uint8_t feed_pitch;
-  uint8_t density:4; //0-f,300+density*46 HEAT_TIME
+  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
+  uint16_t wordgap : 10; // 1023 max
+  uint8_t max_pts;       // max pts in print_dots_8bit_split
   uint8_t lock;
-  
+  int16_t degree; // char rotate 0,90,180,270, -90,-180,-270
+
   Margin margin;
-  FONT*font;
+  FONT *font;
   ImageCache *img;
-  FILE*fp;
-  
+  FILE *fp;
+
   FT_Face face;
   FT_Library ft;
 
-  int (*printf)(struct _CONFIG*, char*, ...);
+  int (*printf)(struct _CONFIG *, char *, ...);
 
-}CONFIG;
+} CONFIG;
 
-
-typedef struct _SerialCache{
+typedef struct _SerialCache {
   uint8_t idx;
-  uint8_t utf8idx;//0-4
+  uint8_t utf8idx; // 0-4
   //  uint8_t data[77];//384/5, minium size font 5 pixel
-  uint32_t data[MAX_DOTS];//uint32_t for utf8 characters
-}SerialCache;
+  uint32_t data[MAX_DOTS]; // uint32_t for utf8 characters
+} SerialCache;
 
-typedef struct _TimeRec{
+typedef struct _TimeRec {
   unsigned int time;
   uint8_t last_status;
   uint8_t check;
-  
-}TimeRec;
 
-void PrintDots8bit(uint8_t *Array, uint8_t characters,uint8_t feed_num);
+} TimeRec;
+
+void PrintDots8bit(uint8_t *Array, uint8_t characters, uint8_t feed_num);
 
 uint8_t invert_bit(uint8_t a);
 

File diff suppressed because it is too large
+ 501 - 492
Code/thermal_printer/devterm_thermal_printer.c


+ 44 - 50
Code/thermal_printer/ftype.c

@@ -4,55 +4,49 @@
 
 static const UTF32 utf32_space[2] = {' ', 0};
 
+bool init_ft(const char *ttf_file, FT_Face *face, FT_Library *ft,
+             int req_size_w, int req_size_h, char **error) {
 
-bool init_ft (const char *ttf_file, FT_Face *face, FT_Library *ft,
-              int req_size_w,int req_size_h, char **error)
-{
-  
   bool ret = false;
-  if (FT_Init_FreeType (ft) == 0) {
+  if (FT_Init_FreeType(ft) == 0) {
     if (FT_New_Face(*ft, ttf_file, 0, face) == 0) {
-      
-      if(FT_Set_Pixel_Sizes(*face, req_size_w, req_size_h) == 0){
+
+      if (FT_Set_Pixel_Sizes(*face, req_size_w, req_size_h) == 0) {
         ret = true;
       } else {
         if (error)
-          *error = strdup ("Can't set font size");
+          *error = strdup("Can't set font size");
       }
-      
+
     } else {
       if (error)
-        *error = strdup ("Can't load TTF file");  
+        *error = strdup("Can't load TTF file");
     }
-    
-  }else{
+
+  } else {
     if (error)
-      *error = strdup ("Can't init freetype library");
+      *error = strdup("Can't init freetype library");
   }
 
   return ret;
 }
 
 /*===========================================================================
-  done_ft 
+  done_ft
   Clean up after we've finished wih the FreeType librar
   =========================================================================*/
-void done_ft(FT_Library ft)
-{
-  FT_Done_FreeType (ft);
-}
+void done_ft(FT_Library ft) { FT_Done_FreeType(ft); }
 
 /*===========================================================================
 
   face_get_line_spacing
 
-  Get the nominal line spacing, that is, the distance between glyph 
+  Get the nominal line spacing, that is, the distance between glyph
   baselines for vertically-adjacent rows of text. This is "nominal" because,
   in "real" typesetting, we'd need to add extra room for accents, etc.
 
   =========================================================================*/
-int face_get_line_spacing (FT_Face face)
-{
+int face_get_line_spacing(FT_Face face) {
   return face->size->metrics.height / 64;
   // There are other possibilities the give subtly different results:
   // return (face->bbox.yMax - face->bbox.yMin)  / 64;
@@ -61,42 +55,42 @@ int face_get_line_spacing (FT_Face face)
 
 int get_slice_len(const char lb) {
 
-  if( ( lb & 0x80 ) == 0 ) return  1;
-  else if( ( lb & 0xE0) == 0xC0) return 2;
-  else if( ( lb & 0xF0) == 0xE0) return 3;
-  else if( ( lb & 0xF8) == 0xF0) return 4;
+  if ((lb & 0x80) == 0)
+    return 1;
+  else if ((lb & 0xE0) == 0xC0)
+    return 2;
+  else if ((lb & 0xF0) == 0xE0)
+    return 3;
+  else if ((lb & 0xF8) == 0xF0)
+    return 4;
   return 1;
 }
 
-UTF32 *cjk_utf8_to_utf32 (const char *word)
-{
-  assert (word != NULL);
+UTF32 *cjk_utf8_to_utf32(const char *word) {
+  assert(word != NULL);
   int l = strlen(word);
   int u8l = utf8_strlen(word);
-  
+
   char buf[5];
-  
-  UTF32 *ret = malloc ((u8l + 1) * sizeof (UTF32));
-  int i=0,j=0;
-  int bskip=1;
-  
-  while( i<l )
-    {
-      
-      bskip = get_slice_len(word[i]);
-      strncpy(buf,&word[i],bskip);
-      if(bskip > 1) {
-        ret[j] = (UTF32)utf8_to_utf32(buf);
-      }else {
-        ret[j] = (UTF32)buf[0];
-      }
-      
-      j++;
-      i+=bskip;
+
+  UTF32 *ret = malloc((u8l + 1) * sizeof(UTF32));
+  int i = 0, j = 0;
+  int bskip = 1;
+
+  while (i < l) {
+
+    bskip = get_slice_len(word[i]);
+    strncpy(buf, &word[i], bskip);
+    if (bskip > 1) {
+      ret[j] = (UTF32)utf8_to_utf32(buf);
+    } else {
+      ret[j] = (UTF32)buf[0];
     }
-  
+
+    j++;
+    i += bskip;
+  }
+
   ret[u8l] = 0;
   return ret;
 }
-
-

+ 6 - 6
Code/thermal_printer/ftype.h

@@ -1,12 +1,12 @@
 #ifndef FTYPE_H
 #define FTYPE_H
 
+#include <assert.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdbool.h>
-#include <assert.h>
-
 #include <freetype2/ft2build.h>
+
 #include <freetype/freetype.h>
 
 #ifndef UTF8
@@ -17,10 +17,10 @@ typedef unsigned char UTF8;
 typedef int32_t UTF32;
 #endif
 
-bool init_ft (const char *ttf_file, FT_Face *face, FT_Library *ft,
-              int req_size_w,int req_size_h, char **error);
+bool init_ft(const char *ttf_file, FT_Face *face, FT_Library *ft,
+             int req_size_w, int req_size_h, char **error);
 
-int face_get_line_spacing (FT_Face face);
+int face_get_line_spacing(FT_Face face);
 
 int get_slice_len(const char lb);
 

+ 480 - 483
Code/thermal_printer/printer.c

@@ -1,14 +1,13 @@
+#include <glob.h>
+#include <math.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h> 
 #include <string.h>
-#include <math.h>
-#include <glob.h>
 
 #include <wiringPi.h>
 #include <wiringPiSPI.h>
 
-
 #include "config.h"
 
 #include "utils.h"
@@ -18,7 +17,7 @@
 extern FONT current_font;
 extern SerialCache ser_cache;
 
-uint16_t STBx[] = {STB1_PIN,STB2_PIN,STB3_PIN,STB4_PIN,STB5_PIN,STB6_PIN};
+uint16_t STBx[] = {STB1_PIN, STB2_PIN, STB3_PIN, STB4_PIN, STB5_PIN, STB6_PIN};
 uint8_t as;
 
 static unsigned int printer_vps_time;
@@ -27,333 +26,311 @@ static uint8_t printer_temp_check;
 
 static char adc_file_path[128];
 
-
-void printer_send_data8(uint8_t w)
-{
+void printer_send_data8(uint8_t w) {
   /*
-  digitalWrite(SPI1_NSS_PIN, LOW); // manually take CSN low for SPI_1 transmission
-  SPI.transfer(w); //Send the HEX data 0x55 over SPI-1 port and store the received byte to the <data> variable.
+  digitalWrite(SPI1_NSS_PIN, LOW); // manually take CSN low for SPI_1
+  transmission SPI.transfer(w); //Send the HEX data 0x55 over SPI-1 port and
+  store the received byte to the <data> variable.
   //SPI.transfer16(w);
-  digitalWrite(SPI1_NSS_PIN, HIGH); // manually take CSN high between spi transmissions
+  digitalWrite(SPI1_NSS_PIN, HIGH); // manually take CSN high between spi
+  transmissions
   */
-  wiringPiSPIDataRW (0, &w, 1);
-  
+  wiringPiSPIDataRW(0, &w, 1);
 }
 
+void clear_printer_buffer() {
+  uint8_t i = 0;
+
+  for (i = 0; i < 48; i++)
+    printer_send_data8(0x00);
 
-void clear_printer_buffer()
-{
-  uint8_t i= 0;
-  
-   for(i=0;i<48;i++)
-     printer_send_data8(0x00);
-  
   LATCH_ENABLE;
   delayus(1);
   LATCH_DISABLE;
   delayus(1);
 }
 
-
-uint8_t IsPaper()
-{
+uint8_t IsPaper() {
   uint8_t status;
   uint8_t tmp;
   return IS_PAPER;
- 
-  if(  millis() - printer_vps_time > 10) {
+
+  if (millis() - printer_vps_time > 10) {
     ENABLE_PEM;
-    if(ASK4PAPER==LOW) // * LOW is what we want**
-    {status = IS_PAPER;}
-    else
-    {status = NO_PAPER; PRINTF("Error:NO PAPER\n"); }
+    if (ASK4PAPER == LOW) // * LOW is what we want**
+    {
+      status = IS_PAPER;
+    } else {
+      status = NO_PAPER;
+      PRINTF("Error:NO PAPER\n");
+    }
     DISABLE_PEM;
 
-    if(printer_temp_check > 20) {
+    if (printer_temp_check > 20) {
       tmp = temperature();
-    
-      if (tmp >= HOT){
+
+      if (tmp >= HOT) {
         PRINTF("Printer too Hot\n");
         status |= HOT_PRINTER;
       }
 
-     printer_temp_check = 0;
+      printer_temp_check = 0;
 
-    }else {
-     printer_temp_check++;
+    } else {
+      printer_temp_check++;
     }
 
-  }else {
+  } else {
     status = printer_vps_last_status;
   }
-  
- 
+
   printer_vps_last_status = status;
   printer_vps_time = millis();
-  
+
   return status;
 }
 
-
 uint8_t header_init() {
-  
+
   uint8_t pin[] = {THERMISTORPIN};
-  
+
   uint8_t x;
-  pinMode(LATCH_PIN,OUTPUT);
+  pinMode(LATCH_PIN, OUTPUT);
 
-  for(x=0; x < STB_NUMBER; x++){
-    pinMode(STBx[x],OUTPUT);
-    digitalWrite(STBx[x],LOW);
+  for (x = 0; x < STB_NUMBER; x++) {
+    pinMode(STBx[x], OUTPUT);
+    digitalWrite(STBx[x], LOW);
   }
-  
+
   LATCH_DISABLE;
 
-  pinMode(VH_PIN,OUTPUT);
-  digitalWrite(VH_PIN,LOW);
+  pinMode(VH_PIN, OUTPUT);
+  digitalWrite(VH_PIN, LOW);
+
+  pinMode(PEM_PIN, INPUT);
+  // pinMode(PEM_CTL_PIN,OUTPUT);
+
+  // adc.setChannels(pin, 1); //this is actually the pin you want to measure
 
-  pinMode(PEM_PIN,INPUT);
-  //pinMode(PEM_CTL_PIN,OUTPUT);
+  pinMode(THERMISTORPIN, INPUT); // 数字io没有 模拟接口。adc 读温度暂时不搞
 
-  
-  //adc.setChannels(pin, 1); //this is actually the pin you want to measure
-  
-  pinMode(THERMISTORPIN,INPUT); // 数字io没有 模拟接口。adc 读温度暂时不搞 
-  
   /*
   //SPI.begin(); //Initialize the SPI_1 port.
   SPI.setBitOrder(MSBFIRST); // Set the SPI_1 bit order
   SPI.setDataMode(SPI_MODE0); //Set the  SPI_1 data mode 0
-  SPI.setClockDivider(SPI_CLOCK_DIV16);      // Slow speed (72 / 16 = 4.5 MHz SPI_1 speed)
-  SPI.setDataSize(DATA_SIZE_8BIT);
-  SPI.begin(); //Initialize the SPI_1 port.
+  SPI.setClockDivider(SPI_CLOCK_DIV16);      // Slow speed (72 / 16 = 4.5 MHz
+  SPI_1 speed) SPI.setDataSize(DATA_SIZE_8BIT); SPI.begin(); //Initialize the
+  SPI_1 port.
   */
-  if (!wiringPiSPISetup (0,  4500000 )) {
-	  PRINTF("SPI init failed,exiting...\n");
+  if (!wiringPiSPISetup(0, 4500000)) {
+    PRINTF("SPI init failed,exiting...\n");
   }
-  
+
   /*
-  pinMode(SPI1_NSS_PIN, OUTPUT);  
+  pinMode(SPI1_NSS_PIN, OUTPUT);
   digitalWrite(SPI1_NSS_PIN,HIGH);
   */
-  
+
   printer_vps_time = 0;
   printer_vps_last_status = IS_PAPER;
-  printer_temp_check= 0;
+  printer_temp_check = 0;
 
   glob_file(ADC_FILE_PAT);
-
 }
 
-
 #if 1
 
-uint8_t current_pos = 1; 
+uint8_t current_pos = 1;
 
 uint8_t header_init1() {
-  
-  pinMode(PA_PIN,OUTPUT);
-  pinMode(PNA_PIN,OUTPUT);
-  pinMode(PB_PIN,OUTPUT);
-  pinMode(PNB_PIN,OUTPUT);
+
+  pinMode(PA_PIN, OUTPUT);
+  pinMode(PNA_PIN, OUTPUT);
+  pinMode(PB_PIN, OUTPUT);
+  pinMode(PNB_PIN, OUTPUT);
 
   as = 0;
 
   return ASK4PAPER;
 }
 
-void motor_stepper_pos2(uint8_t position)//forward
+void motor_stepper_pos2(uint8_t position) // forward
 {
-//  position = 9 - position;
-//  position = (position+1)/2;
+  //  position = 9 - position;
+  //  position = (position+1)/2;
   delayMicroseconds(6700);
-  switch(position){
-    case 0:
-      digitalWrite(PA_PIN,LOW);
-      digitalWrite(PNA_PIN,LOW);
-      digitalWrite(PB_PIN,LOW);
-      digitalWrite(PNB_PIN,LOW);
-      break;   
-    case 1:
-      digitalWrite(PA_PIN,HIGH);
-      digitalWrite(PNA_PIN,LOW);
-      digitalWrite(PB_PIN,LOW);
-      digitalWrite(PNB_PIN,HIGH);
-      break;
-    case 2:
-      digitalWrite(PA_PIN,HIGH);
-      digitalWrite(PNA_PIN,LOW);
-      digitalWrite(PB_PIN,HIGH);
-      digitalWrite(PNB_PIN,LOW);
+  switch (position) {
+  case 0:
+    digitalWrite(PA_PIN, LOW);
+    digitalWrite(PNA_PIN, LOW);
+    digitalWrite(PB_PIN, LOW);
+    digitalWrite(PNB_PIN, LOW);
     break;
-    case 3:
-      digitalWrite(PA_PIN,LOW);
-      digitalWrite(PNA_PIN,HIGH);
-      digitalWrite(PB_PIN,HIGH);
-      digitalWrite(PNB_PIN,LOW);
+  case 1:
+    digitalWrite(PA_PIN, HIGH);
+    digitalWrite(PNA_PIN, LOW);
+    digitalWrite(PB_PIN, LOW);
+    digitalWrite(PNB_PIN, HIGH);
     break;
-    case 4:
-      digitalWrite(PA_PIN,LOW);
-      digitalWrite(PNA_PIN,HIGH);
-      digitalWrite(PB_PIN,LOW);
-      digitalWrite(PNB_PIN,HIGH);
+  case 2:
+    digitalWrite(PA_PIN, HIGH);
+    digitalWrite(PNA_PIN, LOW);
+    digitalWrite(PB_PIN, HIGH);
+    digitalWrite(PNB_PIN, LOW);
+    break;
+  case 3:
+    digitalWrite(PA_PIN, LOW);
+    digitalWrite(PNA_PIN, HIGH);
+    digitalWrite(PB_PIN, HIGH);
+    digitalWrite(PNB_PIN, LOW);
+    break;
+  case 4:
+    digitalWrite(PA_PIN, LOW);
+    digitalWrite(PNA_PIN, HIGH);
+    digitalWrite(PB_PIN, LOW);
+    digitalWrite(PNB_PIN, HIGH);
     break;
-
   }
 }
 
-uint8_t feed_pitch1(uint64_t lines, uint8_t forward_backward)
-{
+uint8_t feed_pitch1(uint64_t lines, uint8_t forward_backward) {
   uint8_t pos = current_pos;
-  uint8_t restor =  ~forward_backward;
-  
+  uint8_t restor = ~forward_backward;
+
   restor &= 0x01;
-  
-  if(lines>0)
-  {
+
+  if (lines > 0) {
     MOTOR_ENABLE1;
     MOTOR_ENABLE2;
     ENABLE_VH;
-    while(lines>0)
-    {
-      motor_stepper_pos2(pos);     /* 0.0625mm */
-      
-      if(pos >= 1 && pos <= 4)
-        pos = pos + (1 - 2*forward_backward); // adding or subtracting
-      if(pos < 1 || pos > 4)
-        pos = pos + (4 - 8*restor); // restoring pos
+    while (lines > 0) {
+      motor_stepper_pos2(pos); /* 0.0625mm */
+
+      if (pos >= 1 && pos <= 4)
+        pos = pos + (1 - 2 * forward_backward); // adding or subtracting
+      if (pos < 1 || pos > 4)
+        pos = pos + (4 - 8 * restor); // restoring pos
 
       lines--;
     }
     MOTOR_DISABLE1;
     MOTOR_DISABLE2;
     DISABLE_VH;
-    
-  }
-  else
-  {
+
+  } else {
     return ERROR_FEED_PITCH;
   }
   current_pos = pos;
   return 0;
-
 }
 
-void print_dots_8bit_split(CONFIG*cfg,uint8_t *Array, uint8_t characters) 
-{
-  uint8_t i=0,y=0, MAX=MAXPIXELS;
+void print_dots_8bit_split(CONFIG *cfg, uint8_t *Array, uint8_t characters) {
+  uint8_t i = 0, y = 0, MAX = MAXPIXELS;
   uint8_t blank;
   uint16_t pts;
   uint8_t temp[MAXPIXELS];
   uint8_t _array[MAXPIXELS];
   pts = 0;
-  memcpy(_array,Array,MAXPIXELS);
-  
-  while( (i< characters) && (i < MAX)) {
+  memcpy(_array, Array, MAXPIXELS);
+
+  while ((i < characters) && (i < MAX)) {
 
     pts = pts + bits_number(Array[i]);
-    
-    if(pts > cfg->max_pts) {
-      memset(temp,0,MAXPIXELS);
-      memcpy(temp,_array,i);
-      print_dots_8bit(cfg,temp,characters,0);
+
+    if (pts > cfg->max_pts) {
+      memset(temp, 0, MAXPIXELS);
+      memcpy(temp, _array, i);
+      print_dots_8bit(cfg, temp, characters, 0);
       pts = bits_number(_array[i]);
-      memset(_array,0,i);
-    }else if(pts==cfg->max_pts) {
-      memset(temp,0,MAXPIXELS);
-      memcpy(temp,_array,i+1);      
-      print_dots_8bit(cfg,temp,characters,0);
-      pts=0;
-      memset(_array,0,i+1);
+      memset(_array, 0, i);
+    } else if (pts == cfg->max_pts) {
+      memset(temp, 0, MAXPIXELS);
+      memcpy(temp, _array, i + 1);
+      print_dots_8bit(cfg, temp, characters, 0);
+      pts = 0;
+      memset(_array, 0, i + 1);
     }
     i++;
   }
 
-  if(pts >0){
-    print_dots_8bit(cfg,_array,characters,0);
+  if (pts > 0) {
+    print_dots_8bit(cfg, _array, characters, 0);
     pts = 0;
   }
 
-  feed_pitch1(cfg->feed_pitch,cfg->orient);
+  feed_pitch1(cfg->feed_pitch, cfg->orient);
 
   return;
 }
 
-void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_num) 
-{
-  uint8_t i=0,y=0, MAX=MAXPIXELS;
+void print_dots_8bit(CONFIG *cfg, uint8_t *Array, uint8_t characters,
+                     uint8_t feed_num) {
+  uint8_t i = 0, y = 0, MAX = MAXPIXELS;
   uint8_t blank;
-  
-      ENABLE_VH;
 
-      if(cfg->align == 0) {
-        while((i<characters) && (i < MAX))
-        {
-          printer_send_data8(Array[i]);
-          i++;
-        }  
-        while( i < MAX)
-        {
-          printer_send_data8(0x00);
-          i++;
-        }
-      }else if(cfg->align==1){// center
-         blank = 0;
-         blank = (MAX-characters)/2;
-         
-         for(i=0;i<blank;i++){
-          printer_send_data8(0x00);
-         }
-         for(i=0;i<characters;i++){
-          printer_send_data8(Array[i]);
-         }
-         for(i=0;i<(MAX-characters-blank);i++){
-          printer_send_data8(0x00);
-         }
-      }else if(cfg->align==2){
-        blank = MAX-characters;
-        for(i=0;i<blank;i++){
-          printer_send_data8(0x00);
-        }
-        for(i=0;i<characters;i++){
-          printer_send_data8(Array[i]);
-        }      
-      }
-      
-      LATCH_ENABLE;
-      delayus(1);
-      LATCH_DISABLE;
-      delayMicroseconds(1);
-      
-      i =0;
-      
-      while(y<STB_NUMBER)
-      {
-        
-          while(i <10)
-          {
-
-                 
-            digitalWrite(STBx[y],HIGH); 
-            delayus(HEAT_TIME+cfg->density*46);
-            digitalWrite(STBx[y],LOW);
-            delayus(14);
-            i++;
-          }
-         
-          y++;
-      }
+  ENABLE_VH;
 
+  if (cfg->align == 0) {
+    while ((i < characters) && (i < MAX)) {
+      printer_send_data8(Array[i]);
+      i++;
+    }
+    while (i < MAX) {
+      printer_send_data8(0x00);
+      i++;
+    }
+  } else if (cfg->align == 1) { // center
+    blank = 0;
+    blank = (MAX - characters) / 2;
 
-    feed_pitch1(feed_num,cfg->orient);
+    for (i = 0; i < blank; i++) {
+      printer_send_data8(0x00);
+    }
+    for (i = 0; i < characters; i++) {
+      printer_send_data8(Array[i]);
+    }
+    for (i = 0; i < (MAX - characters - blank); i++) {
+      printer_send_data8(0x00);
+    }
+  } else if (cfg->align == 2) {
+    blank = MAX - characters;
+    for (i = 0; i < blank; i++) {
+      printer_send_data8(0x00);
+    }
+    for (i = 0; i < characters; i++) {
+      printer_send_data8(Array[i]);
+    }
+  }
 
-      
-    DISABLE_VH;
+  LATCH_ENABLE;
+  delayus(1);
+  LATCH_DISABLE;
+  delayMicroseconds(1);
 
-    return;
+  i = 0;
+
+  while (y < STB_NUMBER) {
+
+    while (i < 10) {
+
+      digitalWrite(STBx[y], HIGH);
+      delayus(HEAT_TIME + cfg->density * 46);
+      digitalWrite(STBx[y], LOW);
+      delayus(14);
+      i++;
+    }
+
+    y++;
+  }
+
+  feed_pitch1(feed_num, cfg->orient);
+
+  DISABLE_VH;
+
+  return;
 }
 
-uint16_t read_adc(char*adc_file) {
+uint16_t read_adc(char *adc_file) {
   long ret;
   char c[16];
   FILE *fptr;
@@ -363,217 +340,239 @@ uint16_t read_adc(char*adc_file) {
     return 0;
   }
   fscanf(fptr, "%[^\n]", c);
-  //printf("Data from the file:\n%s", c);
+  // printf("Data from the file:\n%s", c);
   fclose(fptr);
 
   ret = strtol(c, NULL, 10);
-  //printf("the number ret %d\n",ret);
+  // printf("the number ret %d\n",ret);
 
   return (uint16_t)ret;
 }
 
-
 uint16_t temperature() {
-  
-  
+
   double Rthermistor = 0, TempThermistor = 0;
-  uint16_t ADCSamples=0;
+  uint16_t ADCSamples = 0;
   int Sample = 1;
   uint16_t ADCConvertedValue;
 
- 
-  while(Sample<=NumSamples)
-  {
-      //ADCSamples += analogRead(THERMISTORPIN); //stm32
-      ADCSamples += read_adc(adc_file_path);
-      Sample++;
+  while (Sample <= NumSamples) {
+    // ADCSamples += analogRead(THERMISTORPIN); //stm32
+    ADCSamples += read_adc(adc_file_path);
+    Sample++;
   }
-  //Thermistor Resistance at x Kelvin
-  ADCConvertedValue = (double)ADCSamples/NumSamples;
-  Rthermistor = ( (double)ADCResolution/ ADCConvertedValue) - 1;
-  Rthermistor =  (double)SeriesResistor/Rthermistor;
-  //Thermistor temperature in Kelvin
-  TempThermistor =  Rthermistor / RthNominal ;
-  TempThermistor =  log(TempThermistor);
+  // Thermistor Resistance at x Kelvin
+  ADCConvertedValue = (double)ADCSamples / NumSamples;
+  Rthermistor = ((double)ADCResolution / ADCConvertedValue) - 1;
+  Rthermistor = (double)SeriesResistor / Rthermistor;
+  // Thermistor temperature in Kelvin
+  TempThermistor = Rthermistor / RthNominal;
+  TempThermistor = log(TempThermistor);
   TempThermistor /= BCoefficent;
-  TempThermistor +=  (1/(TempNominal + 273.15));
-  TempThermistor = 1/TempThermistor;
+  TempThermistor += (1 / (TempNominal + 273.15));
+  TempThermistor = 1 / TempThermistor;
+
+  return (uint16_t)(TempThermistor - 273.15);
 
-  return  (uint16_t)(TempThermistor - 273.15);
-  
-  
-  //return  (uint16_t)(0);
+  // return  (uint16_t)(0);
 }
 
-int glob_file(char*av) {
+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)
+  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)
+  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]);
+  if (globlist.gl_pathc > 0) {
+    strcpy(adc_file_path, globlist.gl_pathv[0]);
   }
   return 0;
-
 }
 
 #endif
-uint16_t get_serial_cache_font_width(CONFIG*cfg) {
-	
+uint16_t get_serial_cache_font_width(CONFIG *cfg) {
+
   int i;
   uint8_t *ch;
   uint32_t codename;
   int w;
   w = 0;
   i = 0;
-  while( i <ser_cache.idx) {
-      ch = (uint8_t*)&ser_cache.data[i];
-      codename = utf8_to_utf32(ch);
-      FT_UInt gi = FT_Get_Char_Index ( cfg->face, codename);
-      FT_Load_Glyph ( cfg->face, gi, FT_LOAD_NO_BITMAP);
-      w +=  cfg->face->glyph->metrics.horiAdvance / 64;
-      i++;
+  while (i < ser_cache.idx) {
+    ch = (uint8_t *)&ser_cache.data[i];
+    codename = utf8_to_utf32(ch);
+    FT_UInt gi = FT_Get_Char_Index(cfg->face, codename);
+    FT_Load_Glyph(cfg->face, gi, FT_LOAD_NO_BITMAP);
+    w += cfg->face->glyph->metrics.horiAdvance / 64;
+    i++;
   }
-  return w+cfg->font->width;
+  return w + cfg->font->width;
 }
 
-//print with freetype font dots glyph
-uint8_t print_lines_ft(CONFIG*cfg) {
-  uint8_t i,j,k;
+// print with freetype font dots glyph
+uint8_t print_lines_ft(CONFIG *cfg) {
+  uint8_t i, j, k;
   int8_t w;
   uint8_t dot_line_data[MAXPIXELS];
-  uint8_t dot_line_idx=0;
-  uint8_t dot_line_bitsidx=0;
-  
-  uint8_t lastidx,lastw,lastj;
-  uint8_t row,row_cnt;
+  uint8_t dot_line_idx = 0;
+  uint8_t dot_line_bitsidx = 0;
+
+  uint8_t lastidx, lastw, lastj;
+  uint8_t row, row_cnt;
   uint16_t line_bits;
-    
-  int8_t  left = ser_cache.idx;
+
+  int8_t left = ser_cache.idx;
   uint8_t rv;
-  
-  line_bits=cfg->margin.width;
-  dot_line_idx = line_bits/8;
-  dot_line_bitsidx = line_bits%8;
-  
+
+  line_bits = cfg->margin.width;
+  dot_line_idx = line_bits / 8;
+  dot_line_bitsidx = line_bits % 8;
+
   lastidx = 0;
   lastw = 0;
   lastj = 0;
 
   uint32_t codename;
   uint8_t *ch;
-  printf("left = %d\n",left); 
-  int line_height = (cfg->face->size->metrics.ascender - cfg->face->size->metrics.descender) >> 6;
-  int baseline_height = abs(cfg->face->descender) * current_font.height / cfg->face->units_per_EM;
-  int dpx = 64; 
-  while( left>0 ) {
+  printf("left = %d\n", left);
+  int line_height = (cfg->face->size->metrics.ascender -
+                     cfg->face->size->metrics.descender) >>
+                    6;
+  int baseline_height =
+      abs(cfg->face->descender) * current_font.height / cfg->face->units_per_EM;
+  int dpx = 64;
+  FT_Matrix matrix;
+
+  while (left > 0) {
     i = lastidx;
     row_cnt = 0;
     row = 0;
-    while(row< line_height ){
-      line_bits=cfg->margin.width;
-      dot_line_idx = line_bits/8;
-      dot_line_bitsidx = line_bits%8;
-      memset(dot_line_data,0,MAXPIXELS);
-      //line by line bitmap dots to print
+    while (row < line_height) {
+      line_bits = cfg->margin.width;
+      dot_line_idx = line_bits / 8;
+      dot_line_bitsidx = line_bits % 8;
+      memset(dot_line_data, 0, MAXPIXELS);
+      // line by line bitmap dots to print
       i = lastidx;
-      
-      while( i <ser_cache.idx) {
-        ch = (uint8_t*)&ser_cache.data[i];
+
+      while (i < ser_cache.idx) {
+        ch = (uint8_t *)&ser_cache.data[i];
         codename = utf8_to_utf32(ch);
-        FT_UInt gi = FT_Get_Char_Index ( cfg->face, codename);
-        FT_Load_Glyph (cfg->face, gi, FT_LOAD_DEFAULT);
-        int y_off =  line_height - baseline_height - cfg->face->glyph->metrics.horiBearingY / dpx;
-        int glyph_width  = cfg->face->glyph->metrics.width / dpx;
+
+        matrix.xx = (FT_Fixed)(cos(((double)cfg->degree / 360) * 3.14159 * 2) *
+                               0x10000L);
+        matrix.xy = (FT_Fixed)(-sin(((double)cfg->degree / 360) * 3.14159 * 2) *
+                               0x10000L);
+        matrix.yx = (FT_Fixed)(sin(((double)cfg->degree / 360) * 3.14159 * 2) *
+                               0x10000L);
+        matrix.yy = (FT_Fixed)(cos(((double)cfg->degree / 360) * 3.14159 * 2) *
+                               0x10000L);
+        FT_Set_Transform(cfg->face, &matrix, NULL);
+
+        FT_UInt gi = FT_Get_Char_Index(cfg->face, codename);
+        FT_Load_Glyph(cfg->face, gi, FT_LOAD_DEFAULT);
+        int y_off = line_height - baseline_height -
+                    cfg->face->glyph->metrics.horiBearingY / dpx;
+        int glyph_width = cfg->face->glyph->metrics.width / dpx;
         int glyph_height = cfg->face->glyph->metrics.height / dpx;
         int advance = cfg->face->glyph->metrics.horiAdvance / dpx;
 
-  	int x_off = (advance - glyph_width) / 2;
-
-	int bitmap_rows = cfg->face->glyph->bitmap.rows;
-	int bitmap_width = cfg->face->glyph->bitmap.width;	
-        //FT_Render_Glyph(cfg->face->glyph, FT_RENDER_MODE_NORMAL);
-        FT_Render_Glyph(cfg->face->glyph, FT_RENDER_MODE_MONO); //disable AA
-        
-        j = 0; w= 0;
-        if(lastj !=0){j= lastj;}
-        if(lastw !=0) { w = lastw;}
-        while(w < advance ) {
-          //if(w > 0 && (w%8) == 0) j++;
-          if(dot_line_bitsidx > 7 ){
+        int x_off = (advance - glyph_width) / 2;
+
+        int bitmap_rows = cfg->face->glyph->bitmap.rows;
+        int bitmap_width = cfg->face->glyph->bitmap.width;
+        // FT_Render_Glyph(cfg->face->glyph, FT_RENDER_MODE_NORMAL);
+        FT_Render_Glyph(cfg->face->glyph, FT_RENDER_MODE_MONO); // disable AA
+
+        j = 0;
+        w = 0;
+        if (lastj != 0) {
+          j = lastj;
+        }
+        if (lastw != 0) {
+          w = lastw;
+        }
+        while (w < advance) {
+          // if(w > 0 && (w%8) == 0) j++;
+          if (dot_line_bitsidx > 7) {
             dot_line_idx++;
-            dot_line_bitsidx=0;
+            dot_line_bitsidx = 0;
           }
-          
-          //unsigned char p = cfg->face->glyph->bitmap.buffer[row * cfg->face->glyph->bitmap.pitch + w];
+
+          // unsigned char p = cfg->face->glyph->bitmap.buffer[row *
+          // cfg->face->glyph->bitmap.pitch + w];
           unsigned char p = 0;
-	  int pitch = abs(cfg->face->glyph->bitmap.pitch);
-          
-	  if( w>= x_off && row >= y_off ) {
-	        row_cnt = row-y_off;
-		if(row_cnt < bitmap_rows) {
-	  		//p = (cfg->face->glyph->bitmap.buffer[row_cnt*cfg->face->glyph->bitmap.pitch+j] >> (7-w%8)) & 1;//disable AA
-			j = (w-x_off)/8;
-			p = cfg->face->glyph->bitmap.buffer[row_cnt*pitch+j];
-			p = p & (128 >> ((w-x_off)&7));
-		}
-	  }
-
-          if(p) {
-              printf("#");
-              dot_line_data[dot_line_idx ] |= 1<<(7-dot_line_bitsidx);
-           }else {
-	      printf("0");
-	  }
+          int pitch = abs(cfg->face->glyph->bitmap.pitch);
+
+          if (w >= x_off && row >= y_off) {
+            row_cnt = row - y_off;
+            if (row_cnt < bitmap_rows) {
+              // p =
+              // (cfg->face->glyph->bitmap.buffer[row_cnt*cfg->face->glyph->bitmap.pitch+j]
+              // >> (7-w%8)) & 1;//disable AA
+              j = (w - x_off) / 8;
+              p = cfg->face->glyph->bitmap.buffer[row_cnt * pitch + j];
+              p = p & (128 >> ((w - x_off) & 7));
+            }
+          }
+
+          if (p) {
+            printf("#");
+            dot_line_data[dot_line_idx] |= 1 << (7 - dot_line_bitsidx);
+          } else {
+            printf("0");
+          }
 
           dot_line_bitsidx++;
           w++;
           line_bits++;
-          if(line_bits >= MAX_DOTS) break;
+          if (line_bits >= MAX_DOTS)
+            break;
         }
-        //word gap
+        // word gap
         k = 0;
-        while(k < cfg->wordgap) {
-          if(dot_line_bitsidx>7){
+        while (k < cfg->wordgap) {
+          if (dot_line_bitsidx > 7) {
             dot_line_idx++;
-            dot_line_bitsidx=0;
+            dot_line_bitsidx = 0;
           }
           k++;
           dot_line_bitsidx++;
           line_bits++;
-          if(line_bits >= MAX_DOTS)break;
+          if (line_bits >= MAX_DOTS)
+            break;
         }
-        
-        if(line_bits < MAX_DOTS){
+
+        if (line_bits < MAX_DOTS) {
           i++;
         }
-        
-        if(line_bits >= MAX_DOTS || i >=ser_cache.idx){
-          
-          if(row == (line_height-1)) {// last of the row loop         
-            if(w >= advance ){
-              lastidx = i+1;
-              lastw =0;
-              lastj =0;
-            }else {              
+
+        if (line_bits >= MAX_DOTS || i >= ser_cache.idx) {
+
+          if (row == (line_height - 1)) { // last of the row loop
+            if (w >= advance) {
+              lastidx = i + 1;
+              lastw = 0;
+              lastj = 0;
+            } else {
               lastidx = i;
               lastw = w;
               lastj = j;
             }
           }
-          
+
           break;
         }
       }
       rv = IsPaper();
-      if( rv == IS_PAPER) {
-        //DEBUG("dot_line_idx",dot_line_idx);
-        //DEBUG("dot_line_bits",dot_line_bitsidx);
-        print_dots_8bit_split(cfg,dot_line_data,dot_line_idx+1);
+      if (rv == IS_PAPER) {
+        // DEBUG("dot_line_idx",dot_line_idx);
+        // DEBUG("dot_line_bits",dot_line_bitsidx);
+        print_dots_8bit_split(cfg, dot_line_data, dot_line_idx + 1);
       }
       row++;
       printf("\n");
@@ -586,223 +585,221 @@ uint8_t print_lines_ft(CONFIG*cfg) {
     }
     */
   }
-  
 }
 
+uint8_t print_lines8(CONFIG *cfg) {
 
-uint8_t print_lines8(CONFIG*cfg) {
-
-  if(cfg->font->mode == FONT_MODE_1) {
-      return print_lines_ft(cfg);
+  if (cfg->font->mode == FONT_MODE_1) {
+    return print_lines_ft(cfg);
   }
-  uint8_t i,j,k;
+  uint8_t i, j, k;
   int8_t w;
   uint8_t *data;
-  uint8_t row,pad;
+  uint8_t row, pad;
   uint16_t addr;
-  
+
   uint16_t line_bits;
-  
+
   uint8_t dot_line_data[MAXPIXELS];
-  uint8_t dot_line_idx=0;
-  uint8_t dot_line_bitsidx=0;
+  uint8_t dot_line_idx = 0;
+  uint8_t dot_line_bitsidx = 0;
 
-  uint8_t lastidx,lastw,lastj;
+  uint8_t lastidx, lastw, lastj;
   int8_t left;
   uint8_t rv;
-	
 
-  pad = current_font.width %BITS8;
-  
-  if(pad > 0){
+  pad = current_font.width % BITS8;
+
+  if (pad > 0) {
     pad = 1;
   }
 
   i = 0;
-  i = current_font.width/BITS8;
-  
-  pad = i+pad;
-  
+  i = current_font.width / BITS8;
+
+  pad = i + pad;
+
   row = 0;
   rv = IsPaper();
-  
-  data = (uint8_t*)malloc(sizeof(uint8_t)*(pad+1));
-  i=0;
-
-  
-  line_bits=cfg->margin.width;
-   
-  dot_line_idx = line_bits/8;
-  dot_line_bitsidx = line_bits%8;
+
+  data = (uint8_t *)malloc(sizeof(uint8_t) * (pad + 1));
+  i = 0;
+
+  line_bits = cfg->margin.width;
+
+  dot_line_idx = line_bits / 8;
+  dot_line_bitsidx = line_bits % 8;
   left = ser_cache.idx;
-  lastidx=0;
-  lastw=0;
-  lastj=0;
+  lastidx = 0;
+  lastw = 0;
+  lastj = 0;
 
-  //DEBUG("left",left);  
-  while(left>0){
+  // DEBUG("left",left);
+  while (left > 0) {
     i = lastidx;
-    while(row<current_font.height){
-    
-      line_bits=cfg->margin.width;
-      dot_line_idx = line_bits/8;
-      dot_line_bitsidx = line_bits%8;
-      memset(dot_line_data,0,MAXPIXELS);
+    while (row < current_font.height) {
+
+      line_bits = cfg->margin.width;
+      dot_line_idx = line_bits / 8;
+      dot_line_bitsidx = line_bits % 8;
+      memset(dot_line_data, 0, MAXPIXELS);
       i = lastidx;
-      //DEBUG("i",i)
-      //DEBUG("ser_cache.idx",ser_cache.idx)
-      while( i <ser_cache.idx){
-        addr = pad*(uint8_t)ser_cache.data[i]*current_font.height;
-        for(j=0;j<pad;j++){
-          data[j] = current_font.data[addr+row*pad+j];
+      // DEBUG("i",i)
+      // DEBUG("ser_cache.idx",ser_cache.idx)
+      while (i < ser_cache.idx) {
+        addr = pad * (uint8_t)ser_cache.data[i] * current_font.height;
+        for (j = 0; j < pad; j++) {
+          data[j] = current_font.data[addr + row * pad + j];
         }
-        j=0; w=0;
-        if(lastj !=0){j= lastj;}
-        if(lastw !=0) { w = lastw;}
-        
-          while(w < current_font.width){
-            if(w > 0 && ( w%8) == 0)j++;
-            if(dot_line_bitsidx > 7){
-              dot_line_idx++;
-              dot_line_bitsidx=0;
-            }
-          
-            k = (data[j] >> (7-(w%8))) &1;
-            //Serial.print(data[j],HEX);
-            if( k > 0){
-              dot_line_data[dot_line_idx] |= 1 << (7-dot_line_bitsidx);
-              //Serial.print("1");
-            }
-          
-            dot_line_bitsidx++;
-            w++;
-            line_bits++;
-            if(line_bits >= MAX_DOTS)break;
+        j = 0;
+        w = 0;
+        if (lastj != 0) {
+          j = lastj;
+        }
+        if (lastw != 0) {
+          w = lastw;
+        }
+
+        while (w < current_font.width) {
+          if (w > 0 && (w % 8) == 0)
+            j++;
+          if (dot_line_bitsidx > 7) {
+            dot_line_idx++;
+            dot_line_bitsidx = 0;
           }
 
-          ///word gap
-          k=0;
-          while( k < cfg->wordgap ){
-            if(dot_line_bitsidx > 7){
-              dot_line_idx++;
-              dot_line_bitsidx=0;
-            }
+          k = (data[j] >> (7 - (w % 8))) & 1;
+          // Serial.print(data[j],HEX);
+          if (k > 0) {
+            dot_line_data[dot_line_idx] |= 1 << (7 - dot_line_bitsidx);
+            // Serial.print("1");
+          }
+
+          dot_line_bitsidx++;
+          w++;
+          line_bits++;
+          if (line_bits >= MAX_DOTS)
+            break;
+        }
 
-            k++;
-            dot_line_bitsidx++;
-            line_bits++;
-            if(line_bits >= MAX_DOTS)break;
+        /// word gap
+        k = 0;
+        while (k < cfg->wordgap) {
+          if (dot_line_bitsidx > 7) {
+            dot_line_idx++;
+            dot_line_bitsidx = 0;
           }
-         
-        if(line_bits < MAX_DOTS){
+
+          k++;
+          dot_line_bitsidx++;
+          line_bits++;
+          if (line_bits >= MAX_DOTS)
+            break;
+        }
+
+        if (line_bits < MAX_DOTS) {
           i++;
         }
-        
-        if(line_bits >= MAX_DOTS || i >=ser_cache.idx){
-          
-          if(row == (current_font.height-1)) {// last of the row loop         
-            if(w >= current_font.width){
-              lastidx = i+1;
-              lastw =0;
-              lastj =0;
-            }else {              
+
+        if (line_bits >= MAX_DOTS || i >= ser_cache.idx) {
+
+          if (row == (current_font.height - 1)) { // last of the row loop
+            if (w >= current_font.width) {
+              lastidx = i + 1;
+              lastw = 0;
+              lastj = 0;
+            } else {
               lastidx = i;
               lastw = w;
               lastj = j;
             }
           }
-          
+
           break;
         }
       }
       rv = IsPaper();
-      if( rv == IS_PAPER){
-        //DEBUG("dot_line_idx",dot_line_idx);
-        //DEBUG("dot_line_bits",dot_line_bitsidx);
-        print_dots_8bit_split(cfg,dot_line_data,dot_line_idx+1);
-      }        
+      if (rv == IS_PAPER) {
+        // DEBUG("dot_line_idx",dot_line_idx);
+        // DEBUG("dot_line_bits",dot_line_bitsidx);
+        print_dots_8bit_split(cfg, dot_line_data, dot_line_idx + 1);
+      }
       row++;
     }
     left = left - lastidx;
     row = 0;
-    
-    if(cfg->line_space > cfg->font->height){
-      feed_pitch1(cfg->line_space - cfg->font->height,cfg->orient);
+
+    if (cfg->line_space > cfg->font->height) {
+      feed_pitch1(cfg->line_space - cfg->font->height, cfg->orient);
     }
-    
   }
-  
-  //Serial.println("print ever");
+
+  // Serial.println("print ever");
 
   free(data);
 
   return rv;
 }
 
-
-uint8_t print_image8(CONFIG*cfg){
+uint8_t print_image8(CONFIG *cfg) {
 
   uint16_t height;
-  uint16_t x,y,addr;
-  
+  uint16_t x, y, addr;
+
   uint8_t rv;
   uint8_t LinePixels[MAXPIXELS];
 
-  uint8_t maxchars= PRINTER_BITS/8;
-  height  = cfg->img->num / cfg->img->width;
-  y=0;
+  uint8_t maxchars = PRINTER_BITS / 8;
+  height = cfg->img->num / cfg->img->width;
+  y = 0;
   addr = 0;
-  
+
   rv = IsPaper();
 
-  while(y < height )
-  {
-    x=0;
-    while( x < cfg->img->width )
-    {
-      addr  = x+y*cfg->img->width;
+  while (y < height) {
+    x = 0;
+    while (x < cfg->img->width) {
+      addr = x + y * cfg->img->width;
 
-     
-      if(cfg->img->revert_bits > 0)//LSB
+      if (cfg->img->revert_bits > 0) // LSB
         LinePixels[x] = invert_bit(cfg->img->cache[addr]);
       else
         LinePixels[x] = cfg->img->cache[addr];
-      
+
       x++;
     }
     rv = IsPaper();
-    if( rv == IS_PAPER) {
-    	print_dots_8bit_split(cfg,LinePixels,x);
+    if (rv == IS_PAPER) {
+      print_dots_8bit_split(cfg, LinePixels, x);
     }
-    
-    //feed_pitch1(FEED_PITCH,cfg->orient);
+
+    // feed_pitch1(FEED_PITCH,cfg->orient);
     y++;
   }
-  //feed_pitch1(cfg->feed_pitch,cfg->orient);
-  cfg->img->need_print= 0;
-  
+  // feed_pitch1(cfg->feed_pitch,cfg->orient);
+  cfg->img->need_print = 0;
+
   cfg->img->num = 0;
   cfg->img->idx = 0;
   cfg->img->width = 0;
-  
+
   return rv;
 }
 
-void print_cut_line(CONFIG*cfg){
-  uint8_t bs,i;
+void print_cut_line(CONFIG *cfg) {
+  uint8_t bs, i;
+
+  bs = PRINTER_BITS / cfg->font->width;
+  bs -= 1;
 
-  bs= PRINTER_BITS/ cfg->font->width;
-  bs-=1;
- 
   reset_cmd();
-  
-  for(i=0;i<bs;i++){
-    if(i%2==0){
-      parse_serial_stream(cfg,'=');
-    }else{
-      parse_serial_stream(cfg,'-');
+
+  for (i = 0; i < bs; i++) {
+    if (i % 2 == 0) {
+      parse_serial_stream(cfg, '=');
+    } else {
+      parse_serial_stream(cfg, '-');
     }
   }
-  parse_serial_stream(cfg,ASCII_FF);
-  
+  parse_serial_stream(cfg, ASCII_FF);
 }

+ 16 - 15
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 2
+//#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);
 
@@ -21,26 +21,27 @@ void motor_stepper_pos2(uint8_t Position);
 uint8_t feed_pitch1(uint64_t lines, uint8_t forward_backward);
 
 uint8_t bits_number(uint8_t n);
- 
-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);
+void print_dots_8bit_split(CONFIG *cfg, uint8_t *Array, uint8_t characters);
 
-uint16_t read_adc(char*);
+void print_dots_8bit(CONFIG *cfg, uint8_t *Array, uint8_t characters,
+                     uint8_t feed_num);
+
+uint16_t read_adc(char *);
 uint16_t temperature();
-int glob_file(char*);
-uint16_t get_serial_cache_font_width(CONFIG*);
-uint8_t print_lines_ft(CONFIG*);
-uint8_t print_lines8(CONFIG*);
+int glob_file(char *);
+uint16_t get_serial_cache_font_width(CONFIG *);
+uint8_t print_lines_ft(CONFIG *);
+uint8_t print_lines8(CONFIG *);
 
 uint8_t invert_bit(uint8_t a);
 
-uint8_t print_image8(CONFIG*);
-void print_cut_line(CONFIG*);
+uint8_t print_image8(CONFIG *);
+void print_cut_line(CONFIG *);
 
-void printer_set_font_mode(CONFIG*cfg,int);
-void printer_set_font(CONFIG*cfg,uint8_t fnbits);
-void parse_serial_stream(CONFIG*cfg,uint8_t input_ch);
+void printer_set_font_mode(CONFIG *cfg, int);
+void printer_set_font(CONFIG *cfg, uint8_t fnbits);
+void parse_serial_stream(CONFIG *cfg, uint8_t input_ch);
 
 void reset_cmd();
 

+ 13 - 17
Code/thermal_printer/utils.c

@@ -1,24 +1,20 @@
 #include "utils.h"
 
-void delayus(unsigned int _us){
-  delayMicroseconds(_us);
-}
+void delayus(unsigned int _us) { delayMicroseconds(_us); }
 
-uint8_t invert_bit(uint8_t a){
+uint8_t invert_bit(uint8_t a) {
 
-  return ((a&0x01)<<7)|((a&0x02)<<5)|((a&0x04)<<3)|((a&0x08)<<1)|((a&0x10)>>1)|((a&0x20)>>3)|((a&0x40)>>5)|((a&0x80)>>7);
-  
+  return ((a & 0x01) << 7) | ((a & 0x02) << 5) | ((a & 0x04) << 3) |
+         ((a & 0x08) << 1) | ((a & 0x10) >> 1) | ((a & 0x20) >> 3) |
+         ((a & 0x40) >> 5) | ((a & 0x80) >> 7);
 }
 
-uint8_t bits_number(uint8_t n)//count bits "1"
-{ 
-    uint8_t count = 0; 
-    while (n) { 
-        count += n & 1; 
-        n >>= 1; 
-    } 
-    return count; 
+uint8_t bits_number(uint8_t n) // count bits "1"
+{
+  uint8_t count = 0;
+  while (n) {
+    count += n & 1;
+    n >>= 1;
+  }
+  return count;
 }
-
-
-

+ 10 - 4
Code/thermal_printer/utils.h

@@ -1,19 +1,26 @@
 #ifndef UTILS_H
 #define UTILS_H
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h> 
 #include <string.h>
 
 #include <wiringPi.h>
 
 #define SEP printf(" ");
 // a is string, b is number
-#define DEBUG(a,b) printf(a);SEP;printf("%d\n",b);
+#define DEBUG(a, b)                                                            \
+  printf(a);                                                                   \
+  SEP;                                                                         \
+  printf("%d\n", b);
 
 #define ALINE printf("\n");
 
-#define PRINTF(...) { printf(__VA_ARGS__);fflush(stdout);}
+#define PRINTF(...)                                                            \
+  {                                                                            \
+    printf(__VA_ARGS__);                                                       \
+    fflush(stdout);                                                            \
+  }
 
 void delayus(unsigned int _us);
 
@@ -21,5 +28,4 @@ uint8_t invert_bit(uint8_t a);
 
 uint8_t bits_number(uint8_t n);
 
-
 #endif

Some files were not shown because too many files changed in this diff