Search in sources :

Example 1 with DeviceType

use of nodomain.freeyourgadget.gadgetbridge.model.DeviceType in project Gadgetbridge by Freeyourgadget.

the class DiscoveryActivity method handleDeviceFound.

private void handleDeviceFound(BluetoothDevice device, short rssi, ParcelUuid[] uuids) {
    LOG.debug("found device: " + device.getName() + ", " + device.getAddress());
    if (LOG.isDebugEnabled()) {
        if (uuids != null && uuids.length > 0) {
            for (ParcelUuid uuid : uuids) {
                LOG.debug("  supports uuid: " + uuid.toString());
            }
        }
    }
    if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
        // ignore already bonded devices
        return;
    }
    GBDeviceCandidate candidate = new GBDeviceCandidate(device, rssi, uuids);
    DeviceType deviceType = DeviceHelper.getInstance().getSupportedType(candidate);
    if (deviceType.isSupported()) {
        candidate.setDeviceType(deviceType);
        LOG.info("Recognized supported device: " + candidate);
        int index = deviceCandidates.indexOf(candidate);
        if (index >= 0) {
            // replace
            deviceCandidates.set(index, candidate);
        } else {
            deviceCandidates.add(candidate);
        }
        cadidateListAdapter.notifyDataSetChanged();
    }
}
Also used : ParcelUuid(android.os.ParcelUuid) DeviceType(nodomain.freeyourgadget.gadgetbridge.model.DeviceType) GBDeviceCandidate(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate)

Example 2 with DeviceType

use of nodomain.freeyourgadget.gadgetbridge.model.DeviceType in project Gadgetbridge by Freeyourgadget.

the class DeviceHelper method toGBDevice.

/**
     * Converts a known device from the database to a GBDevice.
     * Note: The device might not be supported anymore, so callers should verify that.
     * @param dbDevice
     * @return
     */
public GBDevice toGBDevice(Device dbDevice) {
    DeviceType deviceType = DeviceType.fromKey(dbDevice.getType());
    GBDevice gbDevice = new GBDevice(dbDevice.getIdentifier(), dbDevice.getName(), deviceType);
    List<DeviceAttributes> deviceAttributesList = dbDevice.getDeviceAttributesList();
    if (deviceAttributesList.size() > 0) {
        gbDevice.setModel(dbDevice.getModel());
        DeviceAttributes attrs = deviceAttributesList.get(0);
        gbDevice.setFirmwareVersion(attrs.getFirmwareVersion1());
        gbDevice.setFirmwareVersion2(attrs.getFirmwareVersion2());
        gbDevice.setVolatileAddress(attrs.getVolatileIdentifier());
    }
    return gbDevice;
}
Also used : DeviceType(nodomain.freeyourgadget.gadgetbridge.model.DeviceType) DeviceAttributes(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Aggregations

DeviceType (nodomain.freeyourgadget.gadgetbridge.model.DeviceType)2 ParcelUuid (android.os.ParcelUuid)1 DeviceAttributes (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1 GBDeviceCandidate (nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate)1