1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

Cleanup according to PR Review

This commit is contained in:
João Paulo Barraca 2016-12-23 01:21:05 +00:00
parent b7cd908fbe
commit 2b78f2708f
4 changed files with 329 additions and 326 deletions

View File

@ -71,6 +71,7 @@ public final class HPlusConstants {
public static final byte DATA_STATS = 0x33;
public static final byte DATA_STEPS = 0x36;
public static final byte DATA_SLEEP = 0x1A;
public static final byte COMMAND_ACTION_INCOMING_SOCIAL = 0x31;
@ -78,8 +79,6 @@ public final class HPlusConstants {
public static final byte COMMAND_ACTION_DISPLAY_TEXT = 0x43;
public static final String PREF_HPLUS_USER_ALIAS = "hplus_user_alias";
public static final String PREF_HPLUS_FITNESS_GOAL = "hplus_fitness_goal";
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";
public static final String PREF_HPLUS_ALLDAYHR = "hplus_alldayhr";
public static final String PREF_HPLUS_UNIT = "hplus_unit";

View File

@ -141,8 +141,9 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static int getFitnessGoal(String address) throws IllegalArgumentException {
Prefs prefs = GBApplication.getPrefs();
return prefs.getInt(HPlusConstants.PREF_HPLUS_FITNESS_GOAL + "_" + address, 10000);
ActivityUser activityUser = new ActivityUser();
return activityUser.getStepsGoal();
}
public static byte getCountry(String address) {
@ -161,28 +162,25 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
public static byte getUserWeight(String address) {
ActivityUser activityUser = new ActivityUser();
return (byte) activityUser.getWeightKg();
return (byte) (activityUser.getWeightKg() & 0xFF);
}
public static byte getUserHeight(String address) {
ActivityUser activityUser = new ActivityUser();
return (byte) activityUser.getHeightCm();
return (byte) (activityUser.getHeightCm() & 0xFF);
}
public static byte getUserAge(String address) {
ActivityUser activityUser = new ActivityUser();
return (byte) activityUser.getAge();
return (byte) (activityUser.getAge() & 0xFF);
}
public static byte getUserSex(String address) {
ActivityUser activityUser = new ActivityUser();
int gender = activityUser.getGender();
return (byte) gender;
return (byte) (activityUser.getGender() & 0xFF);
}
public static int getGoal(String address) {
@ -192,46 +190,37 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static byte getScreenTime(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_SCREENTIME + "_" + address, 5);
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_SCREENTIME + "_" + address, 5) & 0xFF);
}
public static byte getAllDayHR(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_ALLDAYHR + "_" + address, 10);
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_ALLDAYHR + "_" + address, 10) & 0xFF);
}
public static byte getSocial(String address) {
//TODO: Figure what this is. Returning the default value
return (byte) 255;
}
public static byte getUserWrist(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_WRIST + "_" + address, 10);
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_WRIST + "_" + address, 10) & 0xFF);
}
public static boolean getSWAlertTime(String address) {
return prefs.getBoolean(HPlusConstants.PREF_HPLUS_SWALERT + "_" + address, false);
}
public static int getAlertTime(String address) {
return prefs.getInt(HPlusConstants.PREF_HPLUS_ALERT_TIME + "_" + address, 0);
}
public static int getSITStartTime(String address) {
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_START_TIME + "_" + address, 0);
}
public static int getSITEndTime(String address) {
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_END_TIME + "_" + address, 0);
}
}

View File

@ -48,32 +48,6 @@ public class HPlusSampleProvider extends AbstractSampleProvider<HPlusHealthActiv
return activityKind;
}
@Override
public List<HPlusHealthActivitySample> getAllActivitySamples(int timestamp_from, int timestamp_to) {
List<HPlusHealthActivitySample> samples = super.getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL);
Device dbDevice = DBHelper.findDevice(getDevice(), getSession());
if (dbDevice == null) {
// no device, no samples
return Collections.emptyList();
}
QueryBuilder<HPlusHealthActivitySample> qb = getSession().getHPlusHealthActivitySampleDao().queryBuilder();
qb.where(HPlusHealthActivitySampleDao.Properties.DeviceId.eq(dbDevice.getId()), HPlusHealthActivitySampleDao.Properties.Timestamp.ge(timestamp_from))
.where(HPlusHealthActivitySampleDao.Properties.Timestamp.le(timestamp_to));
List<HPlusHealthActivitySample> sampleList = qb.build().list();
for (HPlusHealthActivitySample sample : sampleList) {
if (timestamp_from <= sample.getTimestamp() && sample.getTimestamp() < timestamp_to) {
sample.setRawKind(sample.getRawKind());
}
}
detachFromSession();
return samples;
}
@NonNull
@Override
protected de.greenrobot.dao.Property getTimestampSampleProperty() {

View File

@ -7,17 +7,18 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.support.v4.content.LocalBroadcastManager;
import android.widget.Toast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.UUID;
@ -35,14 +36,13 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
@ -50,9 +50,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSuppo
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class HPlusSupport extends AbstractBTLEDeviceSupport {
@ -110,10 +110,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
builder.notify(getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE), true);
UUID uuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
BluetoothGattDescriptor descriptor = measureCharacteristic.getDescriptor(uuid);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
builder.setGattCallback(this);
builder.notify(measureCharacteristic, true);
@ -123,6 +119,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setInitValues(TransactionBuilder builder) {
LOG.debug("Set Init Values");
builder.write(ctrlCharacteristic, HPlusConstants.COMMAND_SET_INIT1);
builder.write(ctrlCharacteristic, HPlusConstants.COMMAND_SET_INIT2);
return this;
@ -141,9 +138,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport syncPreferences(TransactionBuilder transaction) {
LOG.info("Attempting to sync preferences...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte sex = HPlusCoordinator.getUserSex(getDevice().getAddress());
byte age = HPlusCoordinator.getUserAge(getDevice().getAddress());
@ -161,14 +155,14 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
if (HPlusCoordinator.getSWAlertTime(getDevice().getAddress())) {
int t = HPlusCoordinator.getAlertTime(getDevice().getAddress());
alertTimeHour = (byte) (t / 256);
alertTimeHour = (byte) ((t / 256) & 0xff);
alertTimeMinute = (byte) (t % 256);
}
byte unit = HPlusCoordinator.getUnit(getDevice().getAddress());
byte timemode = HPlusCoordinator.getTimeMode((getDevice().getAddress()));
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_COUNTRY,
sex,
age,
@ -176,7 +170,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
bodyWeight,
0,
0,
(byte) (goal / 256),
(byte) ((goal / 256) & 0xff),
(byte) (goal % 256),
displayTime,
country,
@ -188,24 +182,17 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
alertTimeMinute,
unit,
timemode
};
}
});
return this;
}
private HPlusSupport setCountry(TransactionBuilder transaction) {
LOG.info("Attempting to set country...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getCountry(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_COUNTRY,
(byte) value
};
}
value
});
return this;
}
@ -213,73 +200,57 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setTimeMode(TransactionBuilder transaction) {
LOG.info("Attempting to set Time Mode...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getTimeMode(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_TIMEMODE,
(byte) value
};
}
value
});
return this;
}
private HPlusSupport setUnit(TransactionBuilder transaction) {
LOG.info("Attempting to set Units...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getUnit(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_UNIT,
(byte) value
};
}
value
});
return this;
}
private HPlusSupport setCurrentDate(TransactionBuilder transaction) {
LOG.info("Attempting to set Current Date...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR) - 1900;
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_DATE,
(byte) (year / 256),
(byte) ((year / 256) & 0xff),
(byte) (year % 256),
(byte) (month),
(byte) (day)
};
}
});
return this;
}
private HPlusSupport setCurrentTime(TransactionBuilder transaction) {
LOG.info("Attempting to set Current Time...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
Calendar c = Calendar.getInstance();
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_TIME,
(byte) c.get(Calendar.HOUR_OF_DAY),
(byte) c.get(Calendar.MINUTE),
(byte) c.get(Calendar.SECOND)
};
}
});
return this;
}
@ -287,16 +258,12 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setDayOfWeek(TransactionBuilder transaction) {
LOG.info("Attempting to set Day Of Week...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
Calendar c = Calendar.getInstance();
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_WEEK,
(byte) c.get(Calendar.DAY_OF_WEEK)
};
}
});
return this;
}
@ -304,23 +271,21 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setSIT(TransactionBuilder transaction) {
LOG.info("Attempting to set SIT...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
int startTime = HPlusCoordinator.getSITStartTime(getDevice().getAddress());
int endTime = HPlusCoordinator.getSITEndTime(getDevice().getAddress());
Calendar now = Calendar.getInstance();
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_SIT_INTERVAL,
(byte) (startTime / 256),
(byte) ((startTime / 256) & 0xff),
(byte) (startTime % 256),
(byte) (endTime / 256),
(byte) ((endTime / 256) & 0xff),
(byte) (endTime % 256),
0,
0,
(byte) (now.get(Calendar.YEAR) / 256),
(byte) ((now.get(Calendar.YEAR) / 256) & 0xff),
(byte) (now.get(Calendar.YEAR) % 256),
(byte) (now.get(Calendar.MONTH) + 1),
(byte) (now.get(Calendar.DAY_OF_MONTH)),
@ -331,40 +296,31 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
0,
0,
0
};
}
});
return this;
}
private HPlusSupport setWeight(TransactionBuilder transaction) {
LOG.info("Attempting to set Weight...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getUserWeight(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_WEIGHT,
(byte) value
};
}
value
});
return this;
}
private HPlusSupport setHeight(TransactionBuilder transaction) {
LOG.info("Attempting to set Height...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getUserHeight(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_HEIGHT,
(byte) value
};
}
value
});
return this;
}
@ -372,32 +328,24 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setAge(TransactionBuilder transaction) {
LOG.info("Attempting to set Age...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getUserAge(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_AGE,
(byte) value
};
}
value
});
return this;
}
private HPlusSupport setSex(TransactionBuilder transaction) {
LOG.info("Attempting to set Sex...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getUserSex(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_SEX,
(byte) value
};
}
value
});
return this;
}
@ -405,17 +353,13 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setGoal(TransactionBuilder transaction) {
LOG.info("Attempting to set Sex...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
int value = HPlusCoordinator.getGoal(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_GOAL,
(byte) (value / 256),
(byte) ((value / 256) & 0xff),
(byte) (value % 256)
};
}
});
return this;
}
@ -423,32 +367,24 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setScreenTime(TransactionBuilder transaction) {
LOG.info("Attempting to set Screentime...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getScreenTime(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_SCREENTIME,
(byte) value
};
}
value
});
return this;
}
private HPlusSupport setAllDayHeart(TransactionBuilder transaction) {
LOG.info("Attempting to set All Day HR...");
transaction.add(new ConditionalWriteAction(ctrlCharacteristic) {
@Override
protected byte[] checkCondition() {
byte value = HPlusCoordinator.getAllDayHR(getDevice().getAddress());
return new byte[]{
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.COMMAND_SET_PREF_ALLDAYHR,
(byte) value
};
}
value
});
return this;
}
@ -456,17 +392,20 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setAlarm(TransactionBuilder transaction) {
LOG.info("Attempting to set Alarm...");
//TODO: Find how to set alarms
return this;
}
private HPlusSupport setBlood(TransactionBuilder transaction) {
LOG.info("Attempting to set Blood...");
//TODO: Find what blood means for the band
return this;
}
private HPlusSupport setFindMe(TransactionBuilder transaction) {
LOG.info("Attempting to set Findme...");
//TODO: Find how this works
return this;
}
@ -499,16 +438,16 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
@Override
public void onNotification(NotificationSpec notificationSpec) {
LOG.debug("Got Notification");
//TODO: Show different notifications acccording to source as Band supports this
showText(notificationSpec.body);
}
@Override
public void onSetTime() {
TransactionBuilder builder = new TransactionBuilder("vibration");
TransactionBuilder builder = new TransactionBuilder("time");
setCurrentDate(builder);
setCurrentTime(builder);
}
@Override
@ -594,11 +533,9 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
getQueue().clear();
TransactionBuilder builder = new TransactionBuilder("HeartRateTest");
byte state = 0;
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.COMMAND_SET_PREF_ALLDAYHR, 0x10}); //Set Real Time... ?
builder.queue(getQueue());
}
@Override
@ -608,7 +545,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
getQueue().clear();
TransactionBuilder builder = new TransactionBuilder("realTimeHeartMeasurement");
byte state = 0;
byte state;
if (enable)
state = HPlusConstants.HEARTRATE_ALLDAY_ON;
@ -623,10 +560,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
public void onFindDevice(boolean start) {
LOG.debug("Find Me");
getQueue().clear();
ctrlCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_CONTROL);
TransactionBuilder builder = new TransactionBuilder("findMe");
try {
TransactionBuilder builder = performInitialized("findMe");
byte[] msg = new byte[2];
msg[0] = HPlusConstants.COMMAND_SET_PREF_FINDME;
@ -635,8 +570,13 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
msg[1] = 1;
else
msg[1] = 0;
builder.write(ctrlCharacteristic, msg);
builder.queue(getQueue());
} catch (IOException e) {
GB.toast(getContext(), "Error toogling Find Me: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
@Override
@ -645,9 +585,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
getQueue().clear();
ctrlCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_CONTROL);
TransactionBuilder builder = new TransactionBuilder("vibration");
try {
TransactionBuilder builder = performInitialized("vibration");
byte[] msg = new byte[15];
msg[0] = HPlusConstants.COMMAND_SET_DISPLAY_ALERT;
@ -657,6 +596,9 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, msg);
builder.queue(getQueue());
} catch (IOException e) {
GB.toast(getContext(), "Error setting Vibration: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
@Override
@ -688,7 +630,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
@Override
public void onTestNewFunction() {
LOG.debug("Test New Function");
}
@ -699,9 +640,9 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private void showText(String title, String body) {
LOG.debug("Show Notification");
TransactionBuilder builder = new TransactionBuilder("showText");
if (ctrlCharacteristic == null)
ctrlCharacteristic = getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_CONTROL);
try {
TransactionBuilder builder = performInitialized("notification");
byte[] msg = new byte[20];
for (int i = 0; i < msg.length; i++)
@ -726,7 +667,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.COMMAND_ACTION_INCOMING_SOCIAL, (byte) 255});
int remaining = 0;
int remaining;
if (message.length() % 17 > 0)
remaining = length + 1;
@ -760,6 +701,10 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, msg);
builder.queue(getQueue());
}catch(IOException e){
GB.toast(getContext(), "Error showing device Notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
public boolean isExpectedDevice(BluetoothDevice device) {
@ -786,6 +731,9 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
return processDataStats(data);
case HPlusConstants.DATA_SLEEP:
return processSleepStats(data);
case HPlusConstants.DATA_STEPS:
return processStepStats(data);
default:
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
@ -793,6 +741,99 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
return false;
}
/*
Receives a message containing the status of the day.
*/
private boolean processDayStats(byte[] data) {
int a = data[4] * 256 + data[5];
if (a < 144) {
int slot = a * 2; // 10 minute slots as an offset from 0:00 AM
int avgHR = data[1]; //Average Heart Rate
int steps = data[2] * 256 + data[3]; // Steps in this period
//?? data[6];
int timeInactive = data[7];
LOG.debug("Day Stats: Slot: " + slot + " HR: " + avgHR + " Steps: " + steps + " TimeInactive: " + timeInactive);
try (DBHandler handler = GBApplication.acquireDB()) {
DaoSession session = handler.getDaoSession();
Device device = DBHelper.getDevice(getDevice(), session);
User user = DBHelper.getUser(session);
int ts = (int) (System.currentTimeMillis() / 1000);
HPlusSampleProvider provider = new HPlusSampleProvider(gbDevice, session);
//TODO: Store Sample. How?
//provider.addGBActivitySample(record);
} catch (GBException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} else
LOG.error("Invalid day stats");
return true;
}
private boolean processStepStats(byte[] data) {
LOG.debug("Process Step Stats");
if (data.length < 19) {
LOG.error("Invalid Steps Message Length " + data.length);
return false;
}
/*
This is a dump of the entire day.
*/
int year = data[9] + data[10] * 256;
short month = data[11];
short day = data[12];
int steps = data[2] * 256 + data[1];
float distance = ((float) (data[3] + data[4] * 256) / 100.0f);
/*
unknown fields
short s12 = (short)(data[5] + data[6] * 256);
short s13 = (short)(data[7] + data[8] * 256);
short s16 = (short)(data[13]) + data[14] * 256);
short s17 = data[15];
short s18 = data[16];
*/
LOG.debug("Step Stats: Year: " + year + " Month: " + month + " Day:");
try (DBHandler handler = GBApplication.acquireDB()) {
DaoSession session = handler.getDaoSession();
Device device = DBHelper.getDevice(getDevice(), session);
User user = DBHelper.getUser(session);
int ts = (int) (System.currentTimeMillis() / 1000);
HPlusSampleProvider provider = new HPlusSampleProvider(gbDevice, session);
//TODO: Store Sample. How?
//provider.addGBActivitySample(record);
} catch (GBException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
private boolean processSleepStats(byte[] data) {
LOG.debug("Process Sleep Stats");
@ -856,7 +897,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
sample.setHeartRate(bpm);
sample.setSteps(0);
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
sample.setRawKind(HPlusSampleProvider.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
sample.setRawKind(ActivityKind.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
provider.addGBActivitySample(sample);
}
} catch (GBException e) {