Search in sources :

Example 1 with GetBatteryLevelRequest

use of nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.GetBatteryLevelRequest 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)

Aggregations

IOException (java.io.IOException)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 SetTimeRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.lefun.requests.SetTimeRequest)1