Commit 3e88f053 authored by Andrey's avatar Andrey

Added generic _print method

parent 0db38e74
...@@ -26,6 +26,7 @@ const cFontB = '${esc}M1'; // Font B ...@@ -26,6 +26,7 @@ const cFontB = '${esc}M1'; // Font B
const cAlignLeft = '${esc}a0'; // Left justification const cAlignLeft = '${esc}a0'; // Left justification
const cAlignCenter = '${esc}a1'; // Centered const cAlignCenter = '${esc}a1'; // Centered
const cAlignRight = '${esc}a2'; // Right justification const cAlignRight = '${esc}a2'; // Right justification
const cPos = '$esc\$'; // Set absolute print position [nL] [nH]
// Print // Print
const cFeedN = '${esc}d'; // Print and feed n lines [N] const cFeedN = '${esc}d'; // Print and feed n lines [N]
......
...@@ -10,7 +10,6 @@ class PosString { ...@@ -10,7 +10,6 @@ class PosString {
this.height = PosTextSize.size1, this.height = PosTextSize.size1,
this.width = PosTextSize.size1, this.width = PosTextSize.size1,
this.fontType = PosFontType.fontA, this.fontType = PosFontType.fontA,
this.linesAfter = 0,
}); });
String text; String text;
...@@ -21,7 +20,6 @@ class PosString { ...@@ -21,7 +20,6 @@ class PosString {
PosTextSize height = PosTextSize.size1; PosTextSize height = PosTextSize.size1;
PosTextSize width = PosTextSize.size1; PosTextSize width = PosTextSize.size1;
PosFontType fontType = PosFontType.fontA; PosFontType fontType = PosFontType.fontA;
int linesAfter = 0;
@override @override
String toString() { String toString() {
......
...@@ -30,7 +30,13 @@ class Printer { ...@@ -30,7 +30,13 @@ class Printer {
_socket.destroy(); _socket.destroy();
} }
void println(PosString data) { /// colInd range: 0..11
void _print(PosString data, {int colInd = 0, int linesAfter = 0}) {
final int pos = colInd == 0 ? 0 : (512 * colInd / 11 - 1).round();
final hexStr = pos.toRadixString(16).padLeft(3, '0');
final hexPair = HEX.decode(hexStr);
// print('dec: $pos \t hex: $hexStr \t pair $hexPair');
_socket.write(data.bold ? cBoldOn : cBoldOff); _socket.write(data.bold ? cBoldOn : cBoldOff);
_socket.write(data.reverse ? cReverseOn : cReverseOff); _socket.write(data.reverse ? cReverseOn : cReverseOff);
_socket.write(data.underline ? cUnderline1dot : cUnderlineOff); _socket.write(data.underline ? cUnderline1dot : cUnderlineOff);
...@@ -45,9 +51,20 @@ class Printer { ...@@ -45,9 +51,20 @@ class Printer {
..add(PosTextSize.decSize(data.height, data.width)), ..add(PosTextSize.decSize(data.height, data.width)),
), ),
); );
// Position
_socket.add(
Uint8List.fromList(
List.from(cPos.codeUnits)..addAll([hexPair[1], hexPair[0]]),
),
);
_socket.writeln(data.text); _socket.write(data.text);
emptyLines(data.linesAfter); }
void println(PosString data, {int linesAfter = 0}) {
_print(data, linesAfter: linesAfter);
_socket.writeln();
emptyLines(linesAfter);
reset(); reset();
} }
...@@ -66,19 +83,11 @@ class Printer { ...@@ -66,19 +83,11 @@ class Printer {
for (int i = 0; i < cols.length; ++i) { for (int i = 0; i < cols.length; ++i) {
final colInd = cols.sublist(0, i).fold(0, (int sum, cur) => sum + cur); final colInd = cols.sublist(0, i).fold(0, (int sum, cur) => sum + cur);
_printCol(colInd, data[i]); _print(data[i], colInd: colInd);
} }
_socket.writeln(); _socket.writeln();
} reset();
void _printCol(int i, PosString data) {
final int pos = i == 0 ? 0 : (512 * i / 11 - 1).round();
final hexStr = pos.toRadixString(16).padLeft(3, '0');
final hexPair = HEX.decode(hexStr);
// print('dec: $pos \t hex: $hexStr \t pair $hexPair');
_socket.add(Uint8List.fromList([0x1b, 0x24, hexPair[1], hexPair[0]]));
_socket.write(data);
} }
void beep( void beep(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment