2017-03-10 14:53:19 +01:00
|
|
|
/* Copyright (C) 2015-2017 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
|
|
|
Gobbetti
|
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-08-03 23:51:53 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
|
2015-04-19 22:20:47 +02:00
|
|
|
|
2015-08-18 17:37:51 +02:00
|
|
|
import java.util.GregorianCalendar;
|
|
|
|
|
2015-08-28 10:40:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
2015-08-27 11:50:31 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
2015-05-01 01:26:12 +02:00
|
|
|
|
2015-04-19 22:20:47 +02:00
|
|
|
public class BatteryInfo extends AbstractInfo {
|
2015-08-21 08:41:57 +02:00
|
|
|
public static final byte DEVICE_BATTERY_NORMAL = 0;
|
|
|
|
public static final byte DEVICE_BATTERY_LOW = 1;
|
|
|
|
public static final byte DEVICE_BATTERY_CHARGING = 2;
|
|
|
|
public static final byte DEVICE_BATTERY_CHARGING_FULL = 3;
|
|
|
|
public static final byte DEVICE_BATTERY_CHARGE_OFF = 4;
|
2015-09-24 14:45:21 +02:00
|
|
|
|
2015-04-19 22:20:47 +02:00
|
|
|
public BatteryInfo(byte[] data) {
|
|
|
|
super(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLevelInPercent() {
|
|
|
|
if (mData.length >= 1) {
|
|
|
|
return mData[0];
|
|
|
|
}
|
|
|
|
return 50; // actually unknown
|
|
|
|
}
|
|
|
|
|
2015-08-21 08:41:57 +02:00
|
|
|
public BatteryState getState() {
|
2015-04-19 22:20:47 +02:00
|
|
|
if (mData.length >= 10) {
|
|
|
|
int value = mData[9];
|
|
|
|
switch (value) {
|
2015-08-21 08:41:57 +02:00
|
|
|
case DEVICE_BATTERY_NORMAL:
|
|
|
|
return BatteryState.BATTERY_NORMAL;
|
|
|
|
case DEVICE_BATTERY_LOW:
|
|
|
|
return BatteryState.BATTERY_LOW;
|
|
|
|
case DEVICE_BATTERY_CHARGING:
|
|
|
|
return BatteryState.BATTERY_CHARGING;
|
|
|
|
case DEVICE_BATTERY_CHARGING_FULL:
|
|
|
|
return BatteryState.BATTERY_CHARGING_FULL;
|
|
|
|
case DEVICE_BATTERY_CHARGE_OFF:
|
|
|
|
return BatteryState.BATTERY_NOT_CHARGING_FULL;
|
2015-04-19 22:20:47 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-21 08:41:57 +02:00
|
|
|
return BatteryState.UNKNOWN;
|
2015-04-19 22:20:47 +02:00
|
|
|
}
|
2015-08-18 17:37:51 +02:00
|
|
|
|
|
|
|
public GregorianCalendar getLastChargeTime() {
|
2015-09-19 21:54:01 +02:00
|
|
|
GregorianCalendar lastCharge = MiBandDateConverter.createCalendar();
|
2015-08-18 17:37:51 +02:00
|
|
|
|
|
|
|
if (mData.length >= 10) {
|
2015-08-28 10:40:25 +02:00
|
|
|
lastCharge = MiBandDateConverter.rawBytesToCalendar(new byte[]{
|
2015-08-27 13:12:09 +02:00
|
|
|
mData[1], mData[2], mData[3], mData[4], mData[5], mData[6]
|
|
|
|
});
|
2015-08-18 17:37:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return lastCharge;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNumCharges() {
|
|
|
|
if (mData.length >= 10) {
|
|
|
|
return ((0xff & mData[7]) | ((0xff & mData[8]) << 8));
|
|
|
|
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2015-04-19 22:20:47 +02:00
|
|
|
}
|