convert byte and short values related to activity tracking to int

This avoids a lot of problems because java
- does not know unsigned values
- jvm and dalvic do not internally support byte and short
- sqlite does not know them either
here
Andreas Shimokawa 2016-02-29 20:54:39 +01:00
parent c4dc972804
commit ed85fd5011
42 changed files with 163 additions and 161 deletions

View File

@ -12,7 +12,6 @@ import android.view.View;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
@ -29,7 +28,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashSet;
@ -86,6 +84,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
}
public abstract String getTitle();
public boolean supportsHeartrate() {
return supportsHeartrateChart;
}
@ -447,7 +446,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
}
activityEntries.add(createBarEntry(value, i));
if (hr) {
heartrateEntries.add(createLineEntry(sample.getCustomShortValue(), i));
heartrateEntries.add(createLineEntry(sample.getCustomValue(), i));
}
String xLabel = "";

View File

@ -49,6 +49,7 @@ public class CustomBarChart extends BarChart {
/**
* Call this to set the next value for the Entry to be animated.
* Call animateY() when ready to do that.
*
* @param nextValue
*/
public void setSingleEntryYValue(float nextValue) {

View File

@ -8,7 +8,6 @@ import android.view.View;
import android.view.ViewGroup;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.PieChart;

View File

@ -6,7 +6,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.PieChart;

View File

@ -22,12 +22,12 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.DATABASE_NAME;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_INTENSITY;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_PROVIDER;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_STEPS;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TYPE;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandler {
@ -102,7 +102,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
values.put(KEY_PROVIDER, sample.getProvider().getID());
values.put(KEY_INTENSITY, sample.getRawIntensity());
values.put(KEY_STEPS, sample.getSteps());
values.put(KEY_CUSTOM_SHORT, sample.getCustomShortValue());
values.put(KEY_CUSTOM_SHORT, sample.getCustomValue());
values.put(KEY_TYPE, sample.getRawKind());
db.insert(TABLE_GBACTIVITYSAMPLES, null, values);
@ -117,9 +117,10 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
* @param intensity the sample's raw intensity value
* @param steps the sample's steps value
* @param kind the raw activity kind of the sample
* @param customShortValue
*/
@Override
public void addGBActivitySample(int timestamp, byte provider, short intensity, short steps, byte kind, short customShortValue) {
public void addGBActivitySample(int timestamp, int provider, int intensity, int steps, int kind, int customShortValue) {
if (intensity < 0) {
LOG.error("negative intensity received, ignoring");
intensity = 0;
@ -164,7 +165,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
statement.bindLong(3, activitySample.getRawIntensity());
statement.bindLong(4, activitySample.getSteps());
statement.bindLong(5, activitySample.getRawKind());
statement.bindLong(6, activitySample.getCustomShortValue());
statement.bindLong(6, activitySample.getCustomValue());
statement.execute();
}
db.setTransactionSuccessful();
@ -242,7 +243,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
}
StringBuilder builder = new StringBuilder(" and (");
byte[] dbActivityTypes = ActivityKind.mapToDBActivityTypes(activityTypes, provider);
int[] dbActivityTypes = ActivityKind.mapToDBActivityTypes(activityTypes, provider);
for (int i = 0; i < dbActivityTypes.length; i++) {
builder.append(" type=").append(dbActivityTypes[i]);
if (i + 1 < dbActivityTypes.length) {
@ -254,7 +255,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
}
@Override
public void changeStoredSamplesType(int timestampFrom, int timestampTo, byte kind, SampleProvider provider) {
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider) {
try (SQLiteDatabase db = this.getReadableDatabase()) {
String sql = "UPDATE " + TABLE_GBACTIVITYSAMPLES + " SET " + KEY_TYPE + "= ? WHERE "
+ KEY_PROVIDER + " = ? AND "

View File

@ -24,13 +24,13 @@ public interface DBHandler {
List<ActivitySample> getSleepSamples(int tsFrom, int tsTo, SampleProvider provider);
void addGBActivitySample(int timestamp, byte provider, short intensity, short steps, byte kind, short heartrate);
void addGBActivitySample(int timestamp, int provider, int intensity, int steps, int kind, int heartrate);
void addGBActivitySamples(ActivitySample[] activitySamples);
SQLiteDatabase getWritableDatabase();
void changeStoredSamplesType(int timestampFrom, int timestampTo, byte kind, SampleProvider provider);
void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider);
int fetchLatestTimestamp(SampleProvider provider);

View File

@ -2,15 +2,10 @@ package nodomain.freeyourgadget.gadgetbridge.database.schema;
import android.database.sqlite.SQLiteDatabase;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_PROVIDER;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_STEPS;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_STEPS_PER_DAY;
/**
* Adds a column "customShort" to the table "GBActivitySamples"

View File

@ -12,7 +12,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
* This interface is implemented at least once for every supported gadget device.
* It allows Gadgetbridge to generically deal with different kinds of devices
* without actually knowing the details of any device.
*
* <p/>
* Instances will be created as needed and asked whether they support a given
* device. If a coordinator answers true, it will be used to assist in handling
* the given device.
@ -22,6 +22,7 @@ public interface DeviceCoordinator {
/**
* Checks whether this candidate handles the given candidate.
*
* @param candidate
* @return true if this coordinator handles the given candidate.
*/
@ -29,6 +30,7 @@ public interface DeviceCoordinator {
/**
* Checks whether this candidate handles the given device.
*
* @param device
* @return true if this coordinator handles the given device.
*/
@ -36,6 +38,7 @@ public interface DeviceCoordinator {
/**
* Returns the kind of device type this coordinator supports.
*
* @return
*/
DeviceType getDeviceType();
@ -43,6 +46,7 @@ public interface DeviceCoordinator {
/**
* Returns the Activity class to be started in order to perform a pairing of a
* given device.
*
* @return
*/
Class<? extends Activity> getPairingActivity();
@ -50,6 +54,7 @@ public interface DeviceCoordinator {
/**
* Returns the Activity class that will be used as the primary activity
* for the given device.
*
* @return
*/
Class<? extends Activity> getPrimaryActivity();
@ -57,6 +62,7 @@ public interface DeviceCoordinator {
/**
* Returns true if activity data fetching is supported by the device
* (with this coordinator).
*
* @return
*/
boolean supportsActivityDataFetching();
@ -65,6 +71,7 @@ public interface DeviceCoordinator {
* Returns true if activity data fetching is supported AND possible at this
* very moment. This will consider the device state (being connected/disconnected/busy...)
* etc.
*
* @param device
* @return
*/
@ -72,6 +79,7 @@ public interface DeviceCoordinator {
/**
* Returns the sample provider for the device being supported.
*
* @return
*/
SampleProvider getSampleProvider();
@ -79,6 +87,7 @@ public interface DeviceCoordinator {
/**
* Finds an install handler for the given uri that can install the given
* uri on the device being managed.
*
* @param uri
* @param context
* @return the install handler or null if that uri cannot be installed on the device
@ -87,6 +96,7 @@ public interface DeviceCoordinator {
/**
* Returns true if this device/coordinator supports taking screenshots.
*
* @return
*/
boolean supportsScreenshots();

View File

@ -1,19 +1,19 @@
package nodomain.freeyourgadget.gadgetbridge.devices;
public interface SampleProvider {
byte PROVIDER_MIBAND = 0;
byte PROVIDER_PEBBLE_MORPHEUZ = 1;
byte PROVIDER_PEBBLE_GADGETBRIDGE = 2;
byte PROVIDER_PEBBLE_MISFIT = 3;
byte PROVIDER_PEBBLE_HEALTH = 4;
int PROVIDER_MIBAND = 0;
int PROVIDER_PEBBLE_MORPHEUZ = 1;
int PROVIDER_PEBBLE_GADGETBRIDGE = 2;
int PROVIDER_PEBBLE_MISFIT = 3;
int PROVIDER_PEBBLE_HEALTH = 4;
byte PROVIDER_UNKNOWN = 100;
int PROVIDER_UNKNOWN = 100;
int normalizeType(byte rawType);
int normalizeType(int rawType);
byte toRawActivityKind(int activityKind);
int toRawActivityKind(int activityKind);
float normalizeIntensity(short rawIntensity);
float normalizeIntensity(int rawIntensity);
byte getID();
int getID();
}

View File

@ -15,22 +15,22 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
private static final class UnknownSampleProvider implements SampleProvider {
@Override
public int normalizeType(byte rawType) {
public int normalizeType(int rawType) {
return ActivityKind.TYPE_UNKNOWN;
}
@Override
public byte toRawActivityKind(int activityKind) {
public int toRawActivityKind(int activityKind) {
return 0;
}
@Override
public float normalizeIntensity(short rawIntensity) {
public float normalizeIntensity(int rawIntensity) {
return 0;
}
@Override
public byte getID() {
public int getID() {
return PROVIDER_UNKNOWN;
}
}

View File

@ -23,7 +23,7 @@ public class MiBandSampleProvider implements SampleProvider {
private final float movementDivisor = 180.0f; //256.0f;
@Override
public int normalizeType(byte rawType) {
public int normalizeType(int rawType) {
switch (rawType) {
case TYPE_DEEP_SLEEP:
return ActivityKind.TYPE_DEEP_SLEEP;
@ -42,7 +42,7 @@ public class MiBandSampleProvider implements SampleProvider {
}
@Override
public byte toRawActivityKind(int activityKind) {
public int toRawActivityKind(int activityKind) {
switch (activityKind) {
case ActivityKind.TYPE_ACTIVITY:
return TYPE_ACTIVITY;
@ -59,12 +59,12 @@ public class MiBandSampleProvider implements SampleProvider {
}
@Override
public float normalizeIntensity(short rawIntensity) {
public float normalizeIntensity(int rawIntensity) {
return rawIntensity / movementDivisor;
}
@Override
public byte getID() {
public int getID() {
return SampleProvider.PROVIDER_MIBAND;
}
}

View File

@ -1,11 +1,11 @@
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
import java.util.Arrays;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.util.CheckSums;
import java.util.Arrays;
public class UserInfo {
private final String btAddress;

View File

@ -4,14 +4,14 @@ import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class HealthSampleProvider implements SampleProvider {
public static final byte TYPE_DEEP_SLEEP = 5;
public static final byte TYPE_LIGHT_SLEEP = 4;
public static final byte TYPE_ACTIVITY = -1;
public static final int TYPE_DEEP_SLEEP = 5;
public static final int TYPE_LIGHT_SLEEP = 4;
public static final int TYPE_ACTIVITY = -1;
protected final float movementDivisor = 8000f;
@Override
public int normalizeType(byte rawType) {
public int normalizeType(int rawType) {
switch (rawType) {
case TYPE_DEEP_SLEEP:
return ActivityKind.TYPE_DEEP_SLEEP;
@ -24,7 +24,7 @@ public class HealthSampleProvider implements SampleProvider {
}
@Override
public byte toRawActivityKind(int activityKind) {
public int toRawActivityKind(int activityKind) {
switch (activityKind) {
case ActivityKind.TYPE_ACTIVITY:
return TYPE_ACTIVITY;
@ -40,13 +40,13 @@ public class HealthSampleProvider implements SampleProvider {
@Override
public float normalizeIntensity(short rawIntensity) {
public float normalizeIntensity(int rawIntensity) {
return rawIntensity / movementDivisor;
}
@Override
public byte getID() {
public int getID() {
return SampleProvider.PROVIDER_PEBBLE_HEALTH;
}
}

View File

@ -7,24 +7,24 @@ public class MisfitSampleProvider implements SampleProvider {
protected final float movementDivisor = 300f;
@Override
public int normalizeType(byte rawType) {
public int normalizeType(int rawType) {
return (int) rawType;
}
@Override
public byte toRawActivityKind(int activityKind) {
public int toRawActivityKind(int activityKind) {
return (byte) activityKind;
}
@Override
public float normalizeIntensity(short rawIntensity) {
public float normalizeIntensity(int rawIntensity) {
return rawIntensity / movementDivisor;
}
@Override
public byte getID() {
public int getID() {
return SampleProvider.PROVIDER_PEBBLE_MISFIT;
}
}

View File

@ -13,7 +13,7 @@ public class MorpheuzSampleProvider implements SampleProvider {
protected float movementDivisor = 5000f;
@Override
public int normalizeType(byte rawType) {
public int normalizeType(int rawType) {
switch (rawType) {
case TYPE_DEEP_SLEEP:
return ActivityKind.TYPE_DEEP_SLEEP;
@ -28,7 +28,7 @@ public class MorpheuzSampleProvider implements SampleProvider {
}
@Override
public byte toRawActivityKind(int activityKind) {
public int toRawActivityKind(int activityKind) {
switch (activityKind) {
case ActivityKind.TYPE_ACTIVITY:
return TYPE_ACTIVITY;
@ -43,12 +43,12 @@ public class MorpheuzSampleProvider implements SampleProvider {
}
@Override
public float normalizeIntensity(short rawIntensity) {
public float normalizeIntensity(int rawIntensity) {
return rawIntensity / movementDivisor;
}
@Override
public byte getID() {
public int getID() {
return SampleProvider.PROVIDER_PEBBLE_MORPHEUZ;
}
}

View File

@ -8,7 +8,7 @@ public class PebbleGadgetBridgeSampleProvider extends MorpheuzSampleProvider {
}
@Override
public byte getID() {
public int getID() {
return SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE;
}
}

View File

@ -9,8 +9,6 @@ import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
import java.util.ArrayList;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;

View File

@ -7,21 +7,21 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public class GBActivitySample implements ActivitySample {
private final int timestamp;
private final SampleProvider provider;
private final short intensity;
private final short steps;
private final byte type;
private final short customShortValue;
private final int intensity;
private final int steps;
private final int type;
private final int customValue;
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type) {
this(provider, timestamp, intensity, steps, type, (short) 0);
public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type) {
this(provider, timestamp, intensity, steps, type, 0);
}
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type, short customShortValue) {
public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) {
this.timestamp = timestamp;
this.provider = provider;
this.intensity = intensity;
this.steps = steps;
this.customShortValue = customShortValue;
this.customValue = customValue;
this.type = type;
validate();
}
@ -36,8 +36,8 @@ public class GBActivitySample implements ActivitySample {
if (timestamp < 0) {
throw new IllegalArgumentException("timestamp must be >= 0");
}
if (customShortValue < 0) {
throw new IllegalArgumentException("customShortValue must be >= 0");
if (customValue < 0) {
throw new IllegalArgumentException("customValue must be >= 0");
}
}
@ -52,7 +52,7 @@ public class GBActivitySample implements ActivitySample {
}
@Override
public short getRawIntensity() {
public int getRawIntensity() {
return intensity;
}
@ -62,12 +62,12 @@ public class GBActivitySample implements ActivitySample {
}
@Override
public short getSteps() {
public int getSteps() {
return steps;
}
@Override
public byte getRawKind() {
public int getRawKind() {
return type;
}
@ -77,8 +77,8 @@ public class GBActivitySample implements ActivitySample {
}
@Override
public short getCustomShortValue() {
return customShortValue;
public int getCustomValue() {
return customValue;
}
@Override
@ -87,7 +87,7 @@ public class GBActivitySample implements ActivitySample {
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimeStamp(timestamp)) +
", intensity=" + getIntensity() +
", steps=" + getSteps() +
", customShortValue=" + getCustomShortValue() +
", customValue=" + getCustomValue() +
", type=" + getKind() +
'}';
}

View File

@ -14,8 +14,8 @@ public class ActivityKind {
public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP;
public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN;
public static byte[] mapToDBActivityTypes(int types, SampleProvider provider) {
byte[] result = new byte[3];
public static int[] mapToDBActivityTypes(int types, SampleProvider provider) {
int[] result = new int[3];
int i = 0;
if ((types & ActivityKind.TYPE_ACTIVITY) != 0) {
result[i++] = provider.toRawActivityKind(TYPE_ACTIVITY);

View File

@ -18,7 +18,7 @@ public interface ActivitySample {
/**
* Returns the raw activity kind value as recorded by the SampleProvider
*/
byte getRawKind();
int getRawKind();
/**
* Returns the activity kind value as recorded by the SampleProvider
@ -30,7 +30,7 @@ public interface ActivitySample {
/**
* Returns the raw intensity value as recorded by the SampleProvider
*/
short getRawIntensity();
int getRawIntensity();
/**
* Returns the normalized intensity value between 0 and 1
@ -40,7 +40,7 @@ public interface ActivitySample {
/**
* Returns the number of steps performed during the period of this sample
*/
short getSteps();
int getSteps();
short getCustomShortValue();
int getCustomValue();
}

View File

@ -1,7 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.widget.Toast;
@ -11,10 +10,8 @@ import java.util.EnumSet;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class DeviceSupportFactory {

View File

@ -36,6 +36,7 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
* Performs this operation. The whole operation is asynchronous, i.e.
* this method quickly returns before the actual operation is finished.
* Calls #prePerform() and, if successful, #doPerform().
*
* @throws IOException
*/
@Override
@ -48,6 +49,7 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
/**
* Hook for subclasses to perform something before #doPerform() is invoked.
*
* @throws IOException
*/
protected void prePerform() throws IOException {
@ -58,6 +60,7 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
* successfully.
* Note that subclasses HAVE TO call #operationFinished() when the entire
* opreation is done (successful or not).
*
* @throws IOException
*/
protected abstract void doPerform() throws IOException;
@ -65,6 +68,7 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
/**
* You MUST call this method when the operation has finished, either
* successfull or unsuccessfully.
*
* @throws IOException
*/
protected void operationFinished() throws IOException {

View File

@ -283,6 +283,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
return this;
}*/
/**
* Part of device initialization process. Do not call manually.
*
@ -531,6 +532,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
LOG.error("Unable to reboot MI", ex);
}
}
@Override
public void onHearRateTest() {
if (supportsHeartRate()) {
@ -676,8 +678,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
handleRealtimeSteps(characteristic.getValue());
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
logHeartrate(characteristic.getValue());
}
else {
} else {
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
logMessageContent(characteristic.getValue());
}

View File

@ -41,6 +41,7 @@ public abstract class AbstractMiBandOperation extends AbstractBTLEOperation<MiBa
* Enables or disables certain kinds of notifications that could interfere with this
* operation. Call this method once initially to disable other notifications, and once
* when this operation has finished.
*
* @param builder
* @param enable true to enable, false to disable the other notifications
*/

View File

@ -52,10 +52,10 @@ public class AppMessageHandlerGBPebble extends AppMessageHandler {
db = GBApplication.acquireDB();
while (samples_remaining-- > 0) {
short sample = samplesBuffer.getShort();
byte type = (byte) ((sample & 0xe000) >>> 13);
byte intensity = (byte) ((sample & 0x1f80) >>> 7);
byte steps = (byte) (sample & 0x007f);
db.addGBActivitySample(timestamp + offset_seconds, SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE, (short) (intensity & 0xff), (short) (steps & 0xff), type, (short)0);
int type = ((sample & 0xe000) >>> 13);
int intensity = ((sample & 0x1f80) >>> 7);
int steps = (sample & 0x007f);
db.addGBActivitySample(timestamp + offset_seconds, SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE, intensity, steps, type, 0);
offset_seconds += 60;
}
} catch (GBException e) {

View File

@ -75,7 +75,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
short sample = buf.getShort();
int steps = 0;
int intensity = 0;
byte activityKind = ActivityKind.TYPE_UNKNOWN;
int activityKind = ActivityKind.TYPE_UNKNOWN;
if (((sample & 0x83ff) == 0x0001) && ((sample & 0xff00) <= 0x4800)) {
// sleep seems to be from 0x2401 to 0x4801 (0b0IIIII0000000001) where I = intensity ?
@ -101,7 +101,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
totalSteps += steps;
LOG.info("got steps for sample " + i + " : " + steps + "(" + Integer.toHexString(sample & 0xffff) + ")");
activitySamples[i] = new GBActivitySample(sampleProvider, timestamp + i * 60, (short) intensity, (short) steps, activityKind);
activitySamples[i] = new GBActivitySample(sampleProvider, timestamp + i * 60, intensity, steps, activityKind);
}
LOG.info("total steps for above period: " + totalSteps);

View File

@ -1,6 +1,5 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;
import org.slf4j.Logger;

View File

@ -1,8 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.database.sqlite.SQLiteDatabase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -61,7 +59,8 @@ public class DatalogSessionHealthSteps extends DatalogSession {
for (int recordIdx = 0; recordIdx < recordNum; recordIdx++) {
datalogMessage.position(beginOfRecordPosition + recordIdx * recordLength); //we may not consume all the bytes of a record
stepsRecords[recordIdx] = new StepsRecord(timestamp, datalogMessage.get(), datalogMessage.get(), datalogMessage.getShort(), datalogMessage.get(), datalogMessage.get());
stepsRecords[recordIdx] = new StepsRecord(timestamp, datalogMessage.get() & 0xff, datalogMessage.get() & 0xff, datalogMessage.getShort() & 0xffff);
datalogMessage.getShort(); // skip
timestamp += 60;
}
@ -82,7 +81,7 @@ public class DatalogSessionHealthSteps extends DatalogSession {
sampleProvider,
stepsRecord.timestamp,
stepsRecord.intensity,
(short) (stepsRecord.steps & 0xff),
stepsRecord.steps,
sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY));
}
@ -100,11 +99,11 @@ public class DatalogSessionHealthSteps extends DatalogSession {
private class StepsRecord {
int timestamp;
byte steps;
byte orientation;
short intensity;
int steps;
int orientation;
int intensity;
public StepsRecord(int timestamp, byte steps, byte orientation, short intensity, byte throwAway1, byte throwAway2) {
public StepsRecord(int timestamp, int steps, int orientation, int intensity) {
this.timestamp = timestamp;
this.steps = steps;
this.orientation = orientation;

View File

@ -8,7 +8,6 @@ import android.preference.PreferenceManager;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;