-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_linux.go
128 lines (103 loc) · 2.4 KB
/
main_linux.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"flag"
"fmt"
"log"
"os"
"strconv"
)
var printer *Printer
func main() {
fmt.Println("Point Of Sale Ticket Printer")
fmt.Println("Version 1.04 - SCL")
fmt.Println()
var path string
var cups bool
flag.StringVar(&path, "p", "", "The printer name or path (/dev/usb/lp0)")
flag.BoolVar(&cups, "cups", false, "Use CUPS")
flag.Parse()
c, err := NewConfig("posprinter.conf")
if err != nil {
log.Fatal(err)
}
if path == "" {
path = c.String("path", "")
cups = c.Bool("cups", false)
} else {
c.Set("path", path)
c.Set("cups", strconv.FormatBool(cups))
c.Save()
}
if path == "" {
usage()
}
printer, err = New(path, cups)
if err != nil {
log.Fatal(err)
}
// Print QR
str := ""
for i := 0; i < 650; i++ {
str += "a"
}
content_bytes := []byte(str)
store_len := len(content_bytes) + 3
store_pL := (byte)(store_len % 256)
store_pH := (byte)(store_len / 256)
fmt.Println(len(str), ">", store_pH, store_pL, store_len)
return
INIT := []byte{0x1B, 0x40}
FUNC_165 := []byte{0x1D, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x33, 0x00}
FUNC_167 := []byte{0x1D, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x05} // el último es el tamaño 3-9
FUNC_169 := []byte{0x1D, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x30}
FUNC_180 := []byte{0x1D, 0x28, 0x6b, store_pL, store_pH, 0x31, 0x50, 0x30}
FUNC_181 := []byte{0x1D, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30}
FUNC_182 := []byte{0x1D, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x52, 0x30}
printer.Write(INIT)
printer.Write(FUNC_165)
printer.Write(FUNC_167)
printer.Write(FUNC_169)
printer.Write(FUNC_180)
printer.Write(content_bytes)
printer.Write(FUNC_181)
printer.Write(FUNC_182)
// const N = 20
// for i, len := 0, len(b); i < len; i += N {
// if i+N >= len {
// if err := printer.Write(b[i:]); err != nil {
// log.Fatal(err)
// }
// } else {
// if err := printer.Write(b[i : i+N]); err != nil {
// log.Fatal(err)
// }
// }
// }
// for _, c := range b {
// if err := printer.Write([]byte{c}); err != nil {
// log.Fatal(err)
// }
// }
// fmt.Println(string(b))
//printer.Write(b)
return
listen()
}
func usage() {
fmt.Println(`Usage: posprinter -p /dev/usb/lpt1`)
os.Exit(1)
}
func (p *Printer) Write(b []byte) error {
// d, err := decode(b)
// if err != nil {
// return err
// }
d := b
if p.CUPS {
return p.sendToCUPS(d)
}
if _, err := p.file.Write(d); err != nil {
return err
}
return nil
}