Merge branch 'thermal_fix1'

This commit is contained in:
cuu 2022-06-05 19:28:57 +08:00
commit 25d70e43f9
4 changed files with 86 additions and 37 deletions

View File

@ -92,6 +92,7 @@
#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 READ_VH digitalRead(VH_PIN)
#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)

View File

@ -126,7 +126,7 @@ void init_printer() {
} }
} }
//default still FONT_MODE_0 //default still FONT_MODE_0, comment out below 4 lines to enable unicode printing
current_font.mode = FONT_MODE_0; current_font.mode = FONT_MODE_0;
current_font.width = 8; current_font.width = 8;
current_font.height = 16; current_font.height = 16;
@ -259,7 +259,7 @@ NULL
cfg->img->revert_bits = 0; cfg->img->revert_bits = 0;
cfg->align = ALIGN_LEFT; cfg->align = ALIGN_LEFT;
feed_pitch1(15, cfg->orient); print_lines8(NULL,15, cfg->orient);
cfg->align = ALIGN_CENTER; cfg->align = ALIGN_CENTER;
/* //selftest1 /* //selftest1
@ -285,7 +285,7 @@ NULL
} }
cfg->align = ALIGN_LEFT; cfg->align = ALIGN_LEFT;
feed_pitch1(32, cfg->orient); print_lines8(NULL,32, cfg->orient);
//--------------------------------------------- //---------------------------------------------
@ -308,7 +308,7 @@ NULL
} }
parse_serial_stream(cfg, 10); parse_serial_stream(cfg, 10);
// Serial.println(); // Serial.println();
feed_pitch1(48, cfg->orient); print_lines8(NULL,48, cfg->orient);
} }
printer_set_font_mode(cfg, FONT_MODE_0); printer_set_font_mode(cfg, FONT_MODE_0);
@ -328,7 +328,7 @@ NULL
} }
parse_serial_stream(cfg, 10); parse_serial_stream(cfg, 10);
// Serial.println(); // Serial.println();
feed_pitch1(48, cfg->orient); print_lines8(NULL,48, cfg->orient);
printer_set_font_mode(cfg, FONT_MODE_0); printer_set_font_mode(cfg, FONT_MODE_0);
printer_set_font(cfg, 0); printer_set_font(cfg, 0);
@ -347,7 +347,7 @@ NULL
} }
parse_serial_stream(cfg, 10); parse_serial_stream(cfg, 10);
// Serial.println(); // Serial.println();
feed_pitch1(28, cfg->orient); print_lines8(NULL,28, cfg->orient);
//------------------------------------------- //-------------------------------------------
@ -368,7 +368,7 @@ NULL
//------------------------------------------ //------------------------------------------
label_print_f(cfg, "Firmware version:", 0.1, ""); label_print_f(cfg, "Firmware version:", 0.1, "");
feed_pitch1(cfg->font->height, cfg->orient); print_lines8(NULL,cfg->font->height, cfg->orient);
//-------------------------------------------------------------- //--------------------------------------------------------------
printer_set_font_mode(cfg, FONT_MODE_0); printer_set_font_mode(cfg, FONT_MODE_0);
printer_set_font(cfg, 0); printer_set_font(cfg, 0);
@ -383,7 +383,7 @@ NULL
//----------------------------------- //-----------------------------------
// grid // grid
/* ENABLE_VH;
for(ch = 0;ch <16;ch++){ for(ch = 0;ch <16;ch++){
if(ch%2==0) if(ch%2==0)
j = 0xff; j = 0xff;
@ -401,9 +401,9 @@ NULL
print_dots_8bit_split(cfg,(uint8_t*)buf,48); print_dots_8bit_split(cfg,(uint8_t*)buf,48);
} }
} }
*/ DISABLE_VH;
//-------------------------------------------------------- //--------------------------------------------------------
feed_pitch1(cfg->font->height * 2, cfg->orient); print_lines8(NULL,cfg->font->height * 2, cfg->orient);
} }
void printer_set_font_mode(CONFIG *cfg, int mode) { void printer_set_font_mode(CONFIG *cfg, int mode) {
@ -499,16 +499,16 @@ void parse_cmd(CONFIG *cfg, uint8_t *cmd, uint8_t cmdidx) {
// ESC j n // ESC j n
if (cmd[0] == ASCII_ESC && cmd[1] == 0x4a) { if (cmd[0] == ASCII_ESC && cmd[1] == 0x4a) {
if (print_lines8(cfg) == 0) { if (print_lines8(cfg,0,0) == 0) {
feed_pitch1(cmd[2], cfg->orient); print_lines8(NULL,cmd[2], cfg->orient);
} }
reset_cmd(); reset_cmd();
} }
// ESC d n // ESC d n
if (cmd[0] == ASCII_ESC && cmd[1] == 0x64) { if (cmd[0] == ASCII_ESC && cmd[1] == 0x64) {
if (print_lines8(cfg) == 0) { if (print_lines8(cfg,0,0) == 0) {
feed_pitch1(cmd[2] * cfg->font->height, cfg->orient); print_lines8(NULL,cmd[2] * cfg->font->height, cfg->orient);
} }
reset_cmd(); reset_cmd();
} }
@ -712,14 +712,14 @@ void parse_serial_stream(CONFIG *cfg, uint8_t input_ch) {
switch (input_ch) { switch (input_ch) {
case ASCII_LF: case ASCII_LF:
if (ser_cache.idx == 0) { if (ser_cache.idx == 0) {
feed_pitch1(cfg->font->height, cfg->orient); print_lines8(NULL,cfg->font->height, cfg->orient);
} }
print_lines8(cfg); print_lines8(cfg,0,0);
reset_cmd(); reset_cmd();
break; break;
case ASCII_FF: case ASCII_FF:
print_lines8(cfg); print_lines8(cfg,0,0);
reset_cmd(); reset_cmd();
break; break;
case ASCII_DC2: case ASCII_DC2:
@ -777,9 +777,9 @@ void parse_serial_stream(CONFIG *cfg, uint8_t input_ch) {
if (a >= MAX_DOTS) // got enough points to print if (a >= MAX_DOTS) // got enough points to print
{ {
if (cfg->font->mode == FONT_MODE_1 && cfg->face != NULL ) { if (cfg->font->mode == FONT_MODE_1 && cfg->face != NULL ) {
print_lines_ft(cfg); print_lines_ft(cfg,0,0);
} else { } else {
print_lines8(cfg); print_lines8(cfg,0,0);
} }
reset_cmd(); reset_cmd();
} }
@ -840,7 +840,7 @@ void print_lowpower(CONFIG *cfg) {
parse_serial_stream(cfg, 10); parse_serial_stream(cfg, 10);
reset_cmd(); reset_cmd();
feed_pitch1(128, cfg->orient); print_lines8(NULL,128, cfg->orient);
printer_set_font(cfg, 0); printer_set_font(cfg, 0);
PRINTF("%s\n", msg); PRINTF("%s\n", msg);

View File

@ -26,6 +26,10 @@ static uint8_t printer_temp_check;
static char adc_file_path[128]; static char adc_file_path[128];
static unsigned int printer_last_pitch_time;
static uint8_t acc_time_idx;
static uint16_t acc_time[] = {5459,3459,2762,2314,2028,1828,1675,1553,1456,1374,1302,1242,1191,1144,1103,1065,1031,1000,970,940,910,880};
#define ACCMAX 22
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 digitalWrite(SPI1_NSS_PIN, LOW); // manually take CSN low for SPI_1
@ -53,7 +57,6 @@ void clear_printer_buffer() {
uint8_t IsPaper() { uint8_t IsPaper() {
uint8_t status; uint8_t status;
uint8_t tmp; uint8_t tmp;
return IS_PAPER;
if (millis() - printer_vps_time > 10) { if (millis() - printer_vps_time > 10) {
ENABLE_PEM; ENABLE_PEM;
@ -63,6 +66,7 @@ uint8_t IsPaper() {
} else { } else {
status = NO_PAPER; status = NO_PAPER;
PRINTF("Error:NO PAPER\n"); PRINTF("Error:NO PAPER\n");
DISABLE_VH;
} }
DISABLE_PEM; DISABLE_PEM;
@ -72,6 +76,7 @@ uint8_t IsPaper() {
if (tmp >= HOT) { if (tmp >= HOT) {
PRINTF("Printer too Hot\n"); PRINTF("Printer too Hot\n");
status |= HOT_PRINTER; status |= HOT_PRINTER;
DISABLE_VH;
} }
printer_temp_check = 0; printer_temp_check = 0;
@ -132,8 +137,10 @@ uint8_t header_init() {
*/ */
printer_vps_time = 0; printer_vps_time = 0;
printer_vps_last_status = IS_PAPER; printer_vps_last_status = NO_PAPER;
printer_temp_check = 0; printer_temp_check = 0;
printer_last_pitch_time = 0;
acc_time_idx = 0;
glob_file(ADC_FILE_PAT); glob_file(ADC_FILE_PAT);
} }
@ -158,7 +165,29 @@ void motor_stepper_pos2(uint8_t position) // forward
{ {
// position = 9 - position; // position = 9 - position;
// position = (position+1)/2; // position = (position+1)/2;
delayMicroseconds(6700); if(printer_last_pitch_time == 0) {
acc_time_idx = 0;
}else {
if( millis() - printer_last_pitch_time > 100 ) {
if(READ_VH == LOW) {
acc_time_idx = 0;
}else{
acc_time_idx ++;
if(acc_time_idx > ACCMAX-1) {
acc_time_idx = ACCMAX-1;
}
}
} else {
acc_time_idx ++;
if(acc_time_idx > ACCMAX-1) {
acc_time_idx = ACCMAX-1;
}
}
}
printer_last_pitch_time = millis();
delayMicroseconds(acc_time[acc_time_idx]);
switch (position) { switch (position) {
case 0: case 0:
digitalWrite(PA_PIN, LOW); digitalWrite(PA_PIN, LOW);
@ -200,9 +229,10 @@ uint8_t feed_pitch1(uint64_t lines, uint8_t forward_backward) {
restor &= 0x01; restor &= 0x01;
if (lines > 0) { if (lines > 0) {
/*
MOTOR_ENABLE1; MOTOR_ENABLE1;
MOTOR_ENABLE2; MOTOR_ENABLE2;
ENABLE_VH; */
while (lines > 0) { while (lines > 0) {
motor_stepper_pos2(pos); /* 0.0625mm */ motor_stepper_pos2(pos); /* 0.0625mm */
@ -213,10 +243,10 @@ uint8_t feed_pitch1(uint64_t lines, uint8_t forward_backward) {
lines--; lines--;
} }
/*
MOTOR_DISABLE1; MOTOR_DISABLE1;
MOTOR_DISABLE2; MOTOR_DISABLE2;
DISABLE_VH; */
} else { } else {
return ERROR_FEED_PITCH; return ERROR_FEED_PITCH;
} }
@ -268,7 +298,6 @@ void print_dots_8bit(CONFIG *cfg, uint8_t *Array, uint8_t characters,
uint8_t i = 0, y = 0, MAX = MAXPIXELS; uint8_t i = 0, y = 0, MAX = MAXPIXELS;
uint8_t blank; uint8_t blank;
ENABLE_VH;
if (cfg->align == 0) { if (cfg->align == 0) {
while ((i < characters) && (i < MAX)) { while ((i < characters) && (i < MAX)) {
@ -325,7 +354,6 @@ void print_dots_8bit(CONFIG *cfg, uint8_t *Array, uint8_t characters,
feed_pitch1(feed_num, cfg->orient); feed_pitch1(feed_num, cfg->orient);
DISABLE_VH;
return; return;
} }
@ -414,7 +442,8 @@ uint16_t get_serial_cache_font_width(CONFIG *cfg) {
} }
// print with freetype font dots glyph // print with freetype font dots glyph
uint8_t print_lines_ft(CONFIG *cfg) { uint8_t print_lines_ft(CONFIG *cfg,int lines,int bf) {
uint8_t i, j, k; uint8_t i, j, k;
int8_t w; int8_t w;
uint8_t dot_line_data[MAXPIXELS]; uint8_t dot_line_data[MAXPIXELS];
@ -427,7 +456,13 @@ uint8_t print_lines_ft(CONFIG *cfg) {
int8_t left = ser_cache.idx; int8_t left = ser_cache.idx;
uint8_t rv; uint8_t rv;
if(cfg == NULL && lines > 0) {
ENABLE_VH;
feed_pitch1(lines,bf);
DISABLE_VH;
return 0;
}
line_bits = cfg->margin.width; line_bits = cfg->margin.width;
dot_line_idx = line_bits / 8; dot_line_idx = line_bits / 8;
dot_line_bitsidx = line_bits % 8; dot_line_bitsidx = line_bits % 8;
@ -446,7 +481,7 @@ uint8_t print_lines_ft(CONFIG *cfg) {
abs(cfg->face->descender) * current_font.height / cfg->face->units_per_EM; abs(cfg->face->descender) * current_font.height / cfg->face->units_per_EM;
int dpx = 64; int dpx = 64;
FT_Matrix matrix; FT_Matrix matrix;
ENABLE_VH;
while (left > 0) { while (left > 0) {
i = lastidx; i = lastidx;
row_cnt = 0; row_cnt = 0;
@ -585,12 +620,23 @@ uint8_t print_lines_ft(CONFIG *cfg) {
} }
*/ */
} }
DISABLE_VH;
} }
uint8_t print_lines8(CONFIG *cfg) { uint8_t print_lines8(CONFIG *cfg,int lines,int backforward) {
if(lines > 0 && cfg == NULL ){
ENABLE_VH;
feed_pitch1(lines,backforward);
DISABLE_VH;
return 0;
}
if (cfg->font->mode == FONT_MODE_1 && cfg->face!=NULL) { if (cfg->font->mode == FONT_MODE_1 && cfg->face!=NULL) {
return print_lines_ft(cfg);
return print_lines_ft(cfg,0,0);
} }
uint8_t i, j, k; uint8_t i, j, k;
int8_t w; int8_t w;
@ -635,6 +681,7 @@ uint8_t print_lines8(CONFIG *cfg) {
lastj = 0; lastj = 0;
// DEBUG("left",left); // DEBUG("left",left);
ENABLE_VH;
while (left > 0) { while (left > 0) {
i = lastidx; i = lastidx;
while (row < current_font.height) { while (row < current_font.height) {
@ -737,7 +784,7 @@ uint8_t print_lines8(CONFIG *cfg) {
// Serial.println("print ever"); // Serial.println("print ever");
free(data); free(data);
DISABLE_VH;
return rv; return rv;
} }
@ -755,7 +802,7 @@ uint8_t print_image8(CONFIG *cfg) {
addr = 0; addr = 0;
rv = IsPaper(); rv = IsPaper();
ENABLE_VH;
while (y < height) { while (y < height) {
x = 0; x = 0;
while (x < cfg->img->width) { while (x < cfg->img->width) {
@ -782,6 +829,7 @@ uint8_t print_image8(CONFIG *cfg) {
cfg->img->num = 0; cfg->img->num = 0;
cfg->img->idx = 0; cfg->img->idx = 0;
cfg->img->width = 0; cfg->img->width = 0;
DISABLE_VH;
return rv; return rv;
} }

View File

@ -31,8 +31,8 @@ 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 *,int ,int);
uint8_t print_lines8(CONFIG *); uint8_t print_lines8(CONFIG *,int,int);
uint8_t invert_bit(uint8_t a); uint8_t invert_bit(uint8_t a);