indent code with clang-format, add rotation

This commit is contained in:
cuu 2022-03-10 04:02:24 -06:00
parent 3237703ec3
commit 31670a4428
8 changed files with 1250 additions and 1271 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,8 @@
#include "config.h" #include "config.h"
//#define PRINT_SPLIT 6 // max points printed at the same time, 384/PRINT_SPLIT==96 //#define PRINT_SPLIT 6 // max points printed at the same time,
//#define MAX_PRINT_PTS 2 //384/PRINT_SPLIT==96 #define MAX_PRINT_PTS 2
void printer_send_data8(uint8_t); 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 feed_pitch1(uint64_t lines, uint8_t forward_backward);
uint8_t bits_number(uint8_t n); 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(); uint16_t temperature();
int glob_file(char*); int glob_file(char *);
uint16_t get_serial_cache_font_width(CONFIG*); uint16_t get_serial_cache_font_width(CONFIG *);
uint8_t print_lines_ft(CONFIG*); uint8_t print_lines_ft(CONFIG *);
uint8_t print_lines8(CONFIG*); uint8_t print_lines8(CONFIG *);
uint8_t invert_bit(uint8_t a); uint8_t invert_bit(uint8_t a);
uint8_t print_image8(CONFIG*); uint8_t print_image8(CONFIG *);
void print_cut_line(CONFIG*); void print_cut_line(CONFIG *);
void printer_set_font_mode(CONFIG*cfg,int); void printer_set_font_mode(CONFIG *cfg, int);
void printer_set_font(CONFIG*cfg,uint8_t fnbits); void printer_set_font(CONFIG *cfg, uint8_t fnbits);
void parse_serial_stream(CONFIG*cfg,uint8_t input_ch); void parse_serial_stream(CONFIG *cfg, uint8_t input_ch);
void reset_cmd(); void reset_cmd();

View File

@ -1,24 +1,20 @@
#include "utils.h" #include "utils.h"
void delayus(unsigned int _us){ void delayus(unsigned int _us) { delayMicroseconds(_us); }
delayMicroseconds(_us);
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);
} }
uint8_t invert_bit(uint8_t a){ uint8_t bits_number(uint8_t n) // count bits "1"
{
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 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;
}

View File

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