Search in sources :

Example 16 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class DeviceHelper method getAvailableDevices.

/**
     * Returns the list of all available devices that are supported by Gadgetbridge.
     * Note that no state is known about the returned devices. Even if one of those
     * devices is connected, it will report the default not-connected state.
     *
     * Clients interested in the "live" devices being managed should use the class
     * DeviceManager.
     * @param context
     * @return
     */
public Set<GBDevice> getAvailableDevices(Context context) {
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    Set<GBDevice> availableDevices = new LinkedHashSet<GBDevice>();
    if (btAdapter == null) {
        GB.toast(context, context.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN);
    } else if (!btAdapter.isEnabled()) {
        GB.toast(context, context.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN);
    }
    List<GBDevice> dbDevices = getDatabaseDevices();
    // these come first, as they have the most information already
    availableDevices.addAll(dbDevices);
    if (btAdapter != null) {
        List<GBDevice> bondedDevices = getBondedDevices(btAdapter);
        availableDevices.addAll(bondedDevices);
    }
    Prefs prefs = GBApplication.getPrefs();
    String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
    if (miAddr.length() > 0) {
        GBDevice miDevice = new GBDevice(miAddr, "MI", DeviceType.MIBAND);
        availableDevices.add(miDevice);
    }
    String pebbleEmuAddr = prefs.getString("pebble_emu_addr", "");
    String pebbleEmuPort = prefs.getString("pebble_emu_port", "");
    if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) {
        GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", DeviceType.PEBBLE);
        availableDevices.add(pebbleEmuDevice);
    }
    return availableDevices;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BluetoothAdapter(android.bluetooth.BluetoothAdapter) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 17 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class EntitiesTest method testDeviceAttributes.

@Test
public void testDeviceAttributes() throws Exception {
    GBDevice dummyGBDevice = createDummyGDevice("00:00:00:00:02");
    dummyGBDevice.setFirmwareVersion("1.0");
    Device deviceOld = DBHelper.getDevice(dummyGBDevice, daoSession);
    assertNotNull(deviceOld);
    List<DeviceAttributes> attrListOld = deviceOld.getDeviceAttributesList();
    assertEquals(1, attrListOld.size());
    assertEquals("1.0", attrListOld.get(0).getFirmwareVersion1());
    assertEquals("1.0", DBHelper.getDeviceAttributes(deviceOld).getFirmwareVersion1());
    // some time passes, firmware update occurs
    Thread.sleep(2 * 1000);
    dummyGBDevice.setFirmwareVersion("2.0");
    Device deviceNew = DBHelper.getDevice(dummyGBDevice, daoSession);
    assertNotNull(deviceNew);
    List<DeviceAttributes> attrListNew = deviceNew.getDeviceAttributesList();
    assertEquals(2, attrListNew.size());
    assertEquals("2.0", attrListNew.get(0).getFirmwareVersion1());
    assertEquals("1.0", attrListNew.get(1).getFirmwareVersion1());
    assertEquals("2.0", DBHelper.getDeviceAttributes(deviceNew).getFirmwareVersion1());
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) DeviceAttributes(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Test(org.junit.Test)

Example 18 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class TestBase method createDummyGDevice.

protected GBDevice createDummyGDevice(String macAddress) {
    GBDevice dummyGBDevice = new GBDevice(macAddress, "Testie", DeviceType.TEST);
    dummyGBDevice.setFirmwareVersion("1.2.3");
    dummyGBDevice.setModel("4.0");
    return dummyGBDevice;
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 19 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class MiBandPairingActivity method performApplicationLevelPair.

private void performApplicationLevelPair() {
    // just to make sure...
    GBApplication.deviceService().disconnect();
    GBDevice device = DeviceHelper.getInstance().toSupportedDevice(deviceCandidate);
    if (device != null) {
        GBApplication.deviceService().connect(device, true);
    } else {
        GB.toast(this, "Unable to connect, can't recognize the device type: " + deviceCandidate, Toast.LENGTH_LONG, GB.ERROR);
    }
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 20 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class PebblePairingActivity method getMatchingParentDeviceFromDB.

private GBDevice getMatchingParentDeviceFromDB(BluetoothDevice btDevice) {
    String expectedSuffix = btDevice.getName();
    expectedSuffix = expectedSuffix.replace("Pebble-LE ", "");
    expectedSuffix = expectedSuffix.replace("Pebble Time LE ", "");
    expectedSuffix = expectedSuffix.substring(0, 2) + ":" + expectedSuffix.substring(2);
    LOG.info("will try to find a Pebble with BT address suffix " + expectedSuffix);
    GBDevice gbDevice = null;
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        DaoSession session = dbHandler.getDaoSession();
        DeviceDao deviceDao = session.getDeviceDao();
        Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Type.eq(1), DeviceDao.Properties.Identifier.like("%" + expectedSuffix)).build();
        List<Device> devices = query.list();
        if (devices.size() == 0) {
            GB.toast("Please pair your non-LE Pebble before pairing the LE one", Toast.LENGTH_SHORT, GB.INFO);
            returnToPairingActivity();
            return null;
        } else if (devices.size() > 1) {
            GB.toast("Can not match this Pebble LE to a unique device", Toast.LENGTH_SHORT, GB.INFO);
            returnToPairingActivity();
            return null;
        }
        DeviceHelper deviceHelper = DeviceHelper.getInstance();
        gbDevice = deviceHelper.toGBDevice(devices.get(0));
        gbDevice.setVolatileAddress(btDevice.getAddress());
    } catch (Exception e) {
        GB.toast("Error retrieving devices from database", Toast.LENGTH_SHORT, GB.ERROR);
        returnToPairingActivity();
        return null;
    }
    return gbDevice;
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) BluetoothDevice(android.bluetooth.BluetoothDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DeviceHelper(nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper) DeviceDao(nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Aggregations

GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)23 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)7 BluetoothDevice (android.bluetooth.BluetoothDevice)4 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)3 DeviceAttributes (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes)3 Test (org.junit.Test)3 Intent (android.content.Intent)2 View (android.view.View)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)2 DeviceDao (nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 Uri (android.net.Uri)1 Snackbar (android.support.design.widget.Snackbar)1