forked from mect/go-escpos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epson.tinygo.go
55 lines (41 loc) · 1.12 KB
/
epson.tinygo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//go:build tinygo
// This file is specifically for making things compatible with TinyGo, it will not run in normal Go!
package escpos
import "io"
// our conversion table does not fit in microcontrollers, so we fake the conversion
// we should find a solution someday
type tinyCharacterConverter struct{}
func (t tinyCharacterConverter) Encode(utf_8 []byte) (latin []byte, success int, err error) {
return utf_8, 1, nil
}
var converter characterConverter = tinyCharacterConverter{}
type UART interface {
io.Reader
io.Writer
Buffered() int
}
// convert our UART to also have a closer, which it does not have
type uartToRWC struct {
u UART
}
func (u *uartToRWC) Read(p []byte) (int, error) {
return u.u.Read(p)
}
func (u *uartToRWC) Write(p []byte) (int, error) {
return u.u.Write(p)
}
func (u *uartToRWC) Close() error { // fake this out
return nil
}
// NewPrinterByUART returns a new printer with a TinyGo UART interface
func NewPrinterByUART(uart UART) (*Printer, error) {
return &Printer{
s: &uartToRWC{
u: uart,
},
}, nil
}
func (p *Printer) write(cmd string) error {
_, err := p.s.Write([]byte(cmd))
return err
}