1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-12 10:55:49 +01:00

Lefun: Use proper handlers for find phone and battery level

This commit is contained in:
Yukai Li 2020-10-05 06:17:42 -06:00 committed by Gitea
parent e220acb1b4
commit a2090eeccb
2 changed files with 9 additions and 3 deletions

View File

@ -42,6 +42,7 @@ import de.greenrobot.dao.query.Query;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.LefunConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.FindPhoneCommand;
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.GetActivityDataCommand;
@ -475,8 +476,9 @@ public class LefunDeviceSupport extends AbstractBTLEDeviceSupport {
try {
FindPhoneCommand cmd = new FindPhoneCommand();
cmd.deserialize(data);
// TODO: actually pop something that makes sound
GB.toast("Your device is trying to find your phone", Toast.LENGTH_LONG, GB.INFO);
GBDeviceEventFindPhone event = new GBDeviceEventFindPhone();
event.event = GBDeviceEventFindPhone.Event.START;
evaluateGBDeviceEvent(event);
return true;
} catch (IllegalArgumentException e) {
LOG.error("Failed to handle anti-loss", e);

View File

@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.LefunConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.GetBatteryLevelCommand;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -42,9 +43,12 @@ public class GetBatteryLevelRequest extends Request {
cmd.deserialize(data);
GBDevice device = getSupport().getDevice();
device.setBatteryLevel(cmd.getBatteryLevel());
device.setBatteryThresholdPercent((short)15);
GBDeviceEventBatteryInfo batteryInfo = new GBDeviceEventBatteryInfo();
batteryInfo.level = (short)((int)cmd.getBatteryLevel() & 0xff);
getSupport().evaluateGBDeviceEvent(batteryInfo);
operationStatus = OperationStatus.FINISHED;
}