mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-27 17:50:57 +02:00
Lefun: Add operation status to requests
This commit is contained in:
parent
1fc2356189
commit
6c32a3a99d
@ -4,6 +4,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.lefun.LefunConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.FindDeviceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.LefunDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
|
||||
|
||||
public class FindDeviceRequest extends Request {
|
||||
public FindDeviceRequest(LefunDeviceSupport support, TransactionBuilder builder) {
|
||||
@ -28,5 +29,7 @@ public class FindDeviceRequest extends Request {
|
||||
|
||||
if (!cmd.isSuccess())
|
||||
reportFailure("Could not initiate find device");
|
||||
|
||||
operationStatus = OperationStatus.FINISHED;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.GetBatteryLev
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.LefunDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
|
||||
|
||||
public class GetBatteryLevelRequest extends Request {
|
||||
public GetBatteryLevelRequest(LefunDeviceSupport support, TransactionBuilder builder) {
|
||||
@ -43,6 +44,8 @@ public class GetBatteryLevelRequest extends Request {
|
||||
GBDevice device = getSupport().getDevice();
|
||||
device.setBatteryLevel(cmd.getBatteryLevel());
|
||||
device.setBatteryThresholdPercent((short)15);
|
||||
|
||||
operationStatus = OperationStatus.FINISHED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.GetFirmwareIn
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.LefunDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
|
||||
|
||||
public class GetFirmwareInfoRequest extends Request {
|
||||
public GetFirmwareInfoRequest(LefunDeviceSupport support, TransactionBuilder builder) {
|
||||
@ -48,6 +49,8 @@ public class GetFirmwareInfoRequest extends Request {
|
||||
device.setFirmwareVersion(String.format("%d.%d", softwareVersion >> 8, softwareVersion & 0xff));
|
||||
device.setFirmwareVersion2(String.format("%d.%d", hardwareVersion >> 8, hardwareVersion & 0xff));
|
||||
getSupport().completeInitialization();
|
||||
|
||||
operationStatus = OperationStatus.FINISHED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.lefun.LefunConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.LefunDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
// Ripped from nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request
|
||||
@ -43,17 +44,23 @@ public abstract class Request extends AbstractBTLEOperation<LefunDeviceSupport>
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public TransactionBuilder getTransactionBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPerform() throws IOException {
|
||||
BluetoothGattCharacteristic characteristic = getSupport()
|
||||
.getCharacteristic(LefunConstants.UUID_CHARACTERISTIC_LEFUN_WRITE);
|
||||
builder.write(characteristic, createRequest());
|
||||
if (isSelfQueue())
|
||||
getSupport().performConnected(builder.getTransaction());
|
||||
}
|
||||
|
||||
public abstract byte[] createRequest();
|
||||
|
||||
public void handleResponse(byte[] data) {
|
||||
|
||||
operationStatus = OperationStatus.FINISHED;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -68,6 +75,10 @@ public abstract class Request extends AbstractBTLEOperation<LefunDeviceSupport>
|
||||
|
||||
public abstract int getCommandId();
|
||||
|
||||
public boolean isSelfQueue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean expectsResponse() {
|
||||
return true;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.BaseCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.TimeCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.LefunDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
|
||||
|
||||
public class SetTimeRequest extends Request {
|
||||
public SetTimeRequest(LefunDeviceSupport support, TransactionBuilder builder) {
|
||||
@ -39,7 +40,7 @@ public class SetTimeRequest extends Request {
|
||||
|
||||
cmd.setOp(BaseCommand.OP_SET);
|
||||
cmd.setYear((byte)(c.get(Calendar.YEAR) - 2000));
|
||||
cmd.setMonth((byte)c.get(Calendar.MONTH));
|
||||
cmd.setMonth((byte)(c.get(Calendar.MONTH) + 1));
|
||||
cmd.setDay((byte)c.get(Calendar.DAY_OF_MONTH));
|
||||
cmd.setHour((byte)c.get(Calendar.HOUR_OF_DAY));
|
||||
cmd.setMinute((byte)c.get(Calendar.MINUTE));
|
||||
@ -54,6 +55,8 @@ public class SetTimeRequest extends Request {
|
||||
cmd.deserialize(data);
|
||||
if (cmd.getOp() == BaseCommand.OP_SET && !cmd.isSetSuccess())
|
||||
reportFailure("Could not set time");
|
||||
|
||||
operationStatus = OperationStatus.FINISHED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user