Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esc_pos_print_plus
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
esc_pos_print_plus
Commits
bbf5ce66
Commit
bbf5ce66
authored
Jun 12, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added printCol function.
parent
f8ddcfa7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
0 deletions
+58
-0
esc_pos_printer.dart
lib/esc_pos_printer.dart
+1
-0
enums.dart
lib/src/enums.dart
+17
-0
exceptions.dart
lib/src/exceptions.dart
+7
-0
printer.dart
lib/src/printer.dart
+32
-0
pubspec.yaml
pubspec.yaml
+1
-0
No files found.
lib/esc_pos_printer.dart
View file @
bbf5ce66
...
...
@@ -7,4 +7,5 @@
library
esc_pos_printer
;
export
'./src/enums.dart'
;
export
'./src/exceptions.dart'
;
export
'./src/printer.dart'
;
lib/src/enums.dart
View file @
bbf5ce66
...
...
@@ -31,3 +31,20 @@ class PosBeepDuration {
static
const
beep400ms
=
PosBeepDuration
.
_internal
(
8
);
static
const
beep450ms
=
PosBeepDuration
.
_internal
(
9
);
}
// class PosCol {
// const PosCol._internal(this.value);
// final int value;
// static const col1 = PosCol._internal(1);
// static const col2 = PosCol._internal(2);
// static const col3 = PosCol._internal(3);
// static const col4 = PosCol._internal(4);
// static const col5 = PosCol._internal(5);
// static const col6 = PosCol._internal(6);
// static const col7 = PosCol._internal(7);
// static const col8 = PosCol._internal(8);
// static const col9 = PosCol._internal(9);
// static const col10 = PosCol._internal(10);
// static const col11 = PosCol._internal(11);
// static const col12 = PosCol._internal(12);
// }
lib/src/exceptions.dart
0 → 100644
View file @
bbf5ce66
class
PosRowException
implements
Exception
{
PosRowException
(
this
.
_msg
);
String
_msg
;
@override
String
toString
()
=>
'PosRowException:
$_msg
'
;
}
lib/src/printer.dart
View file @
bbf5ce66
import
'dart:io'
;
import
'dart:typed_data'
;
import
'package:hex/hex.dart'
;
import
'commands.dart'
;
import
'enums.dart'
;
import
'exceptions.dart'
;
/// Printer.
class
Printer
{
...
...
@@ -57,6 +59,36 @@ class Printer {
reset
();
}
void
printRow
(
List
<
int
>
cols
,
List
<
String
>
data
)
{
final
validRange
=
cols
.
every
((
val
)
=>
val
>=
1
&&
val
<=
12
);
if
(!
validRange
)
{
throw
PosRowException
(
'Column width should be between 1..12'
);
}
final
validSum
=
cols
.
fold
(
0
,
(
int
sum
,
cur
)
=>
sum
+
cur
)
==
12
;
if
(!
validSum
)
{
throw
PosRowException
(
'Total columns width must be equal 12'
);
}
if
(
cols
.
length
!=
data
.
length
)
{
throw
PosRowException
(
"Columns number doesn't equal to data number"
);
}
for
(
int
i
=
0
;
i
<
cols
.
length
;
++
i
)
{
final
colInd
=
cols
.
sublist
(
0
,
i
).
fold
(
0
,
(
int
sum
,
cur
)
=>
sum
+
cur
);
_printCol
(
colInd
,
data
[
i
]);
}
_socket
.
writeln
();
}
void
_printCol
(
int
i
,
String
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
(
{
int
count
=
3
,
PosBeepDuration
duration
=
PosBeepDuration
.
beep450ms
})
{
if
(
count
<=
0
)
{
...
...
pubspec.yaml
View file @
bbf5ce66
...
...
@@ -10,6 +10,7 @@ environment:
dependencies
:
flutter
:
sdk
:
flutter
hex
:
^0.1.2
dev_dependencies
:
flutter_test
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment