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