HPlus: Improve reconnection to device

master
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;
}
if(gbDevice.getState() == GBDevice.State.NOT_CONNECTED){
quit();
}
Calendar now = GregorianCalendar.getInstance();
if (now.compareTo(mGetDaySlotsTime) > 0) {
@ -138,7 +142,6 @@ class HPlusHandlerThread extends GBDeviceIoThread {
}
if(now.compareTo(mHelloTime) > 0){
LOG.info("Sending hello");
sendHello();
}
@ -155,10 +158,6 @@ class HPlusHandlerThread extends GBDeviceIoThread {
synchronized (waitObject) {
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.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
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.WeatherSpec;
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.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -91,7 +90,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
public HPlusSupport(DeviceType type) {
super(LOG);
LOG.info("HPlusSupport Instance Created");
deviceType = type;
addSupportedService(HPlusConstants.UUID_SERVICE_HP);
@ -117,26 +116,26 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
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);
ctrlCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_CONTROL);
//Initialize device
sendUserInfo(builder); //Sync preferences
builder.notify(getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE), true);
builder.setGattCallback(this);
builder.notify(measureCharacteristic, true);
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
//Initialize device
sendUserInfo(builder); //Sync preferences
if(syncHelper != null){
syncHelper.setHPlusSupport(this);
}else {
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
if(syncHelper == null) {
syncHelper = new HPlusHandlerThread(getDevice(), getContext(), this);
syncHelper.start();
}
syncHelper.sync();
getDevice().setFirmwareVersion("N/A");