mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-13 02:38:50 +01:00
add schematic pdfs and firmware code
This commit is contained in:
parent
7c8c69ab83
commit
9278b6bad3
13
Code/devterm_keyboard/README.md
Normal file
13
Code/devterm_keyboard/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
Arduino 1.8.13
|
||||
|
||||
http://dan.drown.org/stm32duino/package_STM32duino_index.json
|
||||
|
||||
STM32F1xx/GD32F1xx boards
|
||||
by stm32duino version 2021.2.22
|
||||
|
||||
GENERIC STM32F103R series
|
||||
|
||||
gd32f1_generic_boot20_pc13.bin
|
||||
generic_boot20_pc13.bin
|
||||
|
||||
|
||||
29
Code/devterm_keyboard/devterm.h
Normal file
29
Code/devterm_keyboard/devterm.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef DEVTERM_H
|
||||
#define DEVTERM_H
|
||||
|
||||
|
||||
#include <USBComposite.h>
|
||||
|
||||
typedef struct keyboard_state{
|
||||
|
||||
uint8_t layer;
|
||||
uint8_t shift;
|
||||
uint8_t caps_lock;
|
||||
|
||||
}KEYBOARD_STATE;
|
||||
|
||||
class DEVTERM {
|
||||
public:
|
||||
HIDKeyboard *Keyboard;
|
||||
HIDMouse *Mouse;
|
||||
HIDJoystick *Joystick;
|
||||
KEYBOARD_STATE Keyboard_state;
|
||||
USBCompositeSerial *_Serial;
|
||||
//if not to use USBCompositeSerial,then use default Serial
|
||||
//**Serial and USBCompositeSerial can not use together, otherwise the keyboard firmware uploading will be dead**
|
||||
//and you will need to find a way out to flash the stm32duino bootloader once again
|
||||
//USBSerial *_Serial;//_Serial = &Serial;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
49
Code/devterm_keyboard/devterm_keyboard.ino
Normal file
49
Code/devterm_keyboard/devterm_keyboard.ino
Normal file
@ -0,0 +1,49 @@
|
||||
#include "keyboard.h"
|
||||
#include "keys.h"
|
||||
#include "trackball.h"
|
||||
#include "devterm.h"
|
||||
|
||||
#include <USBComposite.h>
|
||||
|
||||
#define SER_NUM_STR "20210320"
|
||||
|
||||
USBHID HID;
|
||||
DEVTERM dev_term;
|
||||
|
||||
void setup() {
|
||||
USBComposite.setManufacturerString("ClockworkPI");
|
||||
USBComposite.setProductString("DevTerm");
|
||||
USBComposite.setSerialString(SER_NUM_STR);
|
||||
|
||||
dev_term.Keyboard = new HIDKeyboard(HID);
|
||||
dev_term.Joystick = new HIDJoystick(HID);
|
||||
dev_term.Mouse = new HIDMouse(HID);
|
||||
|
||||
dev_term.Keyboard_state.shift = 0;
|
||||
dev_term.Keyboard_state.layer = 0;
|
||||
dev_term.Keyboard_state.caps_lock = 0;
|
||||
|
||||
dev_term._Serial = new USBCompositeSerial;
|
||||
|
||||
HID.begin(*dev_term._Serial,HID_KEYBOARD_MOUSE_JOYSTICK);
|
||||
|
||||
while(!USBComposite);//wait until usb port been plugged in to PC
|
||||
|
||||
|
||||
keyboard_init(&dev_term);
|
||||
keys_init(&dev_term);
|
||||
trackball_init(&dev_term);
|
||||
|
||||
dev_term._Serial->println("setup done");
|
||||
|
||||
//delay(3000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
trackball_task(&dev_term);
|
||||
keys_task(&dev_term); //keys above keyboard
|
||||
keyboard_task(&dev_term);
|
||||
|
||||
|
||||
}
|
||||
19
Code/devterm_keyboard/helper.h
Normal file
19
Code/devterm_keyboard/helper.h
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
*
|
||||
|
||||
|
||||
|
||||
*/
|
||||
#ifndef HELPER_H
|
||||
#define HELPER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
uint8_t read_io(uint8_t io);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
11
Code/devterm_keyboard/helper.ino
Normal file
11
Code/devterm_keyboard/helper.ino
Normal file
@ -0,0 +1,11 @@
|
||||
#include "helper.h"
|
||||
|
||||
|
||||
uint8_t read_io(uint8_t io) {
|
||||
|
||||
if(digitalRead(io) == LOW ){
|
||||
return 0;
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
52
Code/devterm_keyboard/keyboard.h
Normal file
52
Code/devterm_keyboard/keyboard.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef KEYBOARD_H
|
||||
#define KEYBOARD_H
|
||||
|
||||
/*
|
||||
* clockworkpi devterm keyboard test2
|
||||
* able to correct scan the 8x8 keypads re-action
|
||||
*/
|
||||
|
||||
#include "devterm.h"
|
||||
|
||||
#include "keys_io_map.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MATRIX_ROWS 8
|
||||
#define MATRIX_COLS 8
|
||||
|
||||
#ifndef DEBOUNCE
|
||||
# define DEBOUNCE 5
|
||||
#endif
|
||||
|
||||
void init_rows();
|
||||
void init_cols();
|
||||
uint8_t read_io(uint8_t io);
|
||||
|
||||
void matrix_init();
|
||||
uint8_t matrix_scan(void);
|
||||
|
||||
bool matrix_is_on(uint8_t row, uint8_t col);
|
||||
uint8_t matrix_get_row(uint8_t row) ;
|
||||
|
||||
|
||||
//void matrix_print(void);
|
||||
|
||||
|
||||
|
||||
void keyboard_task(DEVTERM*);
|
||||
void keyboard_init(DEVTERM*);
|
||||
|
||||
|
||||
#define KEY_PRESSED 1
|
||||
#define KEY_RELEASED 0
|
||||
|
||||
#define KEY_PRNT_SCRN 0xCE //Print screen
|
||||
#define KEY_PAUSE 0xd0
|
||||
|
||||
#define KEY_VOLUME_UP 0x108
|
||||
#define KEY_VOLUME_DOWN 0x109
|
||||
|
||||
#endif
|
||||
188
Code/devterm_keyboard/keyboard.ino
Normal file
188
Code/devterm_keyboard/keyboard.ino
Normal file
@ -0,0 +1,188 @@
|
||||
#include "keyboard.h"
|
||||
#include "helper.h"
|
||||
|
||||
|
||||
static bool debouncing = false;
|
||||
static uint16_t debouncing_time = 0;
|
||||
|
||||
uint8_t matrix_rows[ MATRIX_ROWS ]= {ROW1,ROW2,ROW3,ROW4,ROW5,ROW6,ROW7,ROW8};
|
||||
uint8_t matrix_cols[ MATRIX_COLS ] = {COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8};
|
||||
|
||||
/* matrix state(1:on, 0:off) */
|
||||
static uint8_t matrix[MATRIX_ROWS];
|
||||
static uint8_t matrix_debouncing[MATRIX_COLS];
|
||||
static uint8_t matrix_prev[MATRIX_ROWS];
|
||||
|
||||
static int8_t jack_idx=-1;
|
||||
static uint16_t jack_time = 0;
|
||||
|
||||
|
||||
|
||||
void init_rows(){
|
||||
int i;
|
||||
for(i=0;i<8;i++) {
|
||||
pinMode(matrix_rows[i],OUTPUT);
|
||||
digitalWrite(matrix_rows[i],LOW);
|
||||
|
||||
pinMode(matrix_rows[i],INPUT_PULLDOWN);
|
||||
}
|
||||
}
|
||||
|
||||
void init_cols() {
|
||||
|
||||
int i;
|
||||
for(i=0;i<8;i++){
|
||||
pinMode(matrix_cols[i],OUTPUT);
|
||||
digitalWrite(matrix_cols[i],LOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void matrix_init() {
|
||||
init_cols();
|
||||
init_rows();
|
||||
|
||||
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||
matrix[i] = 0;
|
||||
matrix_debouncing[i] = 0;
|
||||
matrix_prev[i] = 0;
|
||||
}
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void) {
|
||||
|
||||
uint8_t data;
|
||||
for(int col = 0; col < MATRIX_COLS;col++){
|
||||
data = 0;
|
||||
digitalWrite(matrix_cols[col],HIGH);
|
||||
|
||||
|
||||
delayMicroseconds(20);
|
||||
|
||||
data =(
|
||||
( read_io(matrix_rows[0]) << 0 ) |
|
||||
( read_io(matrix_rows[1]) << 1 ) |
|
||||
( read_io(matrix_rows[2]) << 2 ) |
|
||||
( read_io(matrix_rows[3]) << 3 ) |
|
||||
( read_io(matrix_rows[4]) << 4 ) |
|
||||
( read_io(matrix_rows[5]) << 5 ) |
|
||||
( read_io(matrix_rows[6]) << 6 ) |
|
||||
( read_io(matrix_rows[7]) << 7 )
|
||||
);
|
||||
|
||||
digitalWrite(matrix_cols[col],LOW);
|
||||
if (matrix_debouncing[col] != data) {
|
||||
matrix_debouncing[col] = data;
|
||||
debouncing = true;
|
||||
debouncing_time = millis();
|
||||
}
|
||||
}
|
||||
|
||||
if (debouncing == true && ( (millis() - debouncing_time) > DEBOUNCE )) {
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
matrix[row] = 0;
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col);
|
||||
|
||||
}
|
||||
}
|
||||
debouncing = false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool matrix_is_on(uint8_t row, uint8_t col) {
|
||||
return (matrix[row] & (1<<col));
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t matrix_get_row(uint8_t row) {
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
|
||||
void matrix_press(DEVTERM*dv,uint8_t row,uint8_t col) {
|
||||
char buff[128];
|
||||
|
||||
if(matrix_is_on(row,col) == true ){
|
||||
sprintf(buff,"%d %d M%d pressed\n",row,col,(row+1)*10+col+1);
|
||||
dv->_Serial->print(buff);
|
||||
keyboard_action(dv,row,col,KEY_PRESSED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void matrix_release(DEVTERM*dv,uint8_t row,uint8_t col) {
|
||||
char buff[128];
|
||||
|
||||
|
||||
if(matrix_is_on(row,col) == false ){
|
||||
sprintf(buff,"%d %d M%d released\n",row,col,(row+1)*10+col+1);
|
||||
dv->_Serial->print(buff);
|
||||
keyboard_action(dv,row,col,KEY_RELEASED);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void keyboard_task(DEVTERM*dv)
|
||||
{
|
||||
|
||||
uint8_t matrix_row = 0;
|
||||
uint8_t matrix_change = 0;
|
||||
|
||||
matrix_scan();
|
||||
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
|
||||
matrix_row = matrix_get_row(r);
|
||||
|
||||
uint8_t col_mask =1;
|
||||
for(uint8_t c=0;c < MATRIX_COLS;c++,col_mask <<=1){
|
||||
|
||||
if( ( (matrix_prev[r] & col_mask) == 0) && ( (matrix_row & col_mask) > 0) ) {
|
||||
matrix_press(dv,r,c);
|
||||
}
|
||||
|
||||
if( ( (matrix_prev[r] & col_mask) > 0) && ( (matrix_row & col_mask) == 0) ) {
|
||||
|
||||
matrix_release(dv,r,c);
|
||||
}
|
||||
|
||||
if( ( (matrix_prev[r] & col_mask) > 0) && ( (matrix_row & col_mask) > 0) ) {//same key
|
||||
|
||||
|
||||
if( jack_idx == -1){
|
||||
jack_idx = r*MATRIX_ROWS+c;
|
||||
}else{
|
||||
|
||||
if(jack_idx != r*MATRIX_ROWS+c) {
|
||||
jack_time = 0;
|
||||
jack_idx = r*MATRIX_ROWS+c;
|
||||
}else{
|
||||
jack_time +=1;
|
||||
if( jack_time % (DEBOUNCE*20) == 0){
|
||||
if(jack_idx > 1){//skip select,start button
|
||||
matrix_press(dv,r,c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix_prev[r] = matrix_row;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void keyboard_init(DEVTERM*){
|
||||
matrix_init();
|
||||
|
||||
}
|
||||
288
Code/devterm_keyboard/keymaps.ino
Normal file
288
Code/devterm_keyboard/keymaps.ino
Normal file
@ -0,0 +1,288 @@
|
||||
#include "devterm.h"
|
||||
#include "keyboard.h"
|
||||
#include "keys.h"
|
||||
|
||||
#define EMP 0XFFFF
|
||||
|
||||
/*
|
||||
B1 joystick up
|
||||
B2 joystick down
|
||||
B3 joystick left
|
||||
B4 joystick right
|
||||
|
||||
B5 joystick A
|
||||
B6 joystick B
|
||||
B7 joystick X
|
||||
B8 joystick Y
|
||||
|
||||
B9 left shift
|
||||
B10 Fn
|
||||
B11 left Ctrl
|
||||
B12 Cmd
|
||||
B13 left Alt
|
||||
B14 mouse left
|
||||
B15 mouse mid
|
||||
B16 mouse right
|
||||
*/
|
||||
#define _PRINT_KEY KEY_PRNT_SCRN
|
||||
#define _PAUSE_KEY KEY_PAUSE
|
||||
#define _VOLUME_M KEY_VOLUME_DOWN
|
||||
#define _VOLUME_P KEY_VOLUME_UP
|
||||
#define _LEFT_SHIFT_KEY KEY_LEFT_SHIFT
|
||||
#define _LEFT_CTRL_KEY KEY_LEFT_CTRL
|
||||
#define _CMD_KEY KEY_RIGHT_GUI
|
||||
#define _LEFT_ALT KEY_LEFT_ALT
|
||||
|
||||
enum SKEYS {
|
||||
_SELECT_KEY =0xe8, //Joystick.button(n)
|
||||
_START_KEY, //Joystick.button(n)
|
||||
_JOYSTICK_UP, //B1 //Joystick.Y()
|
||||
_JOYSTICK_DOWN, //Joystick.Y()
|
||||
_JOYSTICK_LEFT, //Joystick.X()
|
||||
_JOYSTICK_RIGHT, //Joystick.X()
|
||||
_JOYSTICK_A, //Joystick.button(1)
|
||||
_JOYSTICK_B, //Joystick.button(2)
|
||||
_JOYSTICK_X, //Joystick.button(3)
|
||||
_JOYSTICK_Y, //Joystick.button(4)
|
||||
_FN_KEY,
|
||||
_MOUSE_LEFT, // Mouse.press(1)
|
||||
_MOUSE_MID, // Mouse.press(2)
|
||||
_MOUSE_RIGHT, // Mouse.press(3)
|
||||
|
||||
|
||||
};
|
||||
|
||||
#define DEF_LAYER 0x00
|
||||
#define SHI_LAYER 0x01
|
||||
#define CAPS_LAYER 0x02
|
||||
#define FN_LAYER 0x03
|
||||
|
||||
/*
|
||||
* keyboard_maps
|
||||
* M11 - M18
|
||||
* M21 - M28
|
||||
* M31 - M38
|
||||
* M41 - M48
|
||||
* M51 - M58
|
||||
* M61 - M68
|
||||
* M71 - M78
|
||||
* M81 - M88
|
||||
*/
|
||||
const uint16_t keyboard_maps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
|
||||
[DEF_LAYER] = { _SELECT_KEY,_START_KEY,_VOLUME_M,'`','[',']','-','=', \
|
||||
'1','2','3','4','5','6','7','8',\
|
||||
'9','0',KEY_ESC,KEY_TAB,KEY_UP_ARROW,KEY_DOWN_ARROW,KEY_LEFT_ARROW,KEY_RIGHT_ARROW, \
|
||||
'q','w','e','r','t','y','u','i', \
|
||||
'o','p','a','s','d','f','g','h',\
|
||||
'j','k','l','z','x','c','v','b', \
|
||||
'n','m',',','.','/','\\',';','\'', \
|
||||
KEY_BACKSPACE,KEY_RETURN,KEY_RIGHT_ALT,KEY_RIGHT_CTRL,KEY_RIGHT_SHIFT,' ',EMP,EMP},
|
||||
|
||||
[SHI_LAYER] = {_SELECT_KEY,_START_KEY,_VOLUME_P,'~','{','}','_','+', \
|
||||
'!','@','#','$','%','^','&','*',\
|
||||
'(',')',KEY_ESC,KEY_TAB,KEY_PAGE_UP,KEY_PAGE_DOWN,KEY_HOME,KEY_END, \
|
||||
'Q','W','E','R','T','Y','U','I', \
|
||||
'O','P','A','S','D','F','G','H',\
|
||||
'J','K','L','Z','X','C','V','B', \
|
||||
'N','M','<','>','?','|',':','"', \
|
||||
KEY_BACKSPACE,KEY_RETURN,KEY_RIGHT_ALT,KEY_RIGHT_CTRL,KEY_RIGHT_SHIFT,' ',EMP,EMP},
|
||||
|
||||
[CAPS_LAYER] = { _SELECT_KEY,_START_KEY,_VOLUME_M,'`','[',']','-','=', \
|
||||
'1','2','3','4','5','6','7','8',\
|
||||
'9','0',KEY_ESC,KEY_TAB,KEY_UP_ARROW,KEY_DOWN_ARROW,KEY_LEFT_ARROW,KEY_RIGHT_ARROW, \
|
||||
'Q','W','E','R','T','Y','U','I', \
|
||||
'O','P','A','S','D','F','G','H',\
|
||||
'J','K','L','Z','X','C','V','B', \
|
||||
'N','M',',','.','/','\\',';','\'', \
|
||||
KEY_BACKSPACE,KEY_RETURN,KEY_RIGHT_ALT,KEY_RIGHT_CTRL,KEY_RIGHT_SHIFT,' ',EMP,EMP},
|
||||
|
||||
[FN_LAYER] = { _PRINT_KEY,_PAUSE_KEY,_VOLUME_M,'`','[',']',KEY_F11,KEY_F12, \
|
||||
KEY_F1,KEY_F2,KEY_F3,KEY_F4,KEY_F5,KEY_F6,KEY_F7,KEY_F8,\
|
||||
KEY_F9,KEY_F10,KEY_ESC,KEY_CAPS_LOCK,KEY_UP_ARROW,KEY_DOWN_ARROW,KEY_LEFT_ARROW,KEY_RIGHT_ARROW, \
|
||||
'q','w','e','r','t','y','u',KEY_INSERT, \
|
||||
'o','p','a','s','d','f','g','h',\
|
||||
'j','k','l','z','x','c','v','b', \
|
||||
'n','m',',','.','/','\\',';','\'', \
|
||||
KEY_DELETE,KEY_RETURN,KEY_RIGHT_ALT,KEY_RIGHT_CTRL,KEY_RIGHT_SHIFT,' ',EMP,EMP}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
const uint16_t keys_maps[KEYS_NUM] = {_JOYSTICK_UP,_JOYSTICK_DOWN, _JOYSTICK_LEFT, \
|
||||
_JOYSTICK_RIGHT,_JOYSTICK_A,_JOYSTICK_B, \
|
||||
_JOYSTICK_X,_JOYSTICK_Y,_LEFT_SHIFT_KEY,_FN_KEY,\
|
||||
_LEFT_CTRL_KEY,_CMD_KEY , _LEFT_ALT, \
|
||||
_MOUSE_LEFT,_MOUSE_MID,_MOUSE_RIGHT};
|
||||
|
||||
|
||||
void keyboard_action(DEVTERM*dv,uint8_t row,uint8_t col,uint8_t mode) {
|
||||
|
||||
uint16_t k;
|
||||
|
||||
k = keyboard_maps[dv->Keyboard_state.layer][row][col];
|
||||
|
||||
if(k == EMP){
|
||||
return;
|
||||
}
|
||||
|
||||
switch(k) {
|
||||
case _LEFT_SHIFT_KEY:
|
||||
case KEY_RIGHT_SHIFT:
|
||||
if(mode == KEY_PRESSED) {
|
||||
dv->_Serial->println("into shift layer");
|
||||
dv->Keyboard_state.layer = SHI_LAYER;
|
||||
dv->Keyboard->press(k);
|
||||
}else if(mode == KEY_RELEASED) {
|
||||
dv->_Serial->println("leave shift layer");
|
||||
dv->Keyboard_state.layer = DEF_LAYER;
|
||||
dv->Keyboard->release(k);
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_CAPS_LOCK:
|
||||
if(mode == KEY_PRESSED) {
|
||||
dv->Keyboard_state.layer = CAPS_LAYER;
|
||||
dv->Keyboard->press(k);
|
||||
|
||||
}else if(mode == KEY_RELEASED) {
|
||||
dv->Keyboard->release(k);
|
||||
if(dv->Keyboard_state.caps_lock == 0) {
|
||||
dv->Keyboard_state.caps_lock = 1;
|
||||
}else{
|
||||
dv->Keyboard_state.caps_lock = 0;
|
||||
dv->Keyboard_state.layer = DEF_LAYER;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case _SELECT_KEY:
|
||||
dv->Joystick->button(9,mode);
|
||||
break;
|
||||
case _START_KEY:
|
||||
dv->Joystick->button(10,mode);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if(mode == KEY_PRESSED) {
|
||||
dv->Keyboard->press(k);
|
||||
}else if(mode == KEY_RELEASED) {
|
||||
dv->Keyboard->release(k);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void keypad_action(DEVTERM*dv,uint8_t col,uint8_t mode) {
|
||||
|
||||
uint16_t k;
|
||||
|
||||
k = keys_maps[col];
|
||||
|
||||
if(k == EMP){
|
||||
return;
|
||||
}
|
||||
|
||||
switch(k) {
|
||||
case _LEFT_SHIFT_KEY:
|
||||
case KEY_RIGHT_SHIFT:
|
||||
if(mode == KEY_PRESSED) {
|
||||
dv->Keyboard_state.layer = SHI_LAYER;
|
||||
dv->Keyboard->press(k);
|
||||
}else if(mode == KEY_RELEASED) {
|
||||
dv->Keyboard_state.layer = DEF_LAYER;
|
||||
dv->Keyboard->release(k);
|
||||
}
|
||||
break;
|
||||
case _FN_KEY:
|
||||
if(mode == KEY_PRESSED){
|
||||
dv->Keyboard_state.layer = FN_LAYER;
|
||||
}else if(mode == KEY_RELEASED ) {
|
||||
dv->Keyboard_state.layer = DEF_LAYER;
|
||||
}
|
||||
break;
|
||||
|
||||
case _JOYSTICK_UP:
|
||||
if(mode == KEY_RELEASED){
|
||||
dv->Joystick->Y(511);
|
||||
}else {
|
||||
dv->Joystick->Y(0);
|
||||
}
|
||||
break;
|
||||
case _JOYSTICK_DOWN:
|
||||
if(mode == KEY_RELEASED){
|
||||
dv->Joystick->Y(511);
|
||||
}else {
|
||||
dv->Joystick->Y(1023);
|
||||
}
|
||||
break;
|
||||
case _JOYSTICK_LEFT:
|
||||
if(mode == KEY_RELEASED){
|
||||
dv->Joystick->X(0);
|
||||
}else {
|
||||
dv->Joystick->X(511);
|
||||
}
|
||||
break;
|
||||
case _JOYSTICK_RIGHT:
|
||||
if(mode == KEY_RELEASED){
|
||||
dv->Joystick->X(511);
|
||||
}else {
|
||||
dv->Joystick->X(1023);
|
||||
}
|
||||
break;
|
||||
case _JOYSTICK_A:
|
||||
dv->Joystick->button(2,mode);
|
||||
break;
|
||||
case _JOYSTICK_B:
|
||||
dv->Joystick->button(3,mode);
|
||||
break;
|
||||
case _JOYSTICK_X:
|
||||
dv->Joystick->button(1,mode);
|
||||
break;
|
||||
case _JOYSTICK_Y:
|
||||
dv->Joystick->button(4,mode);
|
||||
break;
|
||||
case _MOUSE_LEFT:
|
||||
if(mode == KEY_PRESSED){
|
||||
dv->Mouse->press(1);
|
||||
}else if(mode == KEY_RELEASED){
|
||||
dv->Mouse->release(1);
|
||||
}
|
||||
break;
|
||||
case _MOUSE_MID:
|
||||
if(mode == KEY_PRESSED){
|
||||
dv->Mouse->press(2);
|
||||
}else if(mode == KEY_RELEASED){
|
||||
dv->Mouse->release(2);
|
||||
}
|
||||
break;
|
||||
|
||||
case _MOUSE_RIGHT:
|
||||
if(mode == KEY_PRESSED){
|
||||
dv->Mouse->press(3);
|
||||
}else if(mode == KEY_RELEASED){
|
||||
dv->Mouse->release(3);
|
||||
}
|
||||
break;
|
||||
|
||||
//_LEFT_CTRL_KEY,_CMD_KEY , _LEFT_ALT
|
||||
case _LEFT_CTRL_KEY:
|
||||
case _CMD_KEY:
|
||||
case _LEFT_ALT:
|
||||
if(mode == KEY_PRESSED){
|
||||
dv->Keyboard->press(k);
|
||||
}else {
|
||||
dv->Keyboard->release(k);
|
||||
}
|
||||
break;
|
||||
|
||||
default:break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
27
Code/devterm_keyboard/keys.h
Normal file
27
Code/devterm_keyboard/keys.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef KEYS_H
|
||||
#define KEYS_H
|
||||
/*
|
||||
* keys include the joystick and mouse left/mid/right keys
|
||||
*/
|
||||
|
||||
#include "devterm.h"
|
||||
#include "keys_io_map.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef KEY_DEBOUNCE
|
||||
# define KEY_DEBOUNCE 5
|
||||
#endif
|
||||
|
||||
#define KEYS_NUM 16
|
||||
|
||||
|
||||
void keys_task(DEVTERM*);
|
||||
void keys_init(DEVTERM*);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
115
Code/devterm_keyboard/keys.ino
Normal file
115
Code/devterm_keyboard/keys.ino
Normal file
@ -0,0 +1,115 @@
|
||||
#include "keys.h"
|
||||
|
||||
static bool key_debouncing = false;
|
||||
static uint16_t key_debouncing_time = 0;
|
||||
|
||||
uint8_t keys_io[ KEYS_NUM ]= {KEY1,KEY2,KEY3,KEY4,KEY5,KEY6,KEY7,KEY8,KEY9,KEY10,KEY11,KEY12,KEY13,KEY14,KEY15,KEY16};
|
||||
|
||||
/* keys state(1:on, 0:off) */
|
||||
static uint16_t keys;
|
||||
static uint16_t keys_debouncing;
|
||||
static uint16_t keys_prev;
|
||||
|
||||
|
||||
static int8_t keys_jack_idx=-1;
|
||||
static uint16_t keys_jack_time = 0;
|
||||
|
||||
void init_keys(){
|
||||
int i;
|
||||
for(i=0;i<KEYS_NUM;i++) {
|
||||
pinMode( keys_io[i],INPUT_PULLUP);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t scan_keys(){
|
||||
uint16_t data;
|
||||
uint8_t s;
|
||||
|
||||
data = 0;
|
||||
delayMicroseconds(20);
|
||||
for(int i = 0;i < KEYS_NUM;i++) {
|
||||
|
||||
s = digitalRead(keys_io[i]); //HIGH =0,LOW = 1
|
||||
if( s == LOW ){
|
||||
data |= 1 << i;
|
||||
}else {
|
||||
data |= 0 << i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( keys_debouncing != data ) {
|
||||
keys_debouncing = data;
|
||||
key_debouncing = true;
|
||||
key_debouncing_time = millis();
|
||||
}
|
||||
|
||||
if (key_debouncing == true && ( (millis() - key_debouncing_time) > KEY_DEBOUNCE )) {
|
||||
keys = keys_debouncing;
|
||||
debouncing = false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void print_keys(DEVTERM*dv) {
|
||||
char buff[128];
|
||||
|
||||
for (int i = 0; i < KEYS_NUM; i++) {
|
||||
if( keys & (1<< i) ){
|
||||
sprintf(buff,"B%d pressed\n",i+1);
|
||||
dv->_Serial->print(buff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void keys_task(DEVTERM*dv){
|
||||
|
||||
uint16_t _change = 0;
|
||||
|
||||
scan_keys();
|
||||
|
||||
uint16_t _mask =1;
|
||||
for(uint8_t c=0;c < KEYS_NUM;c++,_mask <<=1){
|
||||
|
||||
if( (keys_prev & _mask) == 0 && (keys & _mask) > 0){
|
||||
keypad_action(dv,c,KEY_PRESSED);
|
||||
}
|
||||
if( (keys_prev & _mask) > 0 && (keys & _mask) == 0){
|
||||
keypad_action(dv,c,KEY_RELEASED);
|
||||
}
|
||||
|
||||
if( (keys_prev & _mask) > 0 && (keys & _mask) > 0) { ////same key
|
||||
|
||||
if( c >= 0 && c < 4) {// only allow B1-B4
|
||||
if( keys_jack_idx == -1){
|
||||
keys_jack_idx = c;
|
||||
}else{
|
||||
if(keys_jack_idx != c) {
|
||||
keys_jack_time = 0;
|
||||
keys_jack_idx = c;
|
||||
}else{
|
||||
keys_jack_time +=1;
|
||||
if( keys_jack_time % (KEY_DEBOUNCE*20) == 0){
|
||||
keypad_action(dv,c,KEY_PRESSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
keys_prev = keys;
|
||||
|
||||
}
|
||||
|
||||
void keys_init(DEVTERM*dv){
|
||||
|
||||
init_keys();
|
||||
//center the position
|
||||
dv->Joystick->X(511);
|
||||
dv->Joystick->Y(511);
|
||||
|
||||
}
|
||||
49
Code/devterm_keyboard/keys_io_map.h
Normal file
49
Code/devterm_keyboard/keys_io_map.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef KEYS_IO_MAP_H
|
||||
#define KEYS_IO_MAP_H
|
||||
|
||||
#define ROW1 PA0
|
||||
#define ROW2 PA1
|
||||
#define ROW3 PA2
|
||||
#define ROW4 PA3
|
||||
#define ROW5 PA4
|
||||
#define ROW6 PA5
|
||||
#define ROW7 PA6
|
||||
#define ROW8 PA7
|
||||
|
||||
#define COL1 PC0
|
||||
#define COL2 PC1
|
||||
#define COL3 PC2
|
||||
#define COL4 PC3
|
||||
#define COL5 PC4
|
||||
#define COL6 PC5
|
||||
#define COL7 PC6
|
||||
#define COL8 PC7
|
||||
|
||||
#define KEY1 PB0 //
|
||||
#define KEY2 PB1
|
||||
#define KEY3 PB2
|
||||
#define KEY4 PB3
|
||||
#define KEY5 PB4
|
||||
#define KEY6 PB5
|
||||
#define KEY7 PB6
|
||||
#define KEY8 PB7
|
||||
#define KEY9 PB8
|
||||
#define KEY10 PB9
|
||||
#define KEY11 PB10
|
||||
#define KEY12 PB11
|
||||
#define KEY13 PB12
|
||||
#define KEY14 PB13
|
||||
#define KEY15 PB14
|
||||
#define KEY16 PB15 //
|
||||
|
||||
//ball
|
||||
#define HO1 PC8
|
||||
#define HO2 PC9
|
||||
#define HO3 PC10
|
||||
#define HO4 PC11
|
||||
#define KEY0 PC12
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
67
Code/devterm_keyboard/trackball.h
Normal file
67
Code/devterm_keyboard/trackball.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef TRACKBALL_H
|
||||
#define TRACKBALL_H
|
||||
|
||||
#include "devterm.h"
|
||||
|
||||
#include "keys_io_map.h"
|
||||
|
||||
#define BOUNCE_INTERVAL 30
|
||||
#define BASE_MOVE_PIXELS 5
|
||||
#define EXPONENTIAL_BOUND 15
|
||||
#define EXPONENTIAL_BASE 1.2
|
||||
|
||||
#define BTN_PIN KEY0
|
||||
#define RIGHT_PIN HO3
|
||||
#define LEFT_PIN HO1
|
||||
#define DOWN_PIN HO4
|
||||
#define UP_PIN HO2
|
||||
|
||||
|
||||
|
||||
class Direction {
|
||||
public:
|
||||
Direction(int pin1, int pin2) {
|
||||
this->pins[0] = pin1;
|
||||
this->pins[1] = pin2;
|
||||
pinMode(this->pins[0], INPUT);
|
||||
pinMode(this->pins[1], INPUT);
|
||||
};
|
||||
|
||||
int read_action() {
|
||||
for(int i = 0; i < 2; ++i) {
|
||||
this->current_actions[i] = digitalRead(this->pins[i]);
|
||||
this->current_action_times[i] = millis();
|
||||
if(this->current_actions[i] != this->last_actions[i]) {
|
||||
this->last_actions[i] = this->current_actions[i];
|
||||
exponential = (EXPONENTIAL_BOUND - (this->current_action_times[i] - this->last_action_times[i]));
|
||||
exponential = (exponential > 0) ? exponential : 1;
|
||||
move_multiply = EXPONENTIAL_BASE;
|
||||
for(int i = 0; i < exponential; ++i) {
|
||||
move_multiply *= EXPONENTIAL_BASE;
|
||||
}
|
||||
this->last_action_times[i] = this->current_action_times[i];
|
||||
if(i == 0) {
|
||||
return (-1) * BASE_MOVE_PIXELS * move_multiply;
|
||||
} else {
|
||||
return BASE_MOVE_PIXELS * move_multiply;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
private:
|
||||
int pins[2];
|
||||
int current_actions[2];
|
||||
int last_actions[2];
|
||||
int exponential;
|
||||
double move_multiply;
|
||||
unsigned long current_action_times[2];
|
||||
unsigned long last_action_times[2];
|
||||
};
|
||||
|
||||
void trackball_init(DEVTERM*);
|
||||
void trackball_task(DEVTERM*);
|
||||
|
||||
|
||||
#endif
|
||||
53
Code/devterm_keyboard/trackball.ino
Normal file
53
Code/devterm_keyboard/trackball.ino
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* clockworkpi devterm trackball
|
||||
*/
|
||||
#include "keys_io_map.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <USBComposite.h>
|
||||
|
||||
#include "trackball.h"
|
||||
|
||||
|
||||
int btn_state;
|
||||
int btn_read_state;
|
||||
unsigned long btn_current_action_time;
|
||||
unsigned long btn_last_action_time;
|
||||
|
||||
// mouse move
|
||||
int x_move, y_move;
|
||||
Direction x_direction(LEFT_PIN, RIGHT_PIN);
|
||||
Direction y_direction(UP_PIN, DOWN_PIN);
|
||||
|
||||
void trackball_task(DEVTERM*dv) {
|
||||
btn_read_state = digitalRead(BTN_PIN);
|
||||
|
||||
if(btn_read_state != btn_state) {
|
||||
btn_current_action_time = millis();
|
||||
if(btn_current_action_time - btn_last_action_time > BOUNCE_INTERVAL) {
|
||||
btn_state = btn_read_state;
|
||||
btn_last_action_time = btn_current_action_time;
|
||||
|
||||
if(btn_state == HIGH) {
|
||||
dv->Mouse->release();
|
||||
} else {
|
||||
dv->Mouse->press();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
x_move = x_direction.read_action();
|
||||
y_move = y_direction.read_action();
|
||||
if(x_move != 0 || y_move != 0) {
|
||||
dv->Mouse->move(x_move, y_move, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void trackball_init(DEVTERM*){
|
||||
pinMode(BTN_PIN,INPUT);
|
||||
}
|
||||
27
Code/thermal_printer/Makefile
Normal file
27
Code/thermal_printer/Makefile
Normal file
@ -0,0 +1,27 @@
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -g -Wall
|
||||
LDFLAUS =
|
||||
INCLUDES =
|
||||
LIBS = -lwiringPi
|
||||
|
||||
MAIN = devterm_thermal_printer.elf
|
||||
|
||||
SRCS = printer.c devterm_thermal_printer.c utils.c
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
.PHONY: depend clean
|
||||
|
||||
all: $(MAIN)
|
||||
@echo compile $(MAIN)
|
||||
|
||||
$(MAIN): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) *.o *~ $(MAIN)
|
||||
|
||||
|
||||
59
Code/thermal_printer/cmd.h
Normal file
59
Code/thermal_printer/cmd.h
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef CMD_H
|
||||
#define CMD_H
|
||||
|
||||
/*
|
||||
|
||||
ESC 2
|
||||
设置行间距为 32 点
|
||||
|
||||
ESC @
|
||||
ESC@命令初始化打印机
|
||||
|
||||
ESC j n
|
||||
打印缓冲区数据并走纸 n 点行
|
||||
|
||||
ESC d n
|
||||
打印缓冲区数据并走纸 n 行
|
||||
|
||||
ESC ! n
|
||||
设置打印字体,n为 0-4
|
||||
|
||||
ESC 3 n
|
||||
设置行间距为 n 点行
|
||||
|
||||
ESC v n
|
||||
向主机传送打印机状态
|
||||
|
||||
ESC a n
|
||||
设置对齐方式,左对齐0,右对齐2,居中对齐1
|
||||
|
||||
ESC - n
|
||||
设置下划线的点高度,n为0-2
|
||||
|
||||
ESC SP n
|
||||
设置字符间距n个点
|
||||
|
||||
DC2 # n
|
||||
n 为打印浓度代码:0-F
|
||||
GS L nL nH
|
||||
|
||||
GS v 0 p wL wH hL hH d1…dk
|
||||
位图打印
|
||||
p: 打印位图格式为0
|
||||
W=wL+wH*256 表示水平宽度字节数
|
||||
H=hL+hH*256 表示垂直高度点数
|
||||
位图使用 MSB 格式,最高位在打印位置的左边,先送的数据在打印位置 的左边。
|
||||
|
||||
LF
|
||||
打印行缓冲器里的内容并向前走纸一行
|
||||
|
||||
DC2 T
|
||||
打印测试页
|
||||
|
||||
GS V \0 or GS V \1
|
||||
切纸,打印一行分割示意条 ,=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif
|
||||
224
Code/thermal_printer/config.h
Normal file
224
Code/thermal_printer/config.h
Normal file
@ -0,0 +1,224 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
///raspberry pi CM3
|
||||
|
||||
#define BCM_GPIO_28 28
|
||||
#define BCM_GPIO_29 29
|
||||
#define BCM_GPIO_30 30
|
||||
#define BCM_GPIO_31 31
|
||||
#define BCM_GPIO_32 32
|
||||
#define BCM_GPIO_33 33
|
||||
#define BCM_GPIO_34 34
|
||||
#define BCM_GPIO_35 35
|
||||
#define BCM_GPIO_36 36
|
||||
#define BCM_GPIO_37 37
|
||||
#define BCM_GPIO_38 38
|
||||
#define BCM_GPIO_39 39
|
||||
#define BCM_GPIO_40 40
|
||||
#define BCM_GPIO_41 41
|
||||
#define BCM_GPIO_42 42
|
||||
#define BCM_GPIO_43 43
|
||||
#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
|
||||
|
||||
#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 PEM_CTL_PIN BCM_GPIO_32 //3 VPS
|
||||
#define ENABLE_PEM digitalWrite(PEM_CTL_PIN,HIGH)
|
||||
#define DISABLE_PEM digitalWrite(PEM_CTL_PIN,LOW)
|
||||
*/
|
||||
//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
|
||||
// dtparam=spi=on
|
||||
// dtoverlay=spi-gpio35-39
|
||||
// then we can see GPIO38 GPIO39 in ALT0 Mode by `gpio readall`
|
||||
|
||||
#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
|
||||
|
||||
|
||||
#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 //
|
||||
#define PNA_PIN PH2_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 MOTOR_ENABLE1
|
||||
#define MOTOR_ENABLE2
|
||||
|
||||
#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 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 HOT 64
|
||||
|
||||
#define BCoefficent 3950
|
||||
#define RthNominal 30000
|
||||
#define TempNominal 25
|
||||
#define ADCResolution 4096
|
||||
#define SeriesResistor 30000
|
||||
|
||||
#define NumSamples 10
|
||||
|
||||
#define KELVIN 1
|
||||
#define CELSIUS 0
|
||||
|
||||
#define HEAT_TIME 300 // heat time,better not greater than 1000,300-1000 0-f
|
||||
|
||||
#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 Maxdotsperline ((uint16_t)384)
|
||||
#define nextcharactercolum ((uint8_t)Fontrows/8) // = 3
|
||||
#define Maxcharacterperline ((uint16_t)Maxdotsperline/FontColums) // 384/16=24
|
||||
|
||||
|
||||
|
||||
#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 PRINT_STATE 0
|
||||
#define ESC_STATE 1
|
||||
#define GET_IMAGE 2
|
||||
|
||||
|
||||
#define ALIGN_LEFT 0
|
||||
#define ALIGN_CENTER 1
|
||||
#define ALIGN_RIGHT 2
|
||||
|
||||
#define MAX_DOTS 384
|
||||
#define IMAGE_MAX 9224
|
||||
|
||||
#define BITS8 8
|
||||
#define PRINTER_BITS 384
|
||||
#define MAXPIXELS 48
|
||||
|
||||
//extract bits
|
||||
#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
|
||||
uint8_t height;
|
||||
const uint8_t *data;
|
||||
}FONT;
|
||||
|
||||
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 cache[IMAGE_MAX]; // 48x192bytes(384x192 pixels) ,max
|
||||
|
||||
}ImageCache;
|
||||
|
||||
typedef struct _CONFIG
|
||||
{
|
||||
uint8_t state;
|
||||
uint8_t line_space;
|
||||
uint8_t align;
|
||||
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
|
||||
|
||||
uint16_t wordgap:10;//1023 max
|
||||
|
||||
Margin margin;
|
||||
FONT*font;
|
||||
ImageCache *img;
|
||||
}CONFIG;
|
||||
|
||||
|
||||
typedef struct _SerialCache{
|
||||
uint8_t idx;
|
||||
uint8_t data[77];//384/5
|
||||
}SerialCache;
|
||||
|
||||
void PrintDots8bit(uint8_t *Array, uint8_t characters,uint8_t feed_num);
|
||||
|
||||
uint8_t invert_bit(uint8_t a);
|
||||
|
||||
#endif
|
||||
704
Code/thermal_printer/devterm_thermal_printer.c
Normal file
704
Code/thermal_printer/devterm_thermal_printer.c
Normal file
@ -0,0 +1,704 @@
|
||||
// for ltp02-245
|
||||
// 203 dpi, 384dots in 48mm(1.88976inch) every dots == 0.125mm, 1byte==8dots==1mm
|
||||
// make clean && make && ./stm32duino_thermal_printer.bin
|
||||
//#include <SPI.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
#include "logo.h"
|
||||
|
||||
#include "pcf_5x7-ISO8859-1_5x7.h"
|
||||
#include "pcf_6x12-ISO8859-1_6x12.h"
|
||||
#include "pcf_7x14-ISO8859-1_7x14.h"
|
||||
|
||||
|
||||
#include "ttf_Px437_PS2thin1_8x16.h"
|
||||
#include "ttf_Px437_PS2thin2_8x16.h"
|
||||
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
#include "printer.h"
|
||||
|
||||
SerialCache ser_cache;
|
||||
|
||||
uint8_t cmd[10];
|
||||
uint8_t cmd_idx;
|
||||
|
||||
uint8_t newline;
|
||||
char buf[2];
|
||||
|
||||
unsigned long time;
|
||||
|
||||
ImageCache img_cache;
|
||||
|
||||
FONT current_font;
|
||||
|
||||
CONFIG g_config;
|
||||
|
||||
|
||||
//void printer_set_font(CONFIG*cfg,uint8_t fnbits);
|
||||
//void parse_serial_stream(CONFIG*cfg,uint8_t input_ch);
|
||||
|
||||
void reset_cmd(){
|
||||
cmd_idx = 0;
|
||||
ser_cache.idx=0;
|
||||
g_config.state = PRINT_STATE;
|
||||
}
|
||||
|
||||
void init_printer(){
|
||||
|
||||
memset(cmd,0,10);
|
||||
|
||||
newline = 0;
|
||||
cmd_idx = 0;
|
||||
|
||||
img_cache.idx=0;
|
||||
img_cache.num=0;
|
||||
img_cache.width=0;
|
||||
|
||||
img_cache.need_print=0;
|
||||
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=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_PS2thin1_8x16;
|
||||
|
||||
|
||||
ser_cache.idx=0;
|
||||
|
||||
g_config.line_space=0;
|
||||
g_config.align = ALIGN_LEFT;
|
||||
g_config.reverse = 0;
|
||||
|
||||
g_config.margin.width = 0;
|
||||
g_config.margin.esgs = 0;
|
||||
|
||||
g_config.orient = FORWARD;
|
||||
|
||||
g_config.wordgap = 0;
|
||||
|
||||
g_config.font = ¤t_font;
|
||||
|
||||
g_config.under_line = 0;
|
||||
|
||||
g_config.state = PRINT_STATE;
|
||||
|
||||
g_config.img = &img_cache;
|
||||
g_config.density = 0;
|
||||
|
||||
g_config.feed_pitch = 2;
|
||||
|
||||
}
|
||||
|
||||
const char url[] ={"Powered by clockworkpi.com"};
|
||||
|
||||
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
|
||||
sprintf(buf,"%0.2f%s",m,last);
|
||||
|
||||
j = strlen(buf);
|
||||
i = 48-strlen(label)-j-1;
|
||||
|
||||
if(m == -1.0)
|
||||
sprintf(buf,"%s%*s%s",label,i,"",last);
|
||||
else
|
||||
sprintf(buf,"%s%*s%0.2f%s",label,i,"",m,last);
|
||||
|
||||
|
||||
printer_set_font(cfg,4);
|
||||
reset_cmd();
|
||||
|
||||
for(i=0;i<strlen(buf);i++){
|
||||
parse_serial_stream(cfg,buf[i]);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
reset_cmd();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void label_print_i(CONFIG*cfg,char*label,int m,char*last){
|
||||
char buf[48];
|
||||
uint8_t i,j;
|
||||
|
||||
if(m == -1)
|
||||
sprintf(buf,"%s",last);
|
||||
else
|
||||
sprintf(buf,"%d%s",m,last);
|
||||
|
||||
j = strlen(buf);
|
||||
i = 48-strlen(label)-j-1;
|
||||
|
||||
if(m == -1)
|
||||
sprintf(buf,"%s%*s%s",label,i,"",last);
|
||||
else
|
||||
sprintf(buf,"%s%*s%d%s",label,i,"",m,last);
|
||||
|
||||
printer_set_font(cfg,4);
|
||||
reset_cmd();
|
||||
|
||||
for(i=0;i<strlen(buf);i++){
|
||||
parse_serial_stream(cfg,buf[i]);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
reset_cmd();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void printer_test(CONFIG*cfg){
|
||||
|
||||
uint8_t i,j;
|
||||
uint8_t ch;
|
||||
uint16_t k;
|
||||
|
||||
char buf[48];
|
||||
char *font_names[]={"8x16thin_1","5x7_ISO8859_1","6x12_ISO8859_1","7x14_ISO8859_1","8x16thin_2",NULL};
|
||||
|
||||
/*
|
||||
char *selftest1[] = {
|
||||
" _ __ _ _ ",
|
||||
" ___ ___| |/ _| | |_ ___ ___| |_ ",
|
||||
"/ __|/ _ \\ | |_ | __/ _ \\/ __| __|",
|
||||
"\\__ \\ __/ | _| | || __/\\__ \\ |_ ",
|
||||
"|___/\\___|_|_| \\__\\___||___/\\__|",
|
||||
NULL
|
||||
};
|
||||
*/
|
||||
char *selftest2[] = {
|
||||
" #### ###### # ###### ##### ###### #### #####",
|
||||
"# # # # # # # # ",
|
||||
" #### ##### # ##### # ##### #### # ",
|
||||
" # # # # # # # # ",
|
||||
"# # # # # # # # # # ",
|
||||
" #### ###### ###### # # ###### #### # ",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
cfg->density = 4;
|
||||
|
||||
k = (os120_width/8)*os120_height;
|
||||
memcpy(cfg->img->cache,os120_bits,k);
|
||||
cfg->img->width = os120_width/8;
|
||||
cfg->img->num = k;
|
||||
cfg->img->revert_bits=1;
|
||||
cfg->align = ALIGN_CENTER;
|
||||
print_image8(cfg);
|
||||
|
||||
cfg->img->revert_bits=0;
|
||||
cfg->align = ALIGN_LEFT;
|
||||
feed_pitch1(15,cfg->orient);
|
||||
|
||||
cfg->align = ALIGN_CENTER;
|
||||
/* //selftest1
|
||||
for(i=0;i<5;i++){
|
||||
printer_set_font(cfg,0);
|
||||
reset_cmd();
|
||||
for(j=0;j<strlen(selftest1[i]);j++){
|
||||
parse_serial_stream(cfg,selftest1[i][j]);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
}
|
||||
*/
|
||||
|
||||
for(i=0;i<6;i++){
|
||||
printer_set_font(cfg,1);
|
||||
reset_cmd();
|
||||
|
||||
for(j=0;j<strlen(selftest2[i]);j++){
|
||||
parse_serial_stream(cfg,selftest2[i][j]);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
}
|
||||
cfg->align = ALIGN_LEFT;
|
||||
|
||||
feed_pitch1(32,cfg->orient);
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
for(i=1;i<4;i++){
|
||||
printer_set_font(cfg,0);
|
||||
reset_cmd();
|
||||
for(j=0;j<strlen(font_names[i]);j++){
|
||||
|
||||
parse_serial_stream(cfg,font_names[i][j]);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
|
||||
printer_set_font(cfg,i);
|
||||
reset_cmd();
|
||||
for(ch = 33;ch<127;ch++){
|
||||
parse_serial_stream(cfg,ch);
|
||||
//Serial.print(ch,DEC);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
//Serial.println();
|
||||
feed_pitch1(48,cfg->orient);
|
||||
}
|
||||
|
||||
|
||||
printer_set_font(cfg,0);
|
||||
reset_cmd();
|
||||
for(j=0;j<strlen(font_names[0]);j++){
|
||||
parse_serial_stream(cfg,font_names[0][j]);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
|
||||
printer_set_font(cfg,0);
|
||||
reset_cmd();
|
||||
for(ch = 33;ch<127;ch++){
|
||||
parse_serial_stream(cfg,ch);
|
||||
//Serial.print(ch,DEC);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
//Serial.println();
|
||||
feed_pitch1(48,cfg->orient);
|
||||
|
||||
|
||||
printer_set_font(cfg,0);
|
||||
reset_cmd();
|
||||
for(j=0;j<strlen(font_names[0]);j++){
|
||||
parse_serial_stream(cfg,font_names[4][j]);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
|
||||
printer_set_font(cfg,4);
|
||||
reset_cmd();
|
||||
for(ch = 33;ch<127;ch++){
|
||||
parse_serial_stream(cfg,ch);
|
||||
//Serial.print(ch,DEC);
|
||||
}
|
||||
parse_serial_stream(cfg,10);
|
||||
//Serial.println();
|
||||
feed_pitch1(28,cfg->orient);
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
k = temperature();
|
||||
label_print_i(cfg,"Temperature:",k," C");
|
||||
//--------------------------------------------------------
|
||||
|
||||
label_print_i(cfg,"Darkness setting:",cfg->density," (Light 0-15 Dark)");
|
||||
|
||||
label_print_i(cfg,"Paper width:",-1,"58mm");
|
||||
label_print_i(cfg,"Print width:",-1,"48mm");
|
||||
|
||||
label_print_i(cfg,"Baudrate:",115200,"");
|
||||
label_print_i(cfg,"Data bits:",8,"");
|
||||
label_print_i(cfg,"Stop bits:",1,"");
|
||||
//------------------------------------------
|
||||
|
||||
//------------------------------------------
|
||||
label_print_f(cfg,"Firmware version:",0.1,"");
|
||||
|
||||
feed_pitch1(cfg->font->height,cfg->orient);
|
||||
//--------------------------------------------------------------
|
||||
printer_set_font(cfg,0);
|
||||
reset_cmd();
|
||||
|
||||
//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
|
||||
|
||||
for(ch = 0;ch <16;ch++){
|
||||
if(ch%2==0)
|
||||
j = 0xff;
|
||||
else
|
||||
j = 0x00;
|
||||
|
||||
for(k=0;k<8;k++){
|
||||
for(i=0;i<48;i++){
|
||||
if(i % 2==0) {
|
||||
buf[i]=j;
|
||||
}else{
|
||||
buf[i]=0xff-j;
|
||||
}
|
||||
}
|
||||
print_dots_8bit_split(cfg,(uint8_t*)buf,48);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
feed_pitch1(cfg->font->height*2,cfg->orient);
|
||||
|
||||
}
|
||||
|
||||
void printer_set_font(CONFIG*cfg,uint8_t fnbits){
|
||||
uint8_t ret;
|
||||
ret = MID(fnbits,0,3);
|
||||
|
||||
if(ret==0) {
|
||||
cfg->font->width = 8 ;
|
||||
cfg->font->height = 16;
|
||||
cfg->font->data = font_ttf_Px437_PS2thin1_8x16;
|
||||
}
|
||||
|
||||
if(ret==1){
|
||||
cfg->font->width = 5;
|
||||
cfg->font->height = 7;
|
||||
cfg->font->data = font_pcf_5x7_ISO8859_1_5x7;
|
||||
}
|
||||
|
||||
if(ret==2){
|
||||
cfg->font->width = 6;
|
||||
cfg->font->height = 12;
|
||||
cfg->font->data = font_pcf_6x12_ISO8859_1_6x12;
|
||||
}
|
||||
|
||||
if(ret==3){
|
||||
cfg->font->width = 7;
|
||||
cfg->font->height = 14;
|
||||
cfg->font->data = font_pcf_7x14_ISO8859_1_7x14;
|
||||
}
|
||||
|
||||
if(ret == 4){
|
||||
cfg->font->width = 8 ;
|
||||
cfg->font->height = 16;
|
||||
cfg->font->data = font_ttf_Px437_PS2thin2_8x16;
|
||||
}
|
||||
}
|
||||
|
||||
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){
|
||||
cfg->line_space = cfg->font->height+8;
|
||||
reset_cmd();
|
||||
}
|
||||
|
||||
//ESC @
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(cmdidx > 2){
|
||||
//ESC j n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x4a){
|
||||
|
||||
print_lines8(cfg);
|
||||
feed_pitch1(cmd[2],BACKWARD);
|
||||
reset_cmd();
|
||||
}
|
||||
//ESC d n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x64){
|
||||
|
||||
print_lines8(cfg);
|
||||
|
||||
feed_pitch1(cmd[2]*cfg->font->height,BACKWARD);
|
||||
reset_cmd();
|
||||
}
|
||||
//ESC ! n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x21){
|
||||
printer_set_font(cfg,cmd[2]);
|
||||
reset_cmd();
|
||||
}
|
||||
|
||||
//ESC 3 n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x33){
|
||||
cfg->line_space = cmd[2];
|
||||
reset_cmd();
|
||||
}
|
||||
|
||||
// ESC v n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x76){
|
||||
if(temperature() > 70){
|
||||
ret |= 1 << 6;
|
||||
}
|
||||
if ( (IsPaper() & NO_PAPER) > 0 ) {
|
||||
ret |= 1 << 2;
|
||||
}
|
||||
|
||||
printf("%d",ret);
|
||||
reset_cmd();
|
||||
return;
|
||||
}
|
||||
//ESC a n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x61){
|
||||
ret = cmd[2];
|
||||
if(ret == 0 || ret == 48){
|
||||
cfg->align = ALIGN_LEFT;
|
||||
}
|
||||
if(ret == 1 || ret == 49){
|
||||
cfg->align = ALIGN_CENTER;
|
||||
}
|
||||
if(ret == 2 || ret == 50){
|
||||
cfg->align = ALIGN_RIGHT;
|
||||
}
|
||||
|
||||
reset_cmd();
|
||||
}
|
||||
//ESC - n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x2d){
|
||||
ret = cmd[2];
|
||||
if(ret == 0 || ret == 48){
|
||||
cfg->under_line =0;
|
||||
}
|
||||
if(ret == 1 || ret == 49){
|
||||
cfg->under_line = 1;
|
||||
}
|
||||
if(ret == 2 || ret == 50){
|
||||
cfg->under_line = 2;
|
||||
}
|
||||
|
||||
reset_cmd();
|
||||
|
||||
}
|
||||
|
||||
//ESC SP n
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x20){
|
||||
ret = cmd[2];
|
||||
if( ret + cfg->margin.width <MAX_DOTS){
|
||||
cfg->wordgap = ret;
|
||||
}
|
||||
reset_cmd();
|
||||
return;
|
||||
}
|
||||
|
||||
//DC2 # n
|
||||
if(cmd[0] == ASCII_DC2 && cmd[1] == 0x23){
|
||||
ret = cmd[2];
|
||||
cfg->density = ret;
|
||||
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
|
||||
|
||||
print_cut_line(cfg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(cmdidx > 3){
|
||||
//GS L nL nH
|
||||
if(cmd[0] == ASCII_GS && cmd[1] == 0x4c){
|
||||
uint16_t k;
|
||||
k = cmd[2]+cmd[3]*256;
|
||||
if (k < MAX_DOTS - cfg->font->width){
|
||||
cfg->margin.width = k;
|
||||
}
|
||||
|
||||
reset_cmd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(cmdidx > 4){
|
||||
/*
|
||||
if(cmd[0] == ASCII_ESC && cmd[1] == 0x2a){
|
||||
if( cmd[2] == 0 || cmd[2] == 1){
|
||||
uint16_t k;
|
||||
k = cmd[3] + 256*cmd[4];
|
||||
if(k<= IMAGE_MAX){
|
||||
cfg->state = GET_IMAGE;
|
||||
cfg->img->num = k;
|
||||
cfg->img->idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
reset_cmd();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if(cmdidx > 7){
|
||||
// GS v 0 p wL wH hL hH d1…dk
|
||||
if(cmd[0] == ASCII_GS && cmd[1] == 118 && cmd[2] == 48 ) {
|
||||
uint16_t width = cmd[4] + cmd[5]*256;
|
||||
uint16_t height = cmd[6]+cmd[7]*256;
|
||||
uint16_t k;
|
||||
k = width * height;
|
||||
if(k<= IMAGE_MAX){
|
||||
cfg->state = GET_IMAGE;
|
||||
cfg->img->num = k;
|
||||
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){
|
||||
uint16_t a;
|
||||
|
||||
if(cfg->state == GET_IMAGE){
|
||||
cfg->img->cache[cfg->img->idx] = input_ch;
|
||||
cfg->img->idx++;
|
||||
if(cfg->img->idx >= cfg->img->num){//image full
|
||||
if(cfg->img->need_print==1){
|
||||
print_image8(cfg);
|
||||
}
|
||||
reset_cmd();
|
||||
cfg->state = PRINT_STATE;
|
||||
}
|
||||
}else if(cfg->state == ESC_STATE) {
|
||||
cmd[cmd_idx] = input_ch;
|
||||
cmd_idx++;
|
||||
if(cmd_idx < 10){
|
||||
parse_cmd(cfg,cmd,cmd_idx);
|
||||
}else{
|
||||
reset_cmd();
|
||||
}
|
||||
}else{ //PRINT_STATE
|
||||
switch(input_ch){
|
||||
case ASCII_LF:
|
||||
if(ser_cache.idx == 0){
|
||||
feed_pitch1(cfg->font->height,cfg->orient);
|
||||
}
|
||||
print_lines8(cfg);
|
||||
reset_cmd();
|
||||
break;
|
||||
case ASCII_FF:
|
||||
print_lines8(cfg);
|
||||
reset_cmd();
|
||||
break;
|
||||
case ASCII_DC2:
|
||||
cmd[cmd_idx] = input_ch;
|
||||
cfg->state = ESC_STATE;
|
||||
cmd_idx++;
|
||||
break;
|
||||
case ASCII_GS:
|
||||
cmd[cmd_idx] = input_ch;
|
||||
cfg->state = ESC_STATE;
|
||||
cmd_idx++;
|
||||
break;
|
||||
case ASCII_ESC:
|
||||
cmd[cmd_idx] = input_ch;
|
||||
cfg->state = ESC_STATE;
|
||||
cmd_idx++;
|
||||
break;
|
||||
default:
|
||||
ser_cache.data[ser_cache.idx]=input_ch;
|
||||
ser_cache.idx++;
|
||||
|
||||
a = (ser_cache.idx+1)*current_font.width+(ser_cache.idx)*0+ g_config.margin.width;
|
||||
if( a >= MAX_DOTS)
|
||||
{
|
||||
print_lines8(cfg);
|
||||
reset_cmd();
|
||||
}
|
||||
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
|
||||
*/
|
||||
|
||||
#define FIFO_FILE "/tmp/DEVTERM_PRINTER_OUT"
|
||||
|
||||
void loop() {
|
||||
|
||||
/*
|
||||
if (Serial.available() > 0) {
|
||||
// read the incoming byte
|
||||
Serial.readBytes(buf,1);
|
||||
parse_serial_stream(&g_config,buf[0]);
|
||||
}
|
||||
*/
|
||||
|
||||
int fp;
|
||||
char readbuf[2];
|
||||
|
||||
while(1) {
|
||||
fp = -1;
|
||||
fp = open(FIFO_FILE, O_RDONLY, 0666);
|
||||
if (fp != -1) {
|
||||
while(1)
|
||||
{
|
||||
read(fp,readbuf, 1);
|
||||
//printf("read %x",readbuf[0]);
|
||||
parse_serial_stream(&g_config,readbuf[0]);
|
||||
}
|
||||
close(fp);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//------------------------------------------
|
||||
//printer_test(&g_config);
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
wiringPiSetupGpio();
|
||||
header_init();
|
||||
header_init1();
|
||||
|
||||
clear_printer_buffer();
|
||||
|
||||
//Serial.begin(115200);
|
||||
|
||||
init_printer();
|
||||
|
||||
}
|
||||
|
||||
int main(int argc,char**argv) {
|
||||
|
||||
|
||||
setup();
|
||||
loop();
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=devterm printer main process
|
||||
After=devterm-socat
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/devterm_thermal_printer.elf
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=socat as virtual serial port
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=socat -d -d pty,link=/tmp/DEVTERM_PRINTER_OUT,raw,echo=0 pty,link=/tmp/DEVTERM_PRINTER_IN,raw,echo=0
|
||||
ExecStartPost=/usr/local/bin/devterm_socat.sh
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
160
Code/thermal_printer/logo.h
Normal file
160
Code/thermal_printer/logo.h
Normal file
@ -0,0 +1,160 @@
|
||||
#ifndef LOGO_H
|
||||
#define LOGO_H
|
||||
|
||||
#define os120_width 120
|
||||
#define os120_height 120
|
||||
|
||||
const unsigned char os120_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x1f,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
|
||||
0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
|
||||
0x1f, 0x00, 0xf8, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x80, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x01, 0x00, 0x00, 0x00,
|
||||
0x80, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0xf8, 0x01, 0x00, 0xc0, 0x7f,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0xf0, 0xff, 0xff,
|
||||
0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0x07, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0xe0,
|
||||
0x1f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xf8, 0x07, 0x00, 0x00,
|
||||
0x00, 0x00, 0xf0, 0x0f, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf0,
|
||||
0x0f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00, 0xfe, 0xff, 0xff, 0xff,
|
||||
0xff, 0x01, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0x07, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xfe,
|
||||
0x00, 0xc0, 0xff, 0xff, 0xff, 0x7f, 0xfc, 0x0f, 0x00, 0x7f, 0x00, 0x00,
|
||||
0x00, 0x00, 0x7f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x3f, 0xf0, 0x1f, 0x00,
|
||||
0xfe, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x3f,
|
||||
0xe0, 0x3f, 0x00, 0xfc, 0x01, 0x00, 0x00, 0xc0, 0x1f, 0x00, 0xf8, 0xff,
|
||||
0xff, 0xff, 0x7f, 0x80, 0x7f, 0x00, 0xf8, 0x03, 0x00, 0x00, 0xe0, 0x0f,
|
||||
0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x01, 0x7f, 0x00, 0xf0, 0x07, 0x00,
|
||||
0x00, 0xe0, 0x07, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x07, 0xfe, 0x00,
|
||||
0xe0, 0x07, 0x00, 0x00, 0xf0, 0x03, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff,
|
||||
0x0f, 0xfc, 0x01, 0xc0, 0x0f, 0x00, 0x00, 0xf8, 0x03, 0x00, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0x1f, 0xfc, 0x01, 0xc0, 0x1f, 0x00, 0x00, 0xfc, 0x01,
|
||||
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xf8, 0x03, 0x80, 0x3f, 0x00,
|
||||
0x00, 0xfc, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf0, 0x07,
|
||||
0x00, 0x3f, 0x00, 0x00, 0x7e, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xf0, 0x07, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0xc0, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xf0, 0x07, 0x00, 0x7e, 0x00, 0x00, 0x3f, 0x00,
|
||||
0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0x0f, 0x00, 0xfc, 0x00,
|
||||
0x00, 0x3f, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f,
|
||||
0x00, 0xfc, 0x00, 0x80, 0x1f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xef, 0x1f, 0x00, 0xf8, 0x01, 0x80, 0x0f, 0x00, 0xe0, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xc7, 0x1f, 0x00, 0xf0, 0x01, 0xc0, 0x0f, 0x00,
|
||||
0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x1f, 0x00, 0xf0, 0x03,
|
||||
0xc0, 0x07, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7, 0x3f,
|
||||
0x00, 0xe0, 0x03, 0xe0, 0x07, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xef, 0x3f, 0x00, 0xe0, 0x07, 0xe0, 0x03, 0x00, 0xf0, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xc0, 0x07, 0xf0, 0x03, 0x00,
|
||||
0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xc0, 0x0f,
|
||||
0xf0, 0x03, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f,
|
||||
0x00, 0xc0, 0x0f, 0xf0, 0x01, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0x7f, 0x00, 0x80, 0x0f, 0xf8, 0x01, 0x00, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x80, 0x1f, 0xf8, 0x01, 0xc0,
|
||||
0x0f, 0xfc, 0xff, 0xff, 0x07, 0x3e, 0x80, 0xff, 0x7f, 0x00, 0x80, 0x1f,
|
||||
0xf8, 0x00, 0xe0, 0x03, 0xf0, 0xff, 0xff, 0x01, 0xf0, 0x00, 0xfc, 0x7f,
|
||||
0x00, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x00, 0xc0, 0xf1, 0x7f, 0x00, 0xe0,
|
||||
0x01, 0xf0, 0x7f, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x70, 0xf8, 0x83, 0x03,
|
||||
0x3f, 0xf8, 0xc1, 0x03, 0xc0, 0x7f, 0x00, 0x00, 0x3f, 0x7c, 0x00, 0x38,
|
||||
0xfc, 0x07, 0x07, 0x1c, 0xfe, 0x87, 0x03, 0x80, 0x7f, 0x00, 0x00, 0x3e,
|
||||
0x7c, 0x00, 0x38, 0xfe, 0x0f, 0x07, 0x1c, 0xff, 0x0f, 0x07, 0x00, 0xff,
|
||||
0x00, 0x00, 0x3e, 0x7c, 0x00, 0x1c, 0xf7, 0x1f, 0x0e, 0x0e, 0xfb, 0x1f,
|
||||
0x07, 0x00, 0xff, 0x00, 0x00, 0x3e, 0x7c, 0x00, 0x1c, 0xf3, 0x3f, 0x0e,
|
||||
0x8e, 0xf1, 0x1f, 0x0e, 0x00, 0xfe, 0x00, 0x00, 0x3e, 0x7e, 0x00, 0x8c,
|
||||
0xf3, 0x3f, 0x0c, 0x86, 0xf9, 0x3f, 0x1e, 0x00, 0xfe, 0x00, 0x00, 0x7e,
|
||||
0x7e, 0x00, 0x8c, 0xf9, 0x7f, 0x1c, 0x87, 0xf9, 0x3f, 0xfc, 0xff, 0xff,
|
||||
0x01, 0x00, 0x7e, 0x3e, 0x00, 0x8e, 0xf9, 0x7f, 0x1c, 0xc7, 0xf8, 0x3f,
|
||||
0xfc, 0xff, 0x9f, 0x01, 0x00, 0x7c, 0x3e, 0x00, 0x8e, 0xf9, 0x7f, 0x1c,
|
||||
0xc7, 0xfc, 0x7f, 0x0c, 0x00, 0x80, 0x01, 0x00, 0x7c, 0x3e, 0x00, 0x8e,
|
||||
0xf9, 0x7f, 0x1c, 0xc7, 0xfc, 0x7f, 0x0c, 0x00, 0x80, 0x03, 0x00, 0x7c,
|
||||
0x3e, 0x00, 0x8e, 0xf9, 0x7f, 0x1c, 0xc7, 0xf8, 0x7f, 0x0c, 0x00, 0x80,
|
||||
0x03, 0x00, 0x7c, 0x3e, 0x00, 0x8c, 0xf1, 0x7f, 0x1c, 0x87, 0xf9, 0x7f,
|
||||
0x0c, 0x00, 0x80, 0x01, 0x00, 0x7c, 0x3e, 0x00, 0x8c, 0xf3, 0x7f, 0x1c,
|
||||
0x86, 0xf9, 0x3f, 0x0c, 0x00, 0xc0, 0x01, 0x00, 0x7c, 0x3e, 0x00, 0x1c,
|
||||
0xe3, 0x7f, 0x1c, 0x8e, 0xf1, 0x3f, 0x0c, 0x00, 0xfe, 0x00, 0x00, 0x7c,
|
||||
0x3e, 0x00, 0x1c, 0xc7, 0x3f, 0x0c, 0x0e, 0xe3, 0x3f, 0xfe, 0xff, 0xff,
|
||||
0x00, 0x00, 0x7c, 0x3e, 0x00, 0x38, 0xc6, 0x3f, 0x0e, 0x1e, 0xc6, 0x1f,
|
||||
0xfe, 0x9f, 0xff, 0x00, 0x00, 0x7c, 0x3e, 0x00, 0x38, 0xfc, 0x1f, 0x0e,
|
||||
0x1f, 0xce, 0x1f, 0x07, 0xc0, 0xff, 0x00, 0x00, 0x7c, 0x3e, 0x00, 0x70,
|
||||
0xf8, 0x0f, 0xc7, 0x3f, 0xf8, 0x8f, 0x07, 0xf0, 0xff, 0x00, 0x00, 0x7c,
|
||||
0x3e, 0x00, 0xf0, 0xf0, 0x87, 0xf3, 0x7f, 0xf0, 0x83, 0x03, 0xfc, 0xff,
|
||||
0x00, 0x00, 0x7c, 0x3e, 0x00, 0xe0, 0x01, 0xc0, 0xff, 0xff, 0x00, 0xe0,
|
||||
0x01, 0xff, 0xff, 0x00, 0x00, 0x7c, 0x3e, 0x00, 0xc0, 0x03, 0xe0, 0xff,
|
||||
0xff, 0x03, 0xf0, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x7c, 0x7e, 0x00, 0x80,
|
||||
0x1f, 0xfc, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7e,
|
||||
0x7e, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0x7e, 0x7c, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x0f, 0xfe, 0xff,
|
||||
0xff, 0xff, 0xff, 0x00, 0x00, 0x3e, 0x7c, 0x00, 0x00, 0xf0, 0xff, 0xff,
|
||||
0x01, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3e, 0x7c, 0x00, 0x00,
|
||||
0xf0, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3e,
|
||||
0x7c, 0x00, 0x00, 0xf0, 0xff, 0x3f, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0x3e, 0xfc, 0x00, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0xff,
|
||||
0xff, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x00, 0xf0, 0xff, 0x07,
|
||||
0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00,
|
||||
0xf0, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1f,
|
||||
0xf8, 0x01, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
|
||||
0x00, 0x80, 0x1f, 0xf8, 0x01, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00,
|
||||
0xfe, 0xff, 0xff, 0x01, 0x80, 0x1f, 0xf0, 0x01, 0x00, 0xf0, 0x1f, 0x00,
|
||||
0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x01, 0x80, 0x0f, 0xf0, 0x03, 0x00,
|
||||
0xf8, 0x0f, 0x01, 0x00, 0x00, 0x3c, 0xf8, 0xff, 0xff, 0x01, 0xc0, 0x0f,
|
||||
0xf0, 0x03, 0x00, 0xf8, 0x87, 0x07, 0x00, 0x80, 0x7f, 0xf8, 0xff, 0xff,
|
||||
0x01, 0xc0, 0x0f, 0xe0, 0x03, 0x00, 0xf8, 0xc7, 0x7f, 0x00, 0xf0, 0x7f,
|
||||
0xf8, 0xff, 0xff, 0x03, 0xc0, 0x07, 0xe0, 0x07, 0x00, 0xf8, 0x8f, 0xff,
|
||||
0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0x03, 0xe0, 0x07, 0xc0, 0x07, 0x00,
|
||||
0xfc, 0x0f, 0xff, 0xff, 0xff, 0x0f, 0xfc, 0xff, 0xff, 0x03, 0xe0, 0x03,
|
||||
0xc0, 0x0f, 0x00, 0xfc, 0x1f, 0xfc, 0xff, 0xff, 0x01, 0xfc, 0xff, 0xff,
|
||||
0x07, 0xf0, 0x03, 0x80, 0x0f, 0x00, 0xfc, 0x3f, 0xe0, 0xff, 0x3f, 0x00,
|
||||
0x3f, 0xff, 0xff, 0x07, 0xf0, 0x01, 0x80, 0x1f, 0x00, 0xfe, 0x7f, 0x00,
|
||||
0x00, 0x00, 0x80, 0x3f, 0xff, 0xff, 0x0f, 0xf8, 0x01, 0x00, 0x3f, 0x00,
|
||||
0xfe, 0xff, 0x01, 0x00, 0x00, 0xe0, 0x1f, 0xfe, 0xff, 0x0f, 0xfc, 0x00,
|
||||
0x00, 0x3f, 0x00, 0xfe, 0xf3, 0x03, 0x00, 0x00, 0xf8, 0x0f, 0xfe, 0xff,
|
||||
0x1f, 0xfc, 0x00, 0x00, 0x7e, 0x00, 0xff, 0xc3, 0x0f, 0x00, 0x00, 0xff,
|
||||
0x03, 0xfe, 0xff, 0x3f, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0xff, 0x83, 0x1f,
|
||||
0x00, 0x80, 0xff, 0x00, 0xfc, 0xff, 0x3f, 0x7e, 0x00, 0x00, 0xfc, 0x80,
|
||||
0xff, 0x03, 0x3e, 0x00, 0xe0, 0x3f, 0x00, 0xfc, 0xff, 0x7f, 0x3f, 0x00,
|
||||
0x00, 0xfc, 0x81, 0xff, 0x03, 0x7c, 0x00, 0xf0, 0x0f, 0x00, 0xfc, 0xff,
|
||||
0xff, 0x3f, 0x00, 0x00, 0xf8, 0xc3, 0xff, 0x01, 0xf8, 0x01, 0xfc, 0x03,
|
||||
0x00, 0xf8, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xf0, 0xe3, 0xff, 0x01, 0xf0,
|
||||
0xff, 0xff, 0x01, 0x00, 0xf8, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xe7,
|
||||
0xff, 0x01, 0xe0, 0xff, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x07, 0x00,
|
||||
0x00, 0xe0, 0xff, 0xff, 0x01, 0xc0, 0xff, 0x3f, 0x00, 0x00, 0xf0, 0xff,
|
||||
0xff, 0x07, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x01, 0x00, 0xff, 0x0f, 0x00,
|
||||
0x00, 0xf0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x80, 0xff, 0xff, 0x00, 0x00,
|
||||
0xf8, 0x01, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0xff,
|
||||
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x00, 0x00,
|
||||
0x00, 0x00, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
|
||||
0x7f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xe0, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xf0,
|
||||
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x0f, 0x00, 0x00,
|
||||
0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
|
||||
0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x01,
|
||||
0x00, 0x00, 0x00, 0x80, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x80, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x1f, 0x00, 0xf8,
|
||||
0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff,
|
||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xf8, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
|
||||
#endif
|
||||
2824
Code/thermal_printer/pcf_5x7-ISO8859-1_5x7.h
Normal file
2824
Code/thermal_printer/pcf_5x7-ISO8859-1_5x7.h
Normal file
File diff suppressed because it is too large
Load Diff
4104
Code/thermal_printer/pcf_6x12-ISO8859-1_6x12.h
Normal file
4104
Code/thermal_printer/pcf_6x12-ISO8859-1_6x12.h
Normal file
File diff suppressed because it is too large
Load Diff
4616
Code/thermal_printer/pcf_7x14-ISO8859-1_7x14.h
Normal file
4616
Code/thermal_printer/pcf_7x14-ISO8859-1_7x14.h
Normal file
File diff suppressed because it is too large
Load Diff
570
Code/thermal_printer/printer.c
Normal file
570
Code/thermal_printer/printer.c
Normal file
@ -0,0 +1,570 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringPiSPI.h>
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#include "printer.h"
|
||||
|
||||
extern FONT current_font;
|
||||
extern SerialCache ser_cache;
|
||||
|
||||
uint16_t STBx[] = {STB1_PIN,STB2_PIN,STB3_PIN,STB4_PIN,STB5_PIN,STB6_PIN};
|
||||
uint8_t as;
|
||||
|
||||
static unsigned int printer_vps_time;
|
||||
static uint8_t printer_vps_last_status;
|
||||
|
||||
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.
|
||||
//SPI.transfer16(w);
|
||||
digitalWrite(SPI1_NSS_PIN, HIGH); // manually take CSN high between spi transmissions
|
||||
*/
|
||||
wiringPiSPIDataRW (0, &w, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
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 status;
|
||||
uint8_t tmp;
|
||||
|
||||
if( millis() - printer_vps_time > 10) {
|
||||
ENABLE_PEM;
|
||||
if(ASK4PAPER==HIGH) // * temporary set,LOW is what we want**
|
||||
{status = IS_PAPER;}
|
||||
else
|
||||
{status = NO_PAPER;printf("Error:NO PAPER\n");}
|
||||
DISABLE_PEM;
|
||||
}else {
|
||||
status = printer_vps_last_status;
|
||||
}
|
||||
printer_vps_last_status = status;
|
||||
|
||||
tmp = temperature();
|
||||
if (tmp >= HOT){
|
||||
printf("Printer too Hot\n");
|
||||
status |= HOT_PRINTER;
|
||||
}
|
||||
|
||||
printer_vps_time = millis();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
uint8_t header_init() {
|
||||
|
||||
uint8_t pin[] = {THERMISTORPIN};
|
||||
|
||||
uint8_t x;
|
||||
pinMode(LATCH_PIN,OUTPUT);
|
||||
|
||||
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(PEM_PIN,INPUT);
|
||||
//pinMode(PEM_CTL_PIN,OUTPUT);
|
||||
|
||||
|
||||
//adc.setChannels(pin, 1); //this is actually the pin you want to measure
|
||||
|
||||
//pinMode(THERMISTORPIN,INPUT_ANALOG); // 数字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.
|
||||
*/
|
||||
if (!wiringPiSPISetup (0, 4500000 )) {
|
||||
printf("SPI init failed,exiting...\n");
|
||||
}
|
||||
|
||||
/*
|
||||
pinMode(SPI1_NSS_PIN, OUTPUT);
|
||||
digitalWrite(SPI1_NSS_PIN,HIGH);
|
||||
*/
|
||||
|
||||
printer_vps_time = 0;
|
||||
printer_vps_last_status = IS_PAPER;
|
||||
}
|
||||
|
||||
|
||||
#if 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);
|
||||
|
||||
as = 0;
|
||||
|
||||
return ASK4PAPER;
|
||||
}
|
||||
|
||||
void motor_stepper_pos2(uint8_t position)//forward
|
||||
{
|
||||
// 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);
|
||||
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 pos = current_pos;
|
||||
uint8_t restor = ~forward_backward;
|
||||
|
||||
restor &= 0x01;
|
||||
|
||||
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
|
||||
|
||||
lines--;
|
||||
}
|
||||
MOTOR_DISABLE1;
|
||||
MOTOR_DISABLE2;
|
||||
DISABLE_VH;
|
||||
|
||||
}
|
||||
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=48;
|
||||
uint8_t blank;
|
||||
uint16_t pts;
|
||||
uint8_t temp[48];
|
||||
uint8_t _array[48];
|
||||
pts = 0;
|
||||
memcpy(_array,Array,48);
|
||||
|
||||
while( (i< characters) && (i < MAX)) {
|
||||
|
||||
pts = pts + bits_number(Array[i]);
|
||||
|
||||
if(pts > MAX_PRINT_PTS) {
|
||||
memset(temp,0,48);
|
||||
memcpy(temp,_array,i);
|
||||
print_dots_8bit(cfg,temp,characters,0);
|
||||
pts = bits_number(_array[i]);
|
||||
memset(_array,0,i);
|
||||
}else if(pts==MAX_PRINT_PTS) {
|
||||
memset(temp,0,48);
|
||||
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);
|
||||
pts = 0;
|
||||
}
|
||||
|
||||
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=48;
|
||||
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++;
|
||||
}
|
||||
|
||||
|
||||
feed_pitch1(feed_num,cfg->orient);
|
||||
|
||||
|
||||
DISABLE_VH;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t temperature() {
|
||||
|
||||
/*
|
||||
double Rthermistor = 0, TempThermistor = 0;
|
||||
uint16 ADCSamples=0;
|
||||
int Sample = 1;
|
||||
uint16_t ADCConvertedValue;
|
||||
|
||||
|
||||
while(Sample<=NumSamples)
|
||||
{
|
||||
ADCSamples += analogRead(THERMISTORPIN);
|
||||
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);
|
||||
TempThermistor /= BCoefficent;
|
||||
TempThermistor += (1/(TempNominal + 273.15));
|
||||
TempThermistor = 1/TempThermistor;
|
||||
|
||||
return (uint16_t)(TempThermistor - 273.15);
|
||||
*/
|
||||
|
||||
return (uint16_t)(0);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void print_lines8(CONFIG*cfg) {
|
||||
uint8_t i,j,k;
|
||||
int8_t w;
|
||||
uint8_t *data;
|
||||
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 lastidx,lastw,lastj;
|
||||
int8_t left;
|
||||
pad = current_font.width %BITS8;
|
||||
|
||||
if(pad > 0){
|
||||
pad = 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
i = current_font.width/BITS8;
|
||||
|
||||
pad = i+pad;
|
||||
|
||||
row = 0;
|
||||
|
||||
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;
|
||||
|
||||
//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);
|
||||
i = lastidx;
|
||||
//DEBUG("i",i)
|
||||
//DEBUG("ser_cache.idx",ser_cache.idx)
|
||||
while( i <ser_cache.idx){
|
||||
addr = pad*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;
|
||||
}
|
||||
|
||||
///word gap
|
||||
k=0;
|
||||
while( k < cfg->wordgap ){
|
||||
if(dot_line_bitsidx > 7){
|
||||
dot_line_idx++;
|
||||
dot_line_bitsidx=0;
|
||||
}
|
||||
|
||||
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 {
|
||||
lastidx = i;
|
||||
lastw = w;
|
||||
lastj = j;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(IsPaper()== 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Serial.println("print ever");
|
||||
|
||||
free(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void print_image8(CONFIG*cfg){
|
||||
|
||||
uint16_t height;
|
||||
uint16_t x,y,addr;
|
||||
|
||||
uint8_t LinePixels[MAXPIXELS];
|
||||
|
||||
uint8_t maxchars= PRINTER_BITS/8;
|
||||
height = cfg->img->num / cfg->img->width;
|
||||
y=0;
|
||||
addr = 0;
|
||||
|
||||
while(y < height )
|
||||
{
|
||||
x=0;
|
||||
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
|
||||
LinePixels[x] = cfg->img->cache[addr];
|
||||
|
||||
x++;
|
||||
}
|
||||
|
||||
if(IsPaper()== IS_PAPER) print_dots_8bit_split(cfg,LinePixels,x);
|
||||
|
||||
//feed_pitch1(FEED_PITCH,BACKWARD);
|
||||
y++;
|
||||
}
|
||||
//feed_pitch1(cfg->feed_pitch,cfg->orient);
|
||||
cfg->img->need_print= 0;
|
||||
|
||||
cfg->img->num = 0;
|
||||
cfg->img->idx = 0;
|
||||
cfg->img->width = 0;
|
||||
|
||||
}
|
||||
|
||||
void print_cut_line(CONFIG*cfg){
|
||||
uint8_t bs,i;
|
||||
|
||||
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,'-');
|
||||
}
|
||||
}
|
||||
parse_serial_stream(cfg,ASCII_FF);
|
||||
|
||||
}
|
||||
43
Code/thermal_printer/printer.h
Normal file
43
Code/thermal_printer/printer.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef PRINTER_H
|
||||
#define PRINTER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define PRINT_SPLIT 6 // max points printed at the same time, 384/PRINT_SPLIT==96
|
||||
#define MAX_PRINT_PTS 24
|
||||
|
||||
void printer_send_data8(uint8_t);
|
||||
|
||||
void clear_printer_buffer();
|
||||
uint8_t IsPaper();
|
||||
|
||||
uint8_t header_init();
|
||||
uint8_t header_init1();
|
||||
|
||||
void motor_stepper_pos1(uint8_t Position);
|
||||
|
||||
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);
|
||||
|
||||
uint16_t temperature();
|
||||
|
||||
void print_lines8(CONFIG*);
|
||||
|
||||
uint8_t invert_bit(uint8_t a);
|
||||
|
||||
void print_image8(CONFIG*);
|
||||
void print_cut_line(CONFIG*);
|
||||
|
||||
void printer_set_font(CONFIG*cfg,uint8_t fnbits);
|
||||
void parse_serial_stream(CONFIG*cfg,uint8_t input_ch);
|
||||
|
||||
void reset_cmd();
|
||||
|
||||
#endif
|
||||
5128
Code/thermal_printer/ttf_Px437_PS2thin1_8x16.h
Normal file
5128
Code/thermal_printer/ttf_Px437_PS2thin1_8x16.h
Normal file
File diff suppressed because it is too large
Load Diff
5128
Code/thermal_printer/ttf_Px437_PS2thin2_8x16.h
Normal file
5128
Code/thermal_printer/ttf_Px437_PS2thin2_8x16.h
Normal file
File diff suppressed because it is too large
Load Diff
5
Code/thermal_printer/usr/local/bin/devterm_socat.sh
Executable file
5
Code/thermal_printer/usr/local/bin/devterm_socat.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
sleep 4
|
||||
chmod 777 /tmp/DEVTERM_PRINTER_IN
|
||||
chmod 777 /tmp/DEVTERM_PRINTER_OUT
|
||||
21
Code/thermal_printer/utils.c
Normal file
21
Code/thermal_printer/utils.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include "utils.h"
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
uint8_t bits_number(uint8_t n)//count bits "1"
|
||||
{
|
||||
uint8_t count = 0;
|
||||
while (n) {
|
||||
count += n & 1;
|
||||
n >>= 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
23
Code/thermal_printer/utils.h
Normal file
23
Code/thermal_printer/utils.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_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 ALINE printf("\n");
|
||||
|
||||
void delayus(unsigned int _us);
|
||||
|
||||
uint8_t invert_bit(uint8_t a);
|
||||
|
||||
uint8_t bits_number(uint8_t n);
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because one or more lines are too long
944
Schematics/clockwork_DevTerm_Battery_Schematic.pdf
Normal file
944
Schematics/clockwork_DevTerm_Battery_Schematic.pdf
Normal file
File diff suppressed because one or more lines are too long
2445
Schematics/clockwork_DevTerm_Ext_Schematic.pdf
Normal file
2445
Schematics/clockwork_DevTerm_Ext_Schematic.pdf
Normal file
File diff suppressed because one or more lines are too long
4746
Schematics/clockwork_DevTerm_Keyboard_Schematic.pdf
Normal file
4746
Schematics/clockwork_DevTerm_Keyboard_Schematic.pdf
Normal file
File diff suppressed because one or more lines are too long
7357
Schematics/clockwork_Mainboard_V3.14_Schematic.pdf
Normal file
7357
Schematics/clockwork_Mainboard_V3.14_Schematic.pdf
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user