mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-12 18:28:50 +01:00
indent code with clang-format, add rotation
This commit is contained in:
parent
3237703ec3
commit
31670a4428
@ -1,8 +1,8 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <freetype2/ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype2/ft2build.h>
|
||||
|
||||
/// raspberry pi CM3
|
||||
|
||||
@ -26,7 +26,8 @@
|
||||
#define BCM_GPIO_45 45
|
||||
|
||||
// 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
|
||||
|
||||
@ -53,7 +54,6 @@
|
||||
#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
|
||||
@ -67,7 +67,6 @@
|
||||
#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
|
||||
@ -79,14 +78,11 @@
|
||||
#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 MOTOR_ENABLE1
|
||||
#define MOTOR_ENABLE2
|
||||
|
||||
@ -101,7 +97,6 @@
|
||||
|
||||
#define ASK4PAPER digitalRead(PEM_PIN)
|
||||
|
||||
|
||||
#define ERROR_FEED_PITCH ((uint8_t)0x01)
|
||||
#define IS_PAPER 0x00
|
||||
#define NO_PAPER 0x01
|
||||
@ -139,8 +134,6 @@
|
||||
|
||||
#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
|
||||
@ -164,7 +157,6 @@
|
||||
|
||||
#define BITS8 8
|
||||
|
||||
|
||||
#define MAX_DOTS 384
|
||||
#define PRINTER_BITS MAX_DOTS
|
||||
#define MAXPIXELS 48
|
||||
@ -182,13 +174,11 @@
|
||||
#define LAST(k, n) ((k) & ((1 << (n)) - 1))
|
||||
#define MID(k, m, n) LAST((k) >> (m), ((n) - (m)))
|
||||
|
||||
|
||||
typedef struct _Margin {
|
||||
uint16_t width;
|
||||
uint8_t esgs;
|
||||
} Margin;
|
||||
|
||||
|
||||
typedef struct _FONT {
|
||||
|
||||
uint8_t width; // in bits
|
||||
@ -210,8 +200,7 @@ typedef struct _ImageCache{
|
||||
|
||||
} ImageCache;
|
||||
|
||||
typedef struct _CONFIG
|
||||
{
|
||||
typedef struct _CONFIG {
|
||||
uint8_t state;
|
||||
uint8_t line_space;
|
||||
uint8_t align;
|
||||
@ -224,6 +213,7 @@ typedef struct _CONFIG
|
||||
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;
|
||||
@ -237,7 +227,6 @@ typedef struct _CONFIG
|
||||
|
||||
} CONFIG;
|
||||
|
||||
|
||||
typedef struct _SerialCache {
|
||||
uint8_t idx;
|
||||
uint8_t utf8idx; // 0-4
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
// for ltp02-245
|
||||
// 203 dpi, 384dots in 48mm(1.88976inch) every dots == 0.125mm, 1byte==8dots==1mm
|
||||
// make clean && make && ./*.elf
|
||||
// 203 dpi, 384dots in 48mm(1.88976inch) every dots == 0.125mm,
|
||||
// 1byte==8dots==1mm make clean && make && ./*.elf
|
||||
//#include <SPI.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
@ -23,8 +23,8 @@
|
||||
#include "ttf_Px437_PS2thin2_8x16.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
#include "printer.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "ftype.h"
|
||||
#include <math.h>
|
||||
@ -90,14 +90,18 @@ void init_printer(){
|
||||
img_cache.revert_bits = 0;
|
||||
|
||||
/*
|
||||
current_font.width=5; current_font.height=7; current_font.data = font_pcf_5x7_ISO8859_1_5x7;
|
||||
current_font.width=6;current_font.height=12; current_font.data = font_pcf_6x12_ISO8859_1_6x12;
|
||||
current_font.width=7; current_font.height=14; current_font.data = font_pcf_7x14_ISO8859_1_7x14;
|
||||
current_font.width=5; current_font.height=7; current_font.data =
|
||||
font_pcf_5x7_ISO8859_1_5x7; current_font.width=6;current_font.height=12;
|
||||
current_font.data = font_pcf_6x12_ISO8859_1_6x12; current_font.width=7;
|
||||
current_font.height=14; current_font.data = font_pcf_7x14_ISO8859_1_7x14;
|
||||
|
||||
//current_font.width=8;current_font.height=16; current_font.data= font_ttf_Px437_ISO8_8x16;
|
||||
//current_font.width=8;current_font.height=16; current_font.data= font_ttf_Px437_ISO9_8x16;
|
||||
//current_font.width=8;current_font.height=16; current_font.data=
|
||||
font_ttf_Px437_ISO8_8x16;
|
||||
//current_font.width=8;current_font.height=16; current_font.data=
|
||||
font_ttf_Px437_ISO9_8x16;
|
||||
|
||||
current_font.width=8;current_font.height=16; current_font.data= font_ttf_Px437_PS2thin2_8x16;
|
||||
current_font.width=8;current_font.height=16; current_font.data=
|
||||
font_ttf_Px437_PS2thin2_8x16;
|
||||
*/
|
||||
current_font.width = 16;
|
||||
current_font.height = 16;
|
||||
@ -108,7 +112,8 @@ void init_printer(){
|
||||
ser_cache.idx = 0;
|
||||
ser_cache.utf8idx = 0;
|
||||
|
||||
if( init_ft(current_font.file, &face,&ft,current_font.width,current_font.height,&error)) {
|
||||
if (init_ft(current_font.file, &face, &ft, current_font.width,
|
||||
current_font.height, &error)) {
|
||||
g_config.face = face;
|
||||
g_config.ft = ft;
|
||||
} else {
|
||||
@ -140,7 +145,7 @@ void init_printer(){
|
||||
g_config.feed_pitch = 2;
|
||||
g_config.max_pts = 2;
|
||||
g_config.lock = 0;
|
||||
|
||||
g_config.degree = 0;
|
||||
|
||||
battery_chk_tm.time = millis();
|
||||
battery_chk_tm.last_status = 0;
|
||||
@ -153,7 +158,6 @@ void label_print_f(CONFIG*cfg,char*label,float m,char*last){
|
||||
char buf[48];
|
||||
uint8_t i, j;
|
||||
|
||||
|
||||
if (m == -1.0)
|
||||
sprintf(buf, "%s", last);
|
||||
else
|
||||
@ -167,7 +171,6 @@ void label_print_f(CONFIG*cfg,char*label,float m,char*last){
|
||||
else
|
||||
sprintf(buf, "%s%*s%0.2f%s", label, i, "", m, last);
|
||||
|
||||
|
||||
printer_set_font(cfg, 4);
|
||||
reset_cmd();
|
||||
|
||||
@ -176,8 +179,6 @@ void label_print_f(CONFIG*cfg,char*label,float m,char*last){
|
||||
}
|
||||
parse_serial_stream(cfg, 10);
|
||||
reset_cmd();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void label_print_i(CONFIG *cfg, char *label, int m, char *last) {
|
||||
@ -205,8 +206,6 @@ void label_print_i(CONFIG*cfg,char*label,int m,char*last){
|
||||
}
|
||||
parse_serial_stream(cfg, 10);
|
||||
reset_cmd();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void printer_test(CONFIG *cfg) {
|
||||
@ -216,7 +215,8 @@ void printer_test(CONFIG*cfg){
|
||||
uint16_t k;
|
||||
|
||||
char buf[MAXPIXELS];
|
||||
char *font_names[]={"8x16thin_1","5x7_ISO8859_1","6x12_ISO8859_1","7x14_ISO8859_1","8x16thin_2",NULL};
|
||||
char *font_names[] = {"8x16thin_1", "5x7_ISO8859_1", "6x12_ISO8859_1",
|
||||
"7x14_ISO8859_1", "8x16thin_2", NULL};
|
||||
|
||||
/*
|
||||
char *selftest1[] = {
|
||||
@ -235,9 +235,7 @@ NULL
|
||||
" # # # # # # # # ",
|
||||
"# # # # # # # # # # ",
|
||||
" #### ###### ###### # # ###### #### # ",
|
||||
NULL
|
||||
};
|
||||
|
||||
NULL};
|
||||
|
||||
cfg->density = 6;
|
||||
|
||||
@ -369,12 +367,10 @@ NULL
|
||||
// Serial.println(strlen(url),DEC);
|
||||
for (i = 0; i < strlen(url); i++) {
|
||||
parse_serial_stream(cfg, url[i]);
|
||||
|
||||
}
|
||||
parse_serial_stream(cfg, 10);
|
||||
reset_cmd();
|
||||
|
||||
|
||||
//-----------------------------------
|
||||
// grid
|
||||
/*
|
||||
@ -398,7 +394,6 @@ NULL
|
||||
*/
|
||||
//--------------------------------------------------------
|
||||
feed_pitch1(cfg->font->height * 2, cfg->orient);
|
||||
|
||||
}
|
||||
|
||||
void printer_set_font_mode(CONFIG *cfg, int mode) {
|
||||
@ -444,16 +439,13 @@ void printer_set_font(CONFIG*cfg,uint8_t fnbits){
|
||||
if (cfg->font->mode == 1) {
|
||||
cfg->font->width = 16;
|
||||
cfg->font->height = 16;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void parse_cmd(CONFIG *cfg, uint8_t *cmd, uint8_t cmdidx) {
|
||||
|
||||
uint8_t ret;
|
||||
|
||||
|
||||
if (cmdidx > 1) {
|
||||
// ESC 2
|
||||
if (cmd[0] == ASCII_ESC && cmd[1] == 0x32) {
|
||||
@ -465,13 +457,11 @@ void parse_cmd(CONFIG*cfg,uint8_t *cmd, uint8_t cmdidx){
|
||||
if (cmd[0] == ASCII_ESC && cmd[1] == 0x40) {
|
||||
init_printer();
|
||||
reset_cmd();
|
||||
|
||||
}
|
||||
// DC2 T printer test page
|
||||
if (cmd[0] == ASCII_DC2 && cmd[1] == 0x54) {
|
||||
reset_cmd();
|
||||
printer_test(cfg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,13 +469,17 @@ void parse_cmd(CONFIG*cfg,uint8_t *cmd, uint8_t cmdidx){
|
||||
// ESC j n
|
||||
if (cmd[0] == ASCII_ESC && cmd[1] == 0x4a) {
|
||||
|
||||
if( print_lines8(cfg) == 0) { feed_pitch1(cmd[2],cfg->orient); }
|
||||
if (print_lines8(cfg) == 0) {
|
||||
feed_pitch1(cmd[2], cfg->orient);
|
||||
}
|
||||
reset_cmd();
|
||||
}
|
||||
// ESC d n
|
||||
if (cmd[0] == ASCII_ESC && cmd[1] == 0x64) {
|
||||
|
||||
if( print_lines8(cfg) == 0) { feed_pitch1(cmd[2]*cfg->font->height,cfg->orient); }
|
||||
if (print_lines8(cfg) == 0) {
|
||||
feed_pitch1(cmd[2] * cfg->font->height, cfg->orient);
|
||||
}
|
||||
reset_cmd();
|
||||
}
|
||||
// ESC ! n
|
||||
@ -543,7 +537,6 @@ void parse_cmd(CONFIG*cfg,uint8_t *cmd, uint8_t cmdidx){
|
||||
}
|
||||
|
||||
reset_cmd();
|
||||
|
||||
}
|
||||
|
||||
// ESC SP n
|
||||
@ -563,18 +556,37 @@ void parse_cmd(CONFIG*cfg,uint8_t *cmd, uint8_t cmdidx){
|
||||
reset_cmd();
|
||||
}
|
||||
|
||||
|
||||
// GS V \0 or GS V \1
|
||||
if (cmd[0] == ASCII_GS && cmd[1] == 0x56) {
|
||||
|
||||
ret = cmd[2];
|
||||
reset_cmd();//When using parse_serial_stream function internally, reset_cmd() first
|
||||
reset_cmd(); // When using parse_serial_stream function internally,
|
||||
// reset_cmd() first
|
||||
|
||||
print_cut_line(cfg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ESC V n
|
||||
if (cmd[0] == ASCII_ESC && cmd[1] == 0x56) {
|
||||
ret = cmd[2];
|
||||
if (ret == 0x00 || ret == 0x30) {
|
||||
cfg->degree = 0;
|
||||
}
|
||||
if (ret == 0x01 || ret == 0x31) {
|
||||
cfg->degree = 90;
|
||||
}
|
||||
if (ret == 0x02 || ret == 0x32) {
|
||||
cfg->degree = 180;
|
||||
}
|
||||
|
||||
if (ret == 0x03 || ret == 0x33) {
|
||||
cfg->degree = 270;
|
||||
}
|
||||
printf("set printer degree, %d\n", cfg->degree);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdidx > 3) {
|
||||
@ -588,7 +600,6 @@ void parse_cmd(CONFIG*cfg,uint8_t *cmd, uint8_t cmdidx){
|
||||
|
||||
reset_cmd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (cmdidx > 4) {
|
||||
@ -622,15 +633,12 @@ void parse_cmd(CONFIG*cfg,uint8_t *cmd, uint8_t cmdidx){
|
||||
cfg->img->idx = 0;
|
||||
cfg->img->width = width;
|
||||
cfg->img->need_print = 1;
|
||||
|
||||
}
|
||||
// do not reset_cmd()
|
||||
cmd_idx = 0;
|
||||
ser_cache.idx = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void parse_serial_stream(CONFIG *cfg, uint8_t input_ch) {
|
||||
@ -694,8 +702,10 @@ void parse_serial_stream(CONFIG*cfg,uint8_t input_ch){
|
||||
|
||||
if (bskip == 1) {
|
||||
// append this to int32_t [8:8:8:8] 0xffffffff 4294967295
|
||||
ser_cache.data[ser_cache.idx] |= input_ch << (8 * (ser_cache.utf8idx));
|
||||
if( ser_cache.utf8idx == get_slice_len( ser_cache.data[ser_cache.idx] & 0xff) -1 ) {
|
||||
ser_cache.data[ser_cache.idx] |= input_ch
|
||||
<< (8 * (ser_cache.utf8idx));
|
||||
if (ser_cache.utf8idx ==
|
||||
get_slice_len(ser_cache.data[ser_cache.idx] & 0xff) - 1) {
|
||||
ser_cache.idx++;
|
||||
ser_cache.utf8idx = 0; // next character
|
||||
} else {
|
||||
@ -707,7 +717,6 @@ void parse_serial_stream(CONFIG*cfg,uint8_t input_ch){
|
||||
ser_cache.utf8idx = 1;
|
||||
ser_cache.data[ser_cache.idx] = input_ch;
|
||||
}
|
||||
|
||||
}
|
||||
// read utf8 codename
|
||||
//
|
||||
@ -717,8 +726,8 @@ void parse_serial_stream(CONFIG*cfg,uint8_t input_ch){
|
||||
a += (ser_cache.idx) * 0 + g_config.margin.width;
|
||||
|
||||
} else {
|
||||
a = (ser_cache.idx+1)*current_font.width+(ser_cache.idx)*0+ g_config.margin.width;
|
||||
|
||||
a = (ser_cache.idx + 1) * current_font.width + (ser_cache.idx) * 0 +
|
||||
g_config.margin.width;
|
||||
}
|
||||
if (a >= MAX_DOTS) // got enough points to print
|
||||
{
|
||||
@ -732,11 +741,11 @@ void parse_serial_stream(CONFIG*cfg,uint8_t input_ch){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Virtual serial port created by socat
|
||||
socat -d -d pty,link=/tmp/DEVTERM_PRINTER_OUT,raw,echo=0 pty,link=/tmp/DEVTERM_PRINTER_IN,raw,echo=0
|
||||
socat -d -d pty,link=/tmp/DEVTERM_PRINTER_OUT,raw,echo=0
|
||||
pty,link=/tmp/DEVTERM_PRINTER_IN,raw,echo=0
|
||||
*/
|
||||
|
||||
int read_bat_cap(CONFIG *cfg) {
|
||||
@ -756,7 +765,6 @@ int read_bat_cap(CONFIG*cfg) {
|
||||
ret = strtol(c, NULL, 10);
|
||||
|
||||
return (int)ret;
|
||||
|
||||
}
|
||||
|
||||
int bat_cap_to_pts(CONFIG *cfg, int bat) {
|
||||
@ -766,7 +774,6 @@ int bat_cap_to_pts(CONFIG*cfg,int bat) {
|
||||
return pts;
|
||||
}
|
||||
|
||||
|
||||
void print_lowpower(CONFIG *cfg) {
|
||||
|
||||
int i;
|
||||
@ -778,14 +785,12 @@ void print_lowpower(CONFIG*cfg) {
|
||||
|
||||
for (i = 0; i < strlen(msg); i++) {
|
||||
parse_serial_stream(cfg, msg[i]);
|
||||
|
||||
}
|
||||
parse_serial_stream(cfg, 10);
|
||||
reset_cmd();
|
||||
|
||||
for (i = 0; i < strlen(msg); i++) {
|
||||
parse_serial_stream(cfg, msg[i]);
|
||||
|
||||
}
|
||||
parse_serial_stream(cfg, 10);
|
||||
reset_cmd();
|
||||
@ -794,7 +799,6 @@ void print_lowpower(CONFIG*cfg) {
|
||||
printer_set_font(cfg, 0);
|
||||
|
||||
PRINTF("%s\n", msg);
|
||||
|
||||
}
|
||||
|
||||
int check_battery(CONFIG *cfg) {
|
||||
@ -817,7 +821,6 @@ int check_battery(CONFIG*cfg){
|
||||
|
||||
if (cfg->lock == 0) {
|
||||
print_lowpower(cfg);
|
||||
|
||||
}
|
||||
cfg->lock = 1;
|
||||
PRINTF("printer locked\n");
|
||||
@ -830,7 +833,6 @@ int check_battery(CONFIG*cfg){
|
||||
}
|
||||
|
||||
battery_chk_tm.time = millis();
|
||||
|
||||
}
|
||||
|
||||
if (cfg->lock == 1) {
|
||||
@ -838,7 +840,6 @@ int check_battery(CONFIG*cfg){
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#define FIFO_FILE "/tmp/DEVTERM_PRINTER_OUT"
|
||||
@ -861,8 +862,7 @@ void loop() {
|
||||
fp = fopen(FIFO_FILE, "r+b");
|
||||
if (fp != NULL) {
|
||||
g_config.fp = fp;
|
||||
while(1)
|
||||
{
|
||||
while (1) {
|
||||
fread(readbuf, 1, 1, fp);
|
||||
check_battery(&g_config);
|
||||
|
||||
@ -876,7 +876,7 @@ void loop() {
|
||||
} else { // not a tab
|
||||
parse_serial_stream(&g_config, readbuf[0]);
|
||||
}
|
||||
} else { //g_config.state == PRINT_STATE
|
||||
} else { // g_config.state != PRINT_STATE
|
||||
parse_serial_stream(&g_config, readbuf[0]);
|
||||
}
|
||||
}
|
||||
@ -889,7 +889,6 @@ void loop() {
|
||||
}
|
||||
//------------------------------------------
|
||||
// printer_test(&g_config);
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@ -905,13 +904,10 @@ void setup() {
|
||||
init_printer();
|
||||
|
||||
g_config.printf = &printf_out;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
|
||||
setup();
|
||||
loop();
|
||||
|
||||
}
|
||||
|
||||
@ -4,10 +4,8 @@
|
||||
|
||||
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)
|
||||
{
|
||||
int req_size_w, int req_size_h, char **error) {
|
||||
|
||||
bool ret = false;
|
||||
if (FT_Init_FreeType(ft) == 0) {
|
||||
@ -37,10 +35,7 @@ bool init_ft (const char *ttf_file, FT_Face *face, FT_Library *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); }
|
||||
|
||||
/*===========================================================================
|
||||
|
||||
@ -51,8 +46,7 @@ void done_ft(FT_Library ft)
|
||||
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,15 +55,18 @@ 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)
|
||||
{
|
||||
UTF32 *cjk_utf8_to_utf32(const char *word) {
|
||||
assert(word != NULL);
|
||||
int l = strlen(word);
|
||||
int u8l = utf8_strlen(word);
|
||||
@ -80,8 +77,7 @@ UTF32 *cjk_utf8_to_utf32 (const char *word)
|
||||
int i = 0, j = 0;
|
||||
int bskip = 1;
|
||||
|
||||
while( i<l )
|
||||
{
|
||||
while (i < l) {
|
||||
|
||||
bskip = get_slice_len(word[i]);
|
||||
strncpy(buf, &word[i], bskip);
|
||||
@ -98,5 +94,3 @@ UTF32 *cjk_utf8_to_utf32 (const char *word)
|
||||
ret[u8l] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
@ -27,22 +26,19 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void clear_printer_buffer()
|
||||
{
|
||||
void clear_printer_buffer() {
|
||||
uint8_t i = 0;
|
||||
|
||||
for (i = 0; i < 48; i++)
|
||||
@ -54,9 +50,7 @@ void clear_printer_buffer()
|
||||
delayus(1);
|
||||
}
|
||||
|
||||
|
||||
uint8_t IsPaper()
|
||||
{
|
||||
uint8_t IsPaper() {
|
||||
uint8_t status;
|
||||
uint8_t tmp;
|
||||
return IS_PAPER;
|
||||
@ -64,9 +58,12 @@ uint8_t IsPaper()
|
||||
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"); }
|
||||
{
|
||||
status = IS_PAPER;
|
||||
} else {
|
||||
status = NO_PAPER;
|
||||
PRINTF("Error:NO PAPER\n");
|
||||
}
|
||||
DISABLE_PEM;
|
||||
|
||||
if (printer_temp_check > 20) {
|
||||
@ -87,14 +84,12 @@ uint8_t IsPaper()
|
||||
status = printer_vps_last_status;
|
||||
}
|
||||
|
||||
|
||||
printer_vps_last_status = status;
|
||||
printer_vps_time = millis();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
uint8_t header_init() {
|
||||
|
||||
uint8_t pin[] = {THERMISTORPIN};
|
||||
@ -115,7 +110,6 @@ uint8_t header_init() {
|
||||
pinMode(PEM_PIN, INPUT);
|
||||
// pinMode(PEM_CTL_PIN,OUTPUT);
|
||||
|
||||
|
||||
// adc.setChannels(pin, 1); //this is actually the pin you want to measure
|
||||
|
||||
pinMode(THERMISTORPIN, INPUT); // 数字io没有 模拟接口。adc 读温度暂时不搞
|
||||
@ -124,9 +118,9 @@ uint8_t header_init() {
|
||||
//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");
|
||||
@ -142,10 +136,8 @@ uint8_t header_init() {
|
||||
printer_temp_check = 0;
|
||||
|
||||
glob_file(ADC_FILE_PAT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
uint8_t current_pos = 1;
|
||||
@ -198,24 +190,20 @@ void motor_stepper_pos2(uint8_t position)//forward
|
||||
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;
|
||||
|
||||
restor &= 0x01;
|
||||
|
||||
if(lines>0)
|
||||
{
|
||||
if (lines > 0) {
|
||||
MOTOR_ENABLE1;
|
||||
MOTOR_ENABLE2;
|
||||
ENABLE_VH;
|
||||
while(lines>0)
|
||||
{
|
||||
while (lines > 0) {
|
||||
motor_stepper_pos2(pos); /* 0.0625mm */
|
||||
|
||||
if (pos >= 1 && pos <= 4)
|
||||
@ -229,18 +217,14 @@ uint8_t feed_pitch1(uint64_t lines, uint8_t forward_backward)
|
||||
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)
|
||||
{
|
||||
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;
|
||||
@ -279,21 +263,19 @@ void print_dots_8bit_split(CONFIG*cfg,uint8_t *Array, uint8_t characters)
|
||||
return;
|
||||
}
|
||||
|
||||
void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_num)
|
||||
{
|
||||
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))
|
||||
{
|
||||
while ((i < characters) && (i < MAX)) {
|
||||
printer_send_data8(Array[i]);
|
||||
i++;
|
||||
}
|
||||
while( i < MAX)
|
||||
{
|
||||
while (i < MAX) {
|
||||
printer_send_data8(0x00);
|
||||
i++;
|
||||
}
|
||||
@ -327,12 +309,9 @@ void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_
|
||||
|
||||
i = 0;
|
||||
|
||||
while(y<STB_NUMBER)
|
||||
{
|
||||
|
||||
while(i <10)
|
||||
{
|
||||
while (y < STB_NUMBER) {
|
||||
|
||||
while (i < 10) {
|
||||
|
||||
digitalWrite(STBx[y], HIGH);
|
||||
delayus(HEAT_TIME + cfg->density * 46);
|
||||
@ -344,10 +323,8 @@ void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_
|
||||
y++;
|
||||
}
|
||||
|
||||
|
||||
feed_pitch1(feed_num, cfg->orient);
|
||||
|
||||
|
||||
DISABLE_VH;
|
||||
|
||||
return;
|
||||
@ -372,18 +349,14 @@ uint16_t read_adc(char*adc_file) {
|
||||
return (uint16_t)ret;
|
||||
}
|
||||
|
||||
|
||||
uint16_t temperature() {
|
||||
|
||||
|
||||
double Rthermistor = 0, TempThermistor = 0;
|
||||
uint16_t ADCSamples = 0;
|
||||
int Sample = 1;
|
||||
uint16_t ADCConvertedValue;
|
||||
|
||||
|
||||
while(Sample<=NumSamples)
|
||||
{
|
||||
while (Sample <= NumSamples) {
|
||||
// ADCSamples += analogRead(THERMISTORPIN); //stm32
|
||||
ADCSamples += read_adc(adc_file_path);
|
||||
Sample++;
|
||||
@ -401,7 +374,6 @@ uint16_t temperature() {
|
||||
|
||||
return (uint16_t)(TempThermistor - 273.15);
|
||||
|
||||
|
||||
// return (uint16_t)(0);
|
||||
}
|
||||
|
||||
@ -409,7 +381,8 @@ 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)
|
||||
return 1;
|
||||
@ -418,7 +391,6 @@ int glob_file(char*av) {
|
||||
strcpy(adc_file_path, globlist.gl_pathv[0]);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -467,9 +439,14 @@ uint8_t print_lines_ft(CONFIG*cfg) {
|
||||
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 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;
|
||||
@ -485,9 +462,21 @@ uint8_t print_lines_ft(CONFIG*cfg) {
|
||||
while (i < ser_cache.idx) {
|
||||
ch = (uint8_t *)&ser_cache.data[i];
|
||||
codename = utf8_to_utf32(ch);
|
||||
|
||||
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 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;
|
||||
@ -499,9 +488,14 @@ uint8_t print_lines_ft(CONFIG*cfg) {
|
||||
// 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;}
|
||||
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) {
|
||||
@ -509,14 +503,17 @@ uint8_t print_lines_ft(CONFIG*cfg) {
|
||||
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
|
||||
// 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));
|
||||
@ -533,7 +530,8 @@ uint8_t print_lines_ft(CONFIG*cfg) {
|
||||
dot_line_bitsidx++;
|
||||
w++;
|
||||
line_bits++;
|
||||
if(line_bits >= MAX_DOTS) break;
|
||||
if (line_bits >= MAX_DOTS)
|
||||
break;
|
||||
}
|
||||
// word gap
|
||||
k = 0;
|
||||
@ -545,7 +543,8 @@ uint8_t print_lines_ft(CONFIG*cfg) {
|
||||
k++;
|
||||
dot_line_bitsidx++;
|
||||
line_bits++;
|
||||
if(line_bits >= MAX_DOTS)break;
|
||||
if (line_bits >= MAX_DOTS)
|
||||
break;
|
||||
}
|
||||
|
||||
if (line_bits < MAX_DOTS) {
|
||||
@ -586,10 +585,8 @@ uint8_t print_lines_ft(CONFIG*cfg) {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint8_t print_lines8(CONFIG *cfg) {
|
||||
|
||||
if (cfg->font->mode == FONT_MODE_1) {
|
||||
@ -611,7 +608,6 @@ uint8_t print_lines8(CONFIG*cfg) {
|
||||
int8_t left;
|
||||
uint8_t rv;
|
||||
|
||||
|
||||
pad = current_font.width % BITS8;
|
||||
|
||||
if (pad > 0) {
|
||||
@ -629,7 +625,6 @@ uint8_t print_lines8(CONFIG*cfg) {
|
||||
data = (uint8_t *)malloc(sizeof(uint8_t) * (pad + 1));
|
||||
i = 0;
|
||||
|
||||
|
||||
line_bits = cfg->margin.width;
|
||||
|
||||
dot_line_idx = line_bits / 8;
|
||||
@ -656,12 +651,18 @@ uint8_t print_lines8(CONFIG*cfg) {
|
||||
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;}
|
||||
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 (w > 0 && (w % 8) == 0)
|
||||
j++;
|
||||
if (dot_line_bitsidx > 7) {
|
||||
dot_line_idx++;
|
||||
dot_line_bitsidx = 0;
|
||||
@ -677,7 +678,8 @@ uint8_t print_lines8(CONFIG*cfg) {
|
||||
dot_line_bitsidx++;
|
||||
w++;
|
||||
line_bits++;
|
||||
if(line_bits >= MAX_DOTS)break;
|
||||
if (line_bits >= MAX_DOTS)
|
||||
break;
|
||||
}
|
||||
|
||||
/// word gap
|
||||
@ -691,7 +693,8 @@ uint8_t print_lines8(CONFIG*cfg) {
|
||||
k++;
|
||||
dot_line_bitsidx++;
|
||||
line_bits++;
|
||||
if(line_bits >= MAX_DOTS)break;
|
||||
if (line_bits >= MAX_DOTS)
|
||||
break;
|
||||
}
|
||||
|
||||
if (line_bits < MAX_DOTS) {
|
||||
@ -729,7 +732,6 @@ uint8_t print_lines8(CONFIG*cfg) {
|
||||
if (cfg->line_space > cfg->font->height) {
|
||||
feed_pitch1(cfg->line_space - cfg->font->height, cfg->orient);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Serial.println("print ever");
|
||||
@ -739,7 +741,6 @@ uint8_t print_lines8(CONFIG*cfg) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
uint8_t print_image8(CONFIG *cfg) {
|
||||
|
||||
uint16_t height;
|
||||
@ -755,14 +756,11 @@ uint8_t print_image8(CONFIG*cfg){
|
||||
|
||||
rv = IsPaper();
|
||||
|
||||
while(y < height )
|
||||
{
|
||||
while (y < height) {
|
||||
x = 0;
|
||||
while( x < cfg->img->width )
|
||||
{
|
||||
while (x < cfg->img->width) {
|
||||
addr = x + y * cfg->img->width;
|
||||
|
||||
|
||||
if (cfg->img->revert_bits > 0) // LSB
|
||||
LinePixels[x] = invert_bit(cfg->img->cache[addr]);
|
||||
else
|
||||
@ -804,5 +802,4 @@ void print_cut_line(CONFIG*cfg){
|
||||
}
|
||||
}
|
||||
parse_serial_stream(cfg, ASCII_FF);
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -24,7 +24,8 @@ 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(CONFIG *cfg, uint8_t *Array, uint8_t characters,
|
||||
uint8_t feed_num);
|
||||
|
||||
uint16_t read_adc(char *);
|
||||
uint16_t temperature();
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
#include "utils.h"
|
||||
|
||||
void delayus(unsigned int _us){
|
||||
delayMicroseconds(_us);
|
||||
}
|
||||
void delayus(unsigned int _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);
|
||||
|
||||
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"
|
||||
@ -19,6 +18,3 @@ uint8_t bits_number(uint8_t n)//count bits "1"
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user