Skip to content

Commit 8e452cd

Browse files
committed
优化电量算法
1 parent 20f7a7f commit 8e452cd

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Biomodule 蓝牙SDK [![Download](https://api.bintray.com/packages/hzentertech/maven/biomoduleble/images/download.svg?version=1.0.7)](https://bintray.com/hzentertech/maven/biomoduleble/1.0.7/link)
1+
# Biomodule 蓝牙SDK [![Download](https://api.bintray.com/packages/hzentertech/maven/biomoduleble/images/download.svg?version=1.0.8)](https://bintray.com/hzentertech/maven/biomoduleble/1.0.8/link)
22
# 简介
33

44
本 SDK 包含回车生物电采集模块的蓝牙连接和生物电采集控制。通过此 SDK 可以在 Android app 里快速实现和我们的采集模块连接,并控制其进行数据的采集和停止等指令。
@@ -25,7 +25,7 @@ SDK中Demo与API接口采用Kotlin语言编写,希望你对Kotlin有一定的
2525
### gradle自动依赖
2626
在所需的module中的build.gradle文件下添加以下依赖即可:
2727
```groovy
28-
implementation 'cn.entertech:biomoduleble:1.0.7'
28+
implementation 'cn.entertech:biomoduleble:1.0.8'
2929
```
3030
### jar包集成
3131
如果你在自动依赖遇到问题也可以手动添加依赖
@@ -34,7 +34,7 @@ implementation 'cn.entertech:biomoduleble:1.0.7'
3434

3535
```groovy
3636
implementation fileTree(include: ['*.jar'], dir: 'libs')
37-
implementation files('libs/enter-biomodule-ble-v1.0.7.jar')
37+
implementation files('libs/enter-biomodule-ble-v1.0.8.jar')
3838
```
3939
### 注意事项
4040

Binary file not shown.

ble/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ publish {
5151
//项目名称
5252
artifactId = 'biomoduleble'
5353
//版本号
54-
publishVersion = '1.0.7'
54+
publishVersion = '1.0.8'
5555
//描述,不重要
5656
desc = ''
5757
//网站,不重要

ble/src/main/java/cn/entertech/ble/util/BatteryUtil.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package cn.entertech.ble.util
22

3-
import com.orhanobut.logger.Logger
3+
import kotlin.math.exp
4+
import kotlin.math.max
5+
import kotlin.math.min
6+
import kotlin.math.pow
47

58
/**
69
* Created by EnterTech on 2018/2/8.
@@ -9,18 +12,29 @@ object BatteryUtil {
912

1013
fun getMinutesLeft(byte: Byte): NapBattery {
1114
((byte / 100.0) * (4.1 - 3.1) + 3.1).let {
12-
val minutes = -12050 * Math.pow(it, 4.0) + 137175 * Math.pow(it, 3.0) - 517145 * Math.pow(it, 2.0) + 644850 * it + 5034
13-
// val minutes = 229607.31 * Math.pow(it, 4.0) - 3581456.13 * Math.pow(it, 3.0) + 20922054.15 * Math.pow(it, 2.0) - 54241619.24* it + 52651001.51
14-
val percent = (minutes * 100 / (81 * 60)).toInt()
15+
var a1 = 99.84
16+
var b1 = 4.244
17+
var c1 = 0.3781
18+
var a2 = 21.38
19+
var b2 = 3.953
20+
var c2 = 0.1685
21+
var a3 = 15.21
22+
var b3 = 3.813
23+
var c3 = 0.09208
24+
var q1 = a1 * exp(-((it - b1) / c1).pow(2.0))
25+
var q2 = a2 * exp(-((it - b2) / c2).pow(2.0))
26+
var q3 = a3 * exp(-((it - b3) / c3).pow(2.0))
27+
var percent = (q1 + q2 + q3).toInt()
28+
percent = max(min(percent, 100), 0)
29+
var minutes = 4.52 * percent
1530
val hours = (minutes / 60).toInt()
1631
val minutesLast = (minutes % 60).toInt()
17-
1832
return NapBattery(hours, minutesLast, percent)
1933
}
2034
}
2135
}
2236

23-
data class NapBattery(val hours: Int, val minutes: Int, val percent: Int){
37+
data class NapBattery(val hours: Int, val minutes: Int, val percent: Int) {
2438
override fun toString(): String {
2539
return "NapBattery(hours=$hours, minutes=$minutes, percent=$percent)"
2640
}

0 commit comments

Comments
 (0)