HPlus: Improve reconnection to device

This commit is contained in:
João Paulo Barraca 2017-04-27 00:19:59 +01:00
parent 58cb73a756
commit c9da7548ed
2 changed files with 14 additions and 16 deletions

View File

@ -123,6 +123,10 @@ class HPlusHandlerThread extends GBDeviceIoThread {
break; break;
} }
if(gbDevice.getState() == GBDevice.State.NOT_CONNECTED){
quit();
}
Calendar now = GregorianCalendar.getInstance(); Calendar now = GregorianCalendar.getInstance();
if (now.compareTo(mGetDaySlotsTime) > 0) { if (now.compareTo(mGetDaySlotsTime) > 0) {
@ -138,7 +142,6 @@ class HPlusHandlerThread extends GBDeviceIoThread {
} }
if(now.compareTo(mHelloTime) > 0){ if(now.compareTo(mHelloTime) > 0){
LOG.info("Sending hello");
sendHello(); sendHello();
} }
@ -155,10 +158,6 @@ class HPlusHandlerThread extends GBDeviceIoThread {
synchronized (waitObject) { synchronized (waitObject) {
waitObject.notify(); waitObject.notify();
} }
StackTraceElement l[] = Thread.currentThread().getStackTrace();
for(StackTraceElement e: l){
LOG.warn(e.toString());
}
} }

View File

@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
@ -59,9 +60,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -91,7 +90,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
public HPlusSupport(DeviceType type) { public HPlusSupport(DeviceType type) {
super(LOG); super(LOG);
LOG.info("HPlusSupport Instance Created");
deviceType = type; deviceType = type;
addSupportedService(HPlusConstants.UUID_SERVICE_HP); addSupportedService(HPlusConstants.UUID_SERVICE_HP);
@ -117,26 +116,26 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
protected TransactionBuilder initializeDevice(TransactionBuilder builder) { protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
LOG.info("Initializing"); LOG.info("Initializing");
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext())); gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
measureCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE); measureCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE);
ctrlCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_CONTROL); ctrlCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_CONTROL);
//Initialize device
sendUserInfo(builder); //Sync preferences
builder.notify(getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE), true); builder.notify(getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE), true);
builder.setGattCallback(this); builder.setGattCallback(this);
builder.notify(measureCharacteristic, true); builder.notify(measureCharacteristic, true);
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext())); //Initialize device
sendUserInfo(builder); //Sync preferences
if(syncHelper != null){ gbDevice.setState(GBDevice.State.INITIALIZED);
syncHelper.setHPlusSupport(this); gbDevice.sendDeviceUpdateIntent(getContext());
}else {
if(syncHelper == null) {
syncHelper = new HPlusHandlerThread(getDevice(), getContext(), this); syncHelper = new HPlusHandlerThread(getDevice(), getContext(), this);
syncHelper.start(); syncHelper.start();
} }
syncHelper.sync(); syncHelper.sync();
getDevice().setFirmwareVersion("N/A"); getDevice().setFirmwareVersion("N/A");