Commit eb4f9079 authored by Andrey's avatar Andrey

Added documentstion

parent eed97259
/* /*
* esc_pos_printer * esc_pos_printer
* Created by Andrey U * Created by Andrey Ushakov
* *
* See LICENSE for distribution and usage details. * See LICENSE for distribution and usage details.
*/ */
......
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
const esc = '\x1B'; const esc = '\x1B';
const gs = '\x1D'; const gs = '\x1D';
......
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
enum PosTextAlign { left, center, right } enum PosTextAlign { left, center, right }
enum PosCutMode { full, partial } enum PosCutMode { full, partial }
enum PosFontType { fontA, fontB } enum PosFontType { fontA, fontB }
......
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
/// Used by [Printer.printRow] method
class PosRowException implements Exception { class PosRowException implements Exception {
PosRowException(this._msg); PosRowException(this._msg);
String _msg; String _msg;
......
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
import 'enums.dart'; import 'enums.dart';
/// A string with styles
class PosString { class PosString {
PosString( PosString(
this.text, { this.text, {
......
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:hex/hex.dart'; import 'package:hex/hex.dart';
...@@ -30,7 +38,9 @@ class Printer { ...@@ -30,7 +38,9 @@ class Printer {
_socket.destroy(); _socket.destroy();
} }
/// colInd range: 0..11 /// Generic print for internal use
///
/// [colInd] range: 0..11
void _print(PosString data, {int colInd = 0, int linesAfter = 0}) { void _print(PosString data, {int colInd = 0, int linesAfter = 0}) {
final int pos = colInd == 0 ? 0 : (512 * colInd / 11 - 1).round(); final int pos = colInd == 0 ? 0 : (512 * colInd / 11 - 1).round();
final hexStr = pos.toRadixString(16).padLeft(3, '0'); final hexStr = pos.toRadixString(16).padLeft(3, '0');
...@@ -61,6 +71,7 @@ class Printer { ...@@ -61,6 +71,7 @@ class Printer {
_socket.write(data.text); _socket.write(data.text);
} }
/// Prints one line of styled text
void println(PosString data, {int linesAfter = 0}) { void println(PosString data, {int linesAfter = 0}) {
_print(data, linesAfter: linesAfter); _print(data, linesAfter: linesAfter);
_socket.writeln(); _socket.writeln();
...@@ -68,6 +79,23 @@ class Printer { ...@@ -68,6 +79,23 @@ class Printer {
reset(); reset();
} }
/// Print a row.
///
/// A row contains up to 12 columns. A column has a width between 1 and 12.
/// Total width of columns in one row must be equal 12.
///
/// [cols] parameter is used to define the row structure (each integer value is one column width).
/// [data] parameter is used to define the column data (text, align inside of the column and styles).
/// Column data is represented by [PosString] class.
///
/// ```dart
/// printer.printRow(
/// [3, 6, 3],
/// [ PosString('col3'),
/// PosString('col6'),
/// PosString('col3') ],
/// );
/// ```
void printRow(List<int> cols, List<PosString> data) { void printRow(List<int> cols, List<PosString> data) {
final validRange = cols.every((val) => val >= 1 && val <= 12); final validRange = cols.every((val) => val >= 1 && val <= 12);
if (!validRange) { if (!validRange) {
...@@ -90,13 +118,15 @@ class Printer { ...@@ -90,13 +118,15 @@ class Printer {
reset(); reset();
} }
void beep( /// Beeps [n] times
{int count = 3, PosBeepDuration duration = PosBeepDuration.beep450ms}) { ///
if (count <= 0) { /// Beep [duration] could be between 50 and 450 ms.
void beep({int n = 3, PosBeepDuration duration = PosBeepDuration.beep450ms}) {
if (n <= 0) {
return; return;
} }
int beepCount = count; int beepCount = n;
if (beepCount > 9) { if (beepCount > 9) {
beepCount = 9; beepCount = 9;
} }
...@@ -107,19 +137,26 @@ class Printer { ...@@ -107,19 +137,26 @@ class Printer {
), ),
); );
beep(count: count - 9, duration: duration); beep(n: n - 9, duration: duration);
} }
/// Clear the buffer and reset text styles
void reset() { void reset() {
_socket.write(cInit); _socket.write(cInit);
} }
/// Skips [n] lines
///
/// Similar to [feed] but uses an alternative command
void emptyLines(int n) { void emptyLines(int n) {
if (n > 0) { if (n > 0) {
_socket.write(List.filled(n, '\n').join()); _socket.write(List.filled(n, '\n').join());
} }
} }
/// Skips [n] lines
///
/// Similar to [emptyLines] but uses an alternative command
void feed(int n) { void feed(int n) {
if (n >= 0 && n <= 255) { if (n >= 0 && n <= 255) {
_socket.add( _socket.add(
...@@ -130,6 +167,7 @@ class Printer { ...@@ -130,6 +167,7 @@ class Printer {
} }
} }
/// Reverse feed for [n] lines (if supported by the priner)
void reverseFeed(int n) { void reverseFeed(int n) {
_socket.add( _socket.add(
Uint8List.fromList( Uint8List.fromList(
...@@ -138,6 +176,9 @@ class Printer { ...@@ -138,6 +176,9 @@ class Printer {
); );
} }
/// Cut the paper
///
/// [mode] is used to define the full or partial cut (if supported by the priner)
void cut({PosCutMode mode = PosCutMode.full}) { void cut({PosCutMode mode = PosCutMode.full}) {
_socket.write('\n\n\n\n\n'); _socket.write('\n\n\n\n\n');
if (mode == PosCutMode.partial) { if (mode == PosCutMode.partial) {
......
name: esc_pos_printer name: esc_pos_printer
description: A new Flutter package project. description: ESC/POS (thermal, receipt) printing for Flutter & Dart.
version: 0.0.1 version: 0.9.0
author: author: Andrey Ushakov
homepage: homepage: https://github.com/andrey-ushakov/esc_pos_printer
environment: environment:
sdk: ">=2.1.0 <3.0.0" sdk: ">=2.1.0 <3.0.0"
......
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