Search in sources :

Example 1 with SetTimeRequest

use of nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.SetTimeRequest in project Gadgetbridge by Freeyourgadget.

the class LefunDeviceSupport method initializeDevice.

@Override
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
    builder.setGattCallback(this);
    builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
    // Enable notification
    builder.notify(getCharacteristic(LefunConstants.UUID_CHARACTERISTIC_LEFUN_NOTIFY), true);
    // Init device (get version info, battery level, and set time)
    try {
        GetFirmwareInfoRequest firmwareReq = new GetFirmwareInfoRequest(this, builder);
        firmwareReq.perform();
        inProgressRequests.add(firmwareReq);
        SetTimeRequest timeReq = new SetTimeRequest(this, builder);
        timeReq.perform();
        inProgressRequests.add(timeReq);
        GetBatteryLevelRequest batReq = new GetBatteryLevelRequest(this, builder);
        batReq.perform();
        inProgressRequests.add(batReq);
        sendAmPmSettingIfNecessary(builder);
        sendUnitsSetting(builder);
        sendUserProfile(builder);
    } catch (IOException e) {
        GB.toast(getContext(), "Failed to initialize Lefun device", Toast.LENGTH_SHORT, GB.ERROR, e);
    }
    return builder;
}
Also used : SetTimeRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.SetTimeRequest) GetBatteryLevelRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.GetBatteryLevelRequest) IOException(java.io.IOException) GetFirmwareInfoRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.GetFirmwareInfoRequest) SetDeviceStateAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction)

Example 2 with SetTimeRequest

use of nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.SetTimeRequest in project Gadgetbridge by Freeyourgadget.

the class LefunDeviceSupport method onSetTime.

@Override
public void onSetTime() {
    try {
        TransactionBuilder builder = performInitialized(SetTimeRequest.class.getSimpleName());
        SetTimeRequest request = new SetTimeRequest(this, builder);
        request.perform();
        inProgressRequests.add(request);
        performConnected(builder.getTransaction());
    } catch (IOException e) {
        GB.toast(getContext(), "Failed to set time", Toast.LENGTH_SHORT, GB.ERROR, e);
    }
}
Also used : SetTimeRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.SetTimeRequest) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 SetTimeRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.SetTimeRequest)2 TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)1 SetDeviceStateAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction)1 GetBatteryLevelRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.GetBatteryLevelRequest)1 GetFirmwareInfoRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.GetFirmwareInfoRequest)1