Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
miya-hardware
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengguangpu
miya-hardware
Commits
13d6bbf2
Commit
13d6bbf2
authored
Jan 23, 2019
by
pengguangpu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加商米的打印驱动,测试发现无法正常打印条码和二维码,待调试
parent
eb5a9693
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
739 additions
and
47 deletions
+739
-47
BasePrinter.java
print/src/main/java/com/miya/print/BasePrinter.java
+1
-1
ChuangjiePrinter.java
print/src/main/java/com/miya/print/ChuangjiePrinter.java
+2
-1
PrinterManager.java
print/src/main/java/com/miya/print/PrinterManager.java
+56
-10
SangdaPrinter.java
print/src/main/java/com/miya/print/SangdaPrinter.java
+3
-1
SunmiK1Printer.java
print/src/main/java/com/miya/print/SunmiK1Printer.java
+635
-0
YingtaiPrinter.java
print/src/main/java/com/miya/print/YingtaiPrinter.java
+1
-0
SunmiWeighing.java
weighing/src/main/java/com/miya/weighing/SunmiWeighing.java
+32
-31
WeighingManager.java
...hing/src/main/java/com/miya/weighing/WeighingManager.java
+9
-3
No files found.
print/src/main/java/com/miya/print/BasePrinter.java
View file @
13d6bbf2
...
...
@@ -6,7 +6,7 @@ import android.graphics.Bitmap;
/**
* 打印基类
*/
public
class
BasePrinter
implements
IPrinter
{
public
abstract
class
BasePrinter
implements
IPrinter
{
/**
* 80mm打印纸允许打印的最大图片的宽度,此为经验值
...
...
print/src/main/java/com/miya/print/ChuangjiePrinter.java
View file @
13d6bbf2
...
...
@@ -43,13 +43,14 @@ public class ChuangjiePrinter extends BasePrinter {
@Override
public
boolean
init
(
Context
context
)
{
D
.
i
(
TAG
,
"开始初始化创捷打印机"
);
this
.
context
=
context
;
if
(
mUsbDriver
==
null
)
{
getUsbDriverService
(
context
);
}
// USB线已经连接
getUsbDriverService
();
return
connet
()
==
0
;
return
connet
()
==
PrinterStatusEnum
.
CODE_SUCCESS
.
status
;
}
@Override
...
...
print/src/main/java/com/miya/print/PrinterManager.java
View file @
13d6bbf2
...
...
@@ -17,7 +17,7 @@ public class PrinterManager {
enum
Type
{
//这里添加扩展的驱动
// TYPE_HISENSE("hisense", ChuangjiePrinter.class.getName()),
TYPE_SUNMI
(
"s
hangmik1"
,
Shang
miK1Printer
.
class
.
getName
()),
TYPE_SUNMI
(
"s
unmiK1"
,
Sun
miK1Printer
.
class
.
getName
()),
TYPE_YINGTAI
(
"yingtai"
,
YingtaiPrinter
.
class
.
getName
()),
TYPE_CHUANGJIE
(
"chuangjie"
,
ChuangjiePrinter
.
class
.
getName
()),
TYPE_SANGDA
(
"sangda"
,
SangdaPrinter
.
class
.
getName
());
...
...
@@ -73,10 +73,10 @@ public class PrinterManager {
*/
public
boolean
init
(
Context
context
)
{
for
(
Type
type
:
Type
.
values
())
{
if
(
printer
!=
null
)
{
printer
.
release
();
}
try
{
if
(
printer
!=
null
)
{
printer
.
release
();
}
Class
printerCls
=
Class
.
forName
(
type
.
clsName
);
printer
=
(
IPrinter
)
printerCls
.
newInstance
();
boolean
result
=
printer
.
init
(
context
);
...
...
@@ -91,7 +91,11 @@ public class PrinterManager {
}
//没有找到对应的打印机
if
(
printer
!=
null
)
{
printer
.
release
();
try
{
printer
.
release
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
D
.
i
(
TAG
,
"没找到对应的打印机器,请检查"
);
return
false
;
...
...
@@ -104,16 +108,58 @@ public class PrinterManager {
*/
public
boolean
release
()
{
if
(
isConnected
())
{
boolean
result
=
printer
.
release
();
if
(
result
==
false
)
{
return
false
;
try
{
boolean
result
=
printer
.
release
();
if
(
result
==
false
)
{
return
false
;
}
printer
=
null
;
return
true
;
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
printer
=
null
;
return
true
;
}
return
true
;
}
/**
* 保险起见提供指定硬件的初始化
* ps:谨慎调用
*
* @param context
* @param type 指定硬件类型
* @return
*/
public
boolean
init
(
Context
context
,
Type
type
)
{
if
(
type
==
null
)
{
return
false
;
}
//是否支持指定硬件
boolean
isSupported
=
false
;
for
(
Type
tmpType
:
Type
.
values
())
{
if
(
type
.
typeName
.
equals
(
tmpType
.
typeName
))
{
isSupported
=
true
;
}
}
if
(
isSupported
==
false
)
{
return
false
;
}
//反射新建实例
try
{
Class
printerCls
=
Class
.
forName
(
type
.
clsName
);
printer
=
(
IPrinter
)
printerCls
.
newInstance
();
boolean
result
=
printer
.
init
(
context
);
if
(
result
==
true
)
{
printer
.
setPrinterName
(
type
.
typeName
);
D
.
i
(
TAG
,
"初始化打印机成功,打印机器为:"
+
type
.
typeName
);
}
return
result
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
/**
* 获取当前打印接口
*
...
...
print/src/main/java/com/miya/print/SangdaPrinter.java
View file @
13d6bbf2
...
...
@@ -30,6 +30,7 @@ public class SangdaPrinter extends BasePrinter {
@Override
public
boolean
init
(
Context
context
)
{
D
.
i
(
TAG
,
"开始初始化桑达打印机"
);
super
.
init
(
context
);
mPrinter
=
PrinterAPI
.
getInstance
();
if
(
isConnect
())
{
...
...
@@ -45,8 +46,9 @@ public class SangdaPrinter extends BasePrinter {
return
false
;
}
}
catch
(
Exception
e
)
{
D
.
e
(
TAG
,
"桑达打印机连接失败"
);
e
.
printStackTrace
(
);
}
D
.
e
(
TAG
,
"桑达打印机连接失败"
);
return
false
;
}
...
...
print/src/main/java/com/miya/print/S
hang
miK1Printer.java
→
print/src/main/java/com/miya/print/S
un
miK1Printer.java
View file @
13d6bbf2
This diff is collapsed.
Click to expand it.
print/src/main/java/com/miya/print/YingtaiPrinter.java
View file @
13d6bbf2
...
...
@@ -26,6 +26,7 @@ public class YingtaiPrinter extends BasePrinter {
@Override
public
boolean
init
(
Context
context
)
{
D
.
i
(
TAG
,
"开始初始化英泰打印机"
);
this
.
context
=
context
;
mPrinter
=
PrinterAPI
.
getInstance
();
io
=
new
USBAPI
(
context
);
...
...
weighing/src/main/java/com/miya/weighing/SunmiWeighing.java
View file @
13d6bbf2
...
...
@@ -31,6 +31,11 @@ public class SunmiWeighing extends BaseWeighing {
*/
ScaleService
scaleService
;
/**
* 服务连接器
*/
ServiceConnection
serviceConnection
;
/**
* 称重回调监听
*/
...
...
@@ -61,6 +66,33 @@ public class SunmiWeighing extends BaseWeighing {
@Override
public
boolean
init
(
Context
context
)
{
this
.
context
=
context
;
serviceConnection
=
new
ServiceConnection
()
{
@Override
public
void
onServiceConnected
(
ComponentName
name
,
IBinder
service
)
{
scaleService
=
ScaleService
.
Stub
.
asInterface
(
service
);
if
(
scaleService
!=
null
)
{
//设置重量回调
try
{
scaleService
.
getData
(
stub
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
D
.
i
(
TAG
,
"称重服务初始化失败!"
);
}
}
else
{
D
.
i
(
TAG
,
"防损称连接失败!"
);
}
}
@Override
public
void
onBindingDied
(
ComponentName
name
)
{
D
.
i
(
TAG
,
"解绑成功 ComponentName==>"
+
name
);
}
@Override
public
void
onServiceDisconnected
(
ComponentName
name
)
{
scaleService
=
null
;
}
};
Intent
intent
=
new
Intent
();
intent
.
setPackage
(
SERVICE_PACKAGE
);
intent
.
setAction
(
SERVICE_ACTION
);
...
...
@@ -83,37 +115,6 @@ public class SunmiWeighing extends BaseWeighing {
return
false
;
}
/**
* 服务连接器
*/
ServiceConnection
serviceConnection
=
new
ServiceConnection
()
{
@Override
public
void
onServiceConnected
(
ComponentName
name
,
IBinder
service
)
{
scaleService
=
ScaleService
.
Stub
.
asInterface
(
service
);
if
(
scaleService
!=
null
)
{
//设置重量回调
try
{
scaleService
.
getData
(
stub
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
D
.
i
(
TAG
,
"称重服务初始化失败!"
);
}
}
else
{
D
.
i
(
TAG
,
"防损称连接失败!"
);
}
}
@Override
public
void
onBindingDied
(
ComponentName
name
)
{
D
.
i
(
TAG
,
"解绑成功 ComponentName==>"
+
name
);
}
@Override
public
void
onServiceDisconnected
(
ComponentName
name
)
{
scaleService
=
null
;
}
};
@Override
public
boolean
release
()
{
if
(
context
!=
null
&&
serviceConnection
!=
null
)
{
...
...
weighing/src/main/java/com/miya/weighing/WeighingManager.java
View file @
13d6bbf2
...
...
@@ -4,6 +4,8 @@ import android.content.Context;
import
android.support.annotation.NonNull
;
import
android.util.Log
;
import
com.miya.weighing.utils.D
;
public
class
WeighingManager
{
final
static
String
TAG
=
WeighingManager
.
class
.
getSimpleName
();
...
...
@@ -80,10 +82,10 @@ public class WeighingManager {
//轮询所有的称重服务,注意是同步方法
for
(
Type
type
:
Type
.
values
())
{
//确保之前的称重实例已被销毁
if
(
weighing
!=
null
)
{
weighing
.
release
();
}
try
{
if
(
weighing
!=
null
)
{
weighing
.
release
();
}
//反射新建实例
Class
weighingClass
=
Class
.
forName
(
type
.
clsName
);
weighing
=
(
Weighing
)
weighingClass
.
newInstance
();
...
...
@@ -155,6 +157,10 @@ public class WeighingManager {
Class
weighingClass
=
Class
.
forName
(
type
.
clsName
);
weighing
=
(
Weighing
)
weighingClass
.
newInstance
();
boolean
result
=
weighing
.
init
(
context
);
if
(
result
==
true
)
{
weighing
.
setWeighingName
(
type
.
clsName
);
D
.
i
(
TAG
,
"称重硬件初始化成功==>"
+
weighing
.
getWeighingName
());
}
return
result
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
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