mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-15 03:38:50 +01:00
add CONFIG printf
This commit is contained in:
parent
458a7b4c49
commit
c6e3c43116
1
Code/thermal_printer/.gitignore
vendored
1
Code/thermal_printer/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*.o
|
*.o
|
||||||
*.elf
|
*.elf
|
||||||
|
*.swp
|
||||||
|
|||||||
@ -209,6 +209,10 @@ typedef struct _CONFIG
|
|||||||
Margin margin;
|
Margin margin;
|
||||||
FONT*font;
|
FONT*font;
|
||||||
ImageCache *img;
|
ImageCache *img;
|
||||||
|
FILE*fp;
|
||||||
|
|
||||||
|
int (*printf)(struct _CONFIG*, char*, ...);
|
||||||
|
|
||||||
}CONFIG;
|
}CONFIG;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,20 @@ FONT current_font;
|
|||||||
|
|
||||||
CONFIG g_config;
|
CONFIG g_config;
|
||||||
|
|
||||||
|
int printf_out(CONFIG*cfg, char *format, ...) {
|
||||||
|
va_list args;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
if(cfg->fp != NULL)
|
||||||
|
rv = vfprintf(cfg->fp, format, args);
|
||||||
|
else {
|
||||||
|
rv = -1;
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
//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);
|
||||||
@ -453,8 +467,9 @@ void parse_cmd(CONFIG*cfg,uint8_t *cmd, uint8_t cmdidx){
|
|||||||
if ( (IsPaper() & NO_PAPER) > 0 ) {
|
if ( (IsPaper() & NO_PAPER) > 0 ) {
|
||||||
ret |= 1 << 2;
|
ret |= 1 << 2;
|
||||||
}
|
}
|
||||||
|
// 1<< 3 == power error
|
||||||
printf("%d",ret);
|
|
||||||
|
cfg->printf(cfg,"%d",ret);
|
||||||
reset_cmd();
|
reset_cmd();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -658,20 +673,21 @@ void loop() {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int fp;
|
FILE*fp=NULL;
|
||||||
char readbuf[2];
|
char readbuf[2];
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
fp = -1;
|
fp = NULL;
|
||||||
fp = open(FIFO_FILE, O_RDONLY, 0666);
|
fp = fopen(FIFO_FILE,"r+b");
|
||||||
if (fp != -1) {
|
if (fp != NULL) {
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
read(fp,readbuf, 1);
|
fread(readbuf,1, 1,fp);
|
||||||
//printf("read %x",readbuf[0]);
|
//printf("read %x",readbuf[0]);
|
||||||
parse_serial_stream(&g_config,readbuf[0]);
|
parse_serial_stream(&g_config,readbuf[0]);
|
||||||
}
|
}
|
||||||
close(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
@ -692,7 +708,9 @@ void setup() {
|
|||||||
//Serial.begin(115200);
|
//Serial.begin(115200);
|
||||||
|
|
||||||
init_printer();
|
init_printer();
|
||||||
|
|
||||||
|
g_config.printf = &printf_out;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char**argv) {
|
int main(int argc,char**argv) {
|
||||||
|
|||||||
@ -19,3 +19,6 @@ uint8_t bits_number(uint8_t n)//count bits "1"
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user