Skip to content

Commit

Permalink
Fine-adjust battery level
Browse files Browse the repository at this point in the history
  • Loading branch information
izivkov committed Sep 17, 2023
1 parent 6cd057a commit d55ec2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions api/src/main/java/org/avmedia/gshockapi/io/WatchConditionIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import kotlinx.coroutines.CompletableDeferred
import org.avmedia.gshockapi.WatchInfo
import org.avmedia.gshockapi.utils.Utils
import org.json.JSONObject
import timber.log.Timber
import kotlin.math.roundToInt

object WatchConditionIO {

Expand Down Expand Up @@ -50,11 +52,14 @@ object WatchConditionIO {
val bytes = Utils.byteArrayOfIntArray(intArr.drop(1).toIntArray())

if (bytes.size >= 2) {
// Battery level between 15 and 20 fot B2100 and between 13 and 18 for B5600. Scale accordingly to %
val batteryLevel =
bytes[0].toInt() - if (WatchInfo.model == WatchInfo.WATCH_MODEL.GA) 15 else 13

val batteryLevelPercent: Int = (batteryLevel * 20).coerceIn(0, 100)
// Battery level between 15 and 20 fot B2100 and between 13 and 19 for B5600. Scale accordingly to %
Timber.i("battery level row value: ${bytes[0].toInt()}")

val batteryLevelLowerLimit = if (WatchInfo.model == WatchInfo.WATCH_MODEL.GA) 15 else 13
val batteryLevelUpperLimit = if (WatchInfo.model == WatchInfo.WATCH_MODEL.GA) 20 else 19
val multiplier:Int = (100.0 / (batteryLevelUpperLimit - batteryLevelLowerLimit)).roundToInt()
val batteryLevel = (bytes[0].toInt() - batteryLevelLowerLimit)
val batteryLevelPercent: Int = (batteryLevel * multiplier).coerceIn(0, 100)
val temperature: Int = bytes[1].toInt()

return WatchConditionValue(batteryLevelPercent, temperature)
Expand Down

0 comments on commit d55ec2a

Please sign in to comment.