|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Thermal\Profile; |
|
4
|
|
|
|
|
5
|
|
|
use Thermal\Printer; |
|
6
|
|
|
|
|
7
|
|
|
class Daruma extends Elgin |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param int $number drawer id |
|
11
|
|
|
* @param int $on_time time in milliseconds that activate the drawer |
|
12
|
|
|
* @param int $off_time time in milliseconds that deactivate the drawer |
|
13
|
|
|
*/ |
|
14
|
1 |
|
public function drawer($number, $on_time, $off_time) |
|
15
|
|
|
{ |
|
16
|
|
|
$index = [ |
|
17
|
1 |
|
Printer::DRAWER_1 => "p" |
|
18
|
|
|
]; |
|
19
|
1 |
|
if (!isset($index[$number])) { |
|
20
|
1 |
|
throw new \Exception( |
|
21
|
1 |
|
sprintf('Drawer %d not available for printer "%s"', $this->getName(), intval($number)), |
|
22
|
1 |
|
404 |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
1 |
|
$this->getConnection()->write("\e" . $index[$number]); |
|
26
|
1 |
|
return $this; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
protected function setAlignment($align) |
|
30
|
|
|
{ |
|
31
|
|
|
$cmd = [ |
|
32
|
1 |
|
Printer::ALIGN_LEFT => "\ej0", |
|
33
|
|
|
Printer::ALIGN_CENTER => "\ej1", |
|
34
|
|
|
Printer::ALIGN_RIGHT => "\ej2" |
|
35
|
|
|
]; |
|
36
|
1 |
|
$this->getConnection()->write($cmd[$align]); |
|
37
|
1 |
|
} |
|
38
|
|
|
|
|
39
|
2 |
|
protected function setMode($mode, $enable) |
|
40
|
|
|
{ |
|
41
|
2 |
|
if ($enable) { |
|
42
|
|
|
// enable styles |
|
43
|
2 |
|
if (Printer::STYLE_DOUBLE_WIDTH & $mode) { |
|
44
|
1 |
|
$this->getConnection()->write("\x0E"); |
|
45
|
|
|
} |
|
46
|
2 |
|
if (Printer::STYLE_DOUBLE_HEIGHT & $mode) { |
|
47
|
2 |
|
$this->getConnection()->write("\ew1"); |
|
48
|
|
|
} |
|
49
|
|
|
} else { |
|
50
|
|
|
// disable styles |
|
51
|
2 |
|
if (Printer::STYLE_DOUBLE_HEIGHT & $mode) { |
|
52
|
1 |
|
$this->getConnection()->write("\ew0"); |
|
53
|
|
|
} |
|
54
|
2 |
|
if (Printer::STYLE_DOUBLE_WIDTH & $mode) { |
|
55
|
1 |
|
$this->getConnection()->write("\x14"); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
2 |
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
protected function fontChanged($new_font, $old_font) |
|
62
|
|
|
{ |
|
63
|
1 |
|
if ($new_font['name'] == 'Font A') { |
|
64
|
1 |
|
$this->getConnection()->write("\e!\x00"); |
|
65
|
1 |
|
} elseif ($new_font['name'] == 'Font B') { |
|
66
|
1 |
|
$this->getConnection()->write("\e!\x01"); |
|
67
|
|
|
} |
|
68
|
1 |
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|