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
Show 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;
...
@@ -6,7 +6,7 @@ import android.graphics.Bitmap;
/**
/**
* 打印基类
* 打印基类
*/
*/
public
class
BasePrinter
implements
IPrinter
{
public
abstract
class
BasePrinter
implements
IPrinter
{
/**
/**
* 80mm打印纸允许打印的最大图片的宽度,此为经验值
* 80mm打印纸允许打印的最大图片的宽度,此为经验值
...
...
print/src/main/java/com/miya/print/ChuangjiePrinter.java
View file @
13d6bbf2
...
@@ -43,13 +43,14 @@ public class ChuangjiePrinter extends BasePrinter {
...
@@ -43,13 +43,14 @@ public class ChuangjiePrinter extends BasePrinter {
@Override
@Override
public
boolean
init
(
Context
context
)
{
public
boolean
init
(
Context
context
)
{
D
.
i
(
TAG
,
"开始初始化创捷打印机"
);
this
.
context
=
context
;
this
.
context
=
context
;
if
(
mUsbDriver
==
null
)
{
if
(
mUsbDriver
==
null
)
{
getUsbDriverService
(
context
);
getUsbDriverService
(
context
);
}
}
// USB线已经连接
// USB线已经连接
getUsbDriverService
();
getUsbDriverService
();
return
connet
()
==
0
;
return
connet
()
==
PrinterStatusEnum
.
CODE_SUCCESS
.
status
;
}
}
@Override
@Override
...
...
print/src/main/java/com/miya/print/PrinterManager.java
View file @
13d6bbf2
...
@@ -17,7 +17,7 @@ public class PrinterManager {
...
@@ -17,7 +17,7 @@ public class PrinterManager {
enum
Type
{
enum
Type
{
//这里添加扩展的驱动
//这里添加扩展的驱动
// TYPE_HISENSE("hisense", ChuangjiePrinter.class.getName()),
// 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_YINGTAI
(
"yingtai"
,
YingtaiPrinter
.
class
.
getName
()),
TYPE_CHUANGJIE
(
"chuangjie"
,
ChuangjiePrinter
.
class
.
getName
()),
TYPE_CHUANGJIE
(
"chuangjie"
,
ChuangjiePrinter
.
class
.
getName
()),
TYPE_SANGDA
(
"sangda"
,
SangdaPrinter
.
class
.
getName
());
TYPE_SANGDA
(
"sangda"
,
SangdaPrinter
.
class
.
getName
());
...
@@ -73,10 +73,10 @@ public class PrinterManager {
...
@@ -73,10 +73,10 @@ public class PrinterManager {
*/
*/
public
boolean
init
(
Context
context
)
{
public
boolean
init
(
Context
context
)
{
for
(
Type
type
:
Type
.
values
())
{
for
(
Type
type
:
Type
.
values
())
{
try
{
if
(
printer
!=
null
)
{
if
(
printer
!=
null
)
{
printer
.
release
();
printer
.
release
();
}
}
try
{
Class
printerCls
=
Class
.
forName
(
type
.
clsName
);
Class
printerCls
=
Class
.
forName
(
type
.
clsName
);
printer
=
(
IPrinter
)
printerCls
.
newInstance
();
printer
=
(
IPrinter
)
printerCls
.
newInstance
();
boolean
result
=
printer
.
init
(
context
);
boolean
result
=
printer
.
init
(
context
);
...
@@ -91,7 +91,11 @@ public class PrinterManager {
...
@@ -91,7 +91,11 @@ public class PrinterManager {
}
}
//没有找到对应的打印机
//没有找到对应的打印机
if
(
printer
!=
null
)
{
if
(
printer
!=
null
)
{
try
{
printer
.
release
();
printer
.
release
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
D
.
i
(
TAG
,
"没找到对应的打印机器,请检查"
);
D
.
i
(
TAG
,
"没找到对应的打印机器,请检查"
);
return
false
;
return
false
;
...
@@ -104,16 +108,58 @@ public class PrinterManager {
...
@@ -104,16 +108,58 @@ public class PrinterManager {
*/
*/
public
boolean
release
()
{
public
boolean
release
()
{
if
(
isConnected
())
{
if
(
isConnected
())
{
try
{
boolean
result
=
printer
.
release
();
boolean
result
=
printer
.
release
();
if
(
result
==
false
)
{
if
(
result
==
false
)
{
return
false
;
return
false
;
}
}
printer
=
null
;
printer
=
null
;
return
true
;
return
true
;
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
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 {
...
@@ -30,6 +30,7 @@ public class SangdaPrinter extends BasePrinter {
@Override
@Override
public
boolean
init
(
Context
context
)
{
public
boolean
init
(
Context
context
)
{
D
.
i
(
TAG
,
"开始初始化桑达打印机"
);
super
.
init
(
context
);
super
.
init
(
context
);
mPrinter
=
PrinterAPI
.
getInstance
();
mPrinter
=
PrinterAPI
.
getInstance
();
if
(
isConnect
())
{
if
(
isConnect
())
{
...
@@ -45,8 +46,9 @@ public class SangdaPrinter extends BasePrinter {
...
@@ -45,8 +46,9 @@ public class SangdaPrinter extends BasePrinter {
return
false
;
return
false
;
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
D
.
e
(
TAG
,
"桑达打印机连接失败"
);
e
.
printStackTrace
(
);
}
}
D
.
e
(
TAG
,
"桑达打印机连接失败"
);
return
false
;
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 {
...
@@ -26,6 +26,7 @@ public class YingtaiPrinter extends BasePrinter {
@Override
@Override
public
boolean
init
(
Context
context
)
{
public
boolean
init
(
Context
context
)
{
D
.
i
(
TAG
,
"开始初始化英泰打印机"
);
this
.
context
=
context
;
this
.
context
=
context
;
mPrinter
=
PrinterAPI
.
getInstance
();
mPrinter
=
PrinterAPI
.
getInstance
();
io
=
new
USBAPI
(
context
);
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 {
...
@@ -31,6 +31,11 @@ public class SunmiWeighing extends BaseWeighing {
*/
*/
ScaleService
scaleService
;
ScaleService
scaleService
;
/**
* 服务连接器
*/
ServiceConnection
serviceConnection
;
/**
/**
* 称重回调监听
* 称重回调监听
*/
*/
...
@@ -61,32 +66,7 @@ public class SunmiWeighing extends BaseWeighing {
...
@@ -61,32 +66,7 @@ public class SunmiWeighing extends BaseWeighing {
@Override
@Override
public
boolean
init
(
Context
context
)
{
public
boolean
init
(
Context
context
)
{
this
.
context
=
context
;
this
.
context
=
context
;
Intent
intent
=
new
Intent
();
serviceConnection
=
new
ServiceConnection
()
{
intent
.
setPackage
(
SERVICE_PACKAGE
);
intent
.
setAction
(
SERVICE_ACTION
);
return
this
.
context
.
bindService
(
intent
,
serviceConnection
,
Context
.
BIND_AUTO_CREATE
);
}
@Override
public
void
setWeighingCallback
(
WeighingCallback
weighingCallback
)
{
this
.
weighingCallback
=
weighingCallback
;
}
@Override
public
boolean
resetZero
()
{
try
{
scaleService
.
zero
();
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
/**
* 服务连接器
*/
ServiceConnection
serviceConnection
=
new
ServiceConnection
()
{
@Override
@Override
public
void
onServiceConnected
(
ComponentName
name
,
IBinder
service
)
{
public
void
onServiceConnected
(
ComponentName
name
,
IBinder
service
)
{
scaleService
=
ScaleService
.
Stub
.
asInterface
(
service
);
scaleService
=
ScaleService
.
Stub
.
asInterface
(
service
);
...
@@ -113,6 +93,27 @@ public class SunmiWeighing extends BaseWeighing {
...
@@ -113,6 +93,27 @@ public class SunmiWeighing extends BaseWeighing {
scaleService
=
null
;
scaleService
=
null
;
}
}
};
};
Intent
intent
=
new
Intent
();
intent
.
setPackage
(
SERVICE_PACKAGE
);
intent
.
setAction
(
SERVICE_ACTION
);
return
this
.
context
.
bindService
(
intent
,
serviceConnection
,
Context
.
BIND_AUTO_CREATE
);
}
@Override
public
void
setWeighingCallback
(
WeighingCallback
weighingCallback
)
{
this
.
weighingCallback
=
weighingCallback
;
}
@Override
public
boolean
resetZero
()
{
try
{
scaleService
.
zero
();
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
@Override
@Override
public
boolean
release
()
{
public
boolean
release
()
{
...
...
weighing/src/main/java/com/miya/weighing/WeighingManager.java
View file @
13d6bbf2
...
@@ -4,6 +4,8 @@ import android.content.Context;
...
@@ -4,6 +4,8 @@ import android.content.Context;
import
android.support.annotation.NonNull
;
import
android.support.annotation.NonNull
;
import
android.util.Log
;
import
android.util.Log
;
import
com.miya.weighing.utils.D
;
public
class
WeighingManager
{
public
class
WeighingManager
{
final
static
String
TAG
=
WeighingManager
.
class
.
getSimpleName
();
final
static
String
TAG
=
WeighingManager
.
class
.
getSimpleName
();
...
@@ -80,10 +82,10 @@ public class WeighingManager {
...
@@ -80,10 +82,10 @@ public class WeighingManager {
//轮询所有的称重服务,注意是同步方法
//轮询所有的称重服务,注意是同步方法
for
(
Type
type
:
Type
.
values
())
{
for
(
Type
type
:
Type
.
values
())
{
//确保之前的称重实例已被销毁
//确保之前的称重实例已被销毁
try
{
if
(
weighing
!=
null
)
{
if
(
weighing
!=
null
)
{
weighing
.
release
();
weighing
.
release
();
}
}
try
{
//反射新建实例
//反射新建实例
Class
weighingClass
=
Class
.
forName
(
type
.
clsName
);
Class
weighingClass
=
Class
.
forName
(
type
.
clsName
);
weighing
=
(
Weighing
)
weighingClass
.
newInstance
();
weighing
=
(
Weighing
)
weighingClass
.
newInstance
();
...
@@ -155,6 +157,10 @@ public class WeighingManager {
...
@@ -155,6 +157,10 @@ public class WeighingManager {
Class
weighingClass
=
Class
.
forName
(
type
.
clsName
);
Class
weighingClass
=
Class
.
forName
(
type
.
clsName
);
weighing
=
(
Weighing
)
weighingClass
.
newInstance
();
weighing
=
(
Weighing
)
weighingClass
.
newInstance
();
boolean
result
=
weighing
.
init
(
context
);
boolean
result
=
weighing
.
init
(
context
);
if
(
result
==
true
)
{
weighing
.
setWeighingName
(
type
.
clsName
);
D
.
i
(
TAG
,
"称重硬件初始化成功==>"
+
weighing
.
getWeighingName
());
}
return
result
;
return
result
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
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