Commit 43233a73 authored by Andrey's avatar Andrey

Added beep and fontType commands

parent 81180762
......@@ -3,6 +3,7 @@ const gs = '\x1D';
// Miscellaneous
const cInit = '$esc@'; // Initialize printer
const cBeep = '${esc}B'; // Beeper [count] [duration]
// Mech. Control
const cCut = '${gs}V0'; // Cut paper
......@@ -19,6 +20,8 @@ const cUnderline1dot = '$esc-1'; // Turns on underline mode (1-dot thick)
const cUnderline2dots = '$esc-2'; // Turns on underline mode (2-dots thick)
const cBoldOn = '${esc}E1'; // Turn emphasized mode on
const cBoldOff = '${esc}E0'; // Turn emphasized mode off
const cFontA = '${esc}M0'; // Font A
const cFontB = '${esc}M1'; // Font B
// Print Position
const cAlignLeft = '${esc}a0'; // Left justification
......
......@@ -4,6 +4,7 @@ import 'commands.dart';
enum PosTextAlign { left, center, right }
enum PosCutMode { normal, partial, full }
enum PosFontType { fontA, fontB }
class PosTextSize {
final int value;
......@@ -21,6 +22,20 @@ class PosTextSize {
16 * (width.value - 1) + (height.value - 1);
}
class PosBeepDuration {
final int value;
const PosBeepDuration._internal(this.value);
static const beep50ms = const PosBeepDuration._internal(1);
static const beep100ms = const PosBeepDuration._internal(2);
static const beep150ms = const PosBeepDuration._internal(3);
static const beep200ms = const PosBeepDuration._internal(4);
static const beep250ms = const PosBeepDuration._internal(5);
static const beep300ms = const PosBeepDuration._internal(6);
static const beep350ms = const PosBeepDuration._internal(7);
static const beep400ms = const PosBeepDuration._internal(8);
static const beep450ms = const PosBeepDuration._internal(9);
}
/// Abstract printer.
class Printer {
Printer(this._socket) {
......@@ -66,6 +81,7 @@ class Printer {
PosTextAlign align = PosTextAlign.left,
PosTextSize height = PosTextSize.size1,
PosTextSize width = PosTextSize.size1,
PosFontType fontType = PosFontType.fontA,
int linesAfter = 0,
}) {
_socket.write(bold ? cBoldOn : cBoldOff);
......@@ -74,7 +90,7 @@ class Printer {
_socket.write(align == PosTextAlign.left
? cAlignLeft
: (align == PosTextAlign.center ? cAlignCenter : cAlignRight));
_socket.write(fontType == PosFontType.fontA ? cFontA : cFontB);
// Text size
_socket.add(
Uint8List.fromList(
......@@ -87,6 +103,26 @@ class Printer {
reset();
}
void beep(
{int count = 3, PosBeepDuration duration = PosBeepDuration.beep450ms}) {
if (count <= 0) {
return;
}
int beepCount = count;
if (beepCount > 9) {
beepCount = 9;
}
_socket.add(
Uint8List.fromList(
List.from(cBeep.codeUnits)..addAll([beepCount, duration.value]),
),
);
beep(count: count - 9, duration: duration);
}
void reset() {
_socket.write(cInit);
}
......
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