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
This commit is contained in:
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

@ -261,26 +261,26 @@ public class GBApplication extends Application {
private void migratePrefs(int oldVersion) { private void migratePrefs(int oldVersion) {
SharedPreferences.Editor editor = sharedPrefs.edit(); SharedPreferences.Editor editor = sharedPrefs.edit();
switch (oldVersion) { switch (oldVersion) {
case 0: case 0:
String legacyGender = sharedPrefs.getString("mi_user_gender", null); String legacyGender = sharedPrefs.getString("mi_user_gender", null);
String legacyHeight = sharedPrefs.getString("mi_user_height_cm", null); String legacyHeight = sharedPrefs.getString("mi_user_height_cm", null);
String legacyWeigth = sharedPrefs.getString("mi_user_weight_kg", null); String legacyWeigth = sharedPrefs.getString("mi_user_weight_kg", null);
String legacyYOB = sharedPrefs.getString("mi_user_year_of_birth",null); String legacyYOB = sharedPrefs.getString("mi_user_year_of_birth", null);
if(legacyGender != null) { if (legacyGender != null) {
int gender = "male".equals(legacyGender) ? 1 : "female".equals(legacyGender) ? 0 : 2; int gender = "male".equals(legacyGender) ? 1 : "female".equals(legacyGender) ? 0 : 2;
editor.putString(ActivityUser.PREF_USER_GENDER, Integer.toString(gender)); editor.putString(ActivityUser.PREF_USER_GENDER, Integer.toString(gender));
editor.remove("mi_user_gender"); editor.remove("mi_user_gender");
} }
if(legacyHeight != null) { if (legacyHeight != null) {
editor.putString(ActivityUser.PREF_USER_HEIGHT_CM, legacyHeight); editor.putString(ActivityUser.PREF_USER_HEIGHT_CM, legacyHeight);
editor.remove("mi_user_height_cm"); editor.remove("mi_user_height_cm");
} }
if(legacyWeigth != null) { if (legacyWeigth != null) {
editor.putString(ActivityUser.PREF_USER_WEIGHT_KG, legacyWeigth); editor.putString(ActivityUser.PREF_USER_WEIGHT_KG, legacyWeigth);
editor.remove("mi_user_weight_kg"); editor.remove("mi_user_weight_kg");
} }
if(legacyYOB != null) { if (legacyYOB != null) {
editor.putString(ActivityUser.PREF_USER_YEAR_OF_BIRTH, legacyYOB); editor.putString(ActivityUser.PREF_USER_YEAR_OF_BIRTH, legacyYOB);
editor.remove("mi_user_year_of_birth"); editor.remove("mi_user_year_of_birth");
} }

View File

@ -12,7 +12,6 @@ import android.view.View;
import com.github.mikephil.charting.charts.BarLineChartBase; import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart; 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.components.YAxis;
import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarDataSet;
@ -29,7 +28,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashSet; import java.util.HashSet;
@ -86,6 +84,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
} }
public abstract String getTitle(); public abstract String getTitle();
public boolean supportsHeartrate() { public boolean supportsHeartrate() {
return supportsHeartrateChart; return supportsHeartrateChart;
} }
@ -166,7 +165,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
protected ChartsHost getChartsHost() { protected ChartsHost getChartsHost() {
return (ChartsHost) getActivity(); return (ChartsHost) getActivity();
} }
private void setEndDate(Date date) { private void setEndDate(Date date) {
getChartsHost().setEndDate(date); getChartsHost().setEndDate(date);
} }
@ -447,7 +446,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
} }
activityEntries.add(createBarEntry(value, i)); activityEntries.add(createBarEntry(value, i));
if (hr) { if (hr) {
heartrateEntries.add(createLineEntry(sample.getCustomShortValue(), i)); heartrateEntries.add(createLineEntry(sample.getCustomValue(), i));
} }
String xLabel = ""; 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 this to set the next value for the Entry to be animated.
* Call animateY() when ready to do that. * Call animateY() when ready to do that.
*
* @param nextValue * @param nextValue
*/ */
public void setSingleEntryYValue(float nextValue) { public void setSingleEntryYValue(float nextValue) {

View File

@ -315,9 +315,9 @@ public class LiveActivityFragment extends AbstractChartFragment {
List<String> xLabels = new ArrayList<>(); List<String> xLabels = new ArrayList<>();
List<Integer> colors = new ArrayList<>(); List<Integer> colors = new ArrayList<>();
entries.add(new BarEntry(0,0)); entries.add(new BarEntry(0, 0));
entries.add(entry); entries.add(entry);
entries.add(new BarEntry(0,2)); entries.add(new BarEntry(0, 2));
colors.add(akActivity.color); colors.add(akActivity.color);
colors.add(akActivity.color); colors.add(akActivity.color);
colors.add(akActivity.color); colors.add(akActivity.color);

View File

@ -8,7 +8,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.github.mikephil.charting.animation.Easing; 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.Chart;
import com.github.mikephil.charting.charts.CombinedChart; import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.charts.PieChart;

View File

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

View File

@ -22,15 +22,15 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.DATABASE_NAME; 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_INTENSITY;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_PROVIDER; 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_STEPS;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP; 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_TYPE;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT;
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandler { public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandler {
private static final Logger LOG = LoggerFactory.getLogger(ActivityDatabaseHandler.class); private static final Logger LOG = LoggerFactory.getLogger(ActivityDatabaseHandler.class);
@ -102,7 +102,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
values.put(KEY_PROVIDER, sample.getProvider().getID()); values.put(KEY_PROVIDER, sample.getProvider().getID());
values.put(KEY_INTENSITY, sample.getRawIntensity()); values.put(KEY_INTENSITY, sample.getRawIntensity());
values.put(KEY_STEPS, sample.getSteps()); 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()); values.put(KEY_TYPE, sample.getRawKind());
db.insert(TABLE_GBACTIVITYSAMPLES, null, values); db.insert(TABLE_GBACTIVITYSAMPLES, null, values);
@ -112,14 +112,15 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
/** /**
* Adds the a new sample to the database * Adds the a new sample to the database
* *
* @param timestamp the timestamp of the same, second-based! * @param timestamp the timestamp of the same, second-based!
* @param provider the SampleProvider ID * @param provider the SampleProvider ID
* @param intensity the sample's raw intensity value * @param intensity the sample's raw intensity value
* @param steps the sample's steps value * @param steps the sample's steps value
* @param kind the raw activity kind of the sample * @param kind the raw activity kind of the sample
* @param customShortValue
*/ */
@Override @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) { if (intensity < 0) {
LOG.error("negative intensity received, ignoring"); LOG.error("negative intensity received, ignoring");
intensity = 0; intensity = 0;
@ -164,7 +165,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
statement.bindLong(3, activitySample.getRawIntensity()); statement.bindLong(3, activitySample.getRawIntensity());
statement.bindLong(4, activitySample.getSteps()); statement.bindLong(4, activitySample.getSteps());
statement.bindLong(5, activitySample.getRawKind()); statement.bindLong(5, activitySample.getRawKind());
statement.bindLong(6, activitySample.getCustomShortValue()); statement.bindLong(6, activitySample.getCustomValue());
statement.execute(); statement.execute();
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -242,7 +243,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
} }
StringBuilder builder = new StringBuilder(" and ("); 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++) { for (int i = 0; i < dbActivityTypes.length; i++) {
builder.append(" type=").append(dbActivityTypes[i]); builder.append(" type=").append(dbActivityTypes[i]);
if (i + 1 < dbActivityTypes.length) { if (i + 1 < dbActivityTypes.length) {
@ -254,7 +255,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa
} }
@Override @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()) { try (SQLiteDatabase db = this.getReadableDatabase()) {
String sql = "UPDATE " + TABLE_GBACTIVITYSAMPLES + " SET " + KEY_TYPE + "= ? WHERE " String sql = "UPDATE " + TABLE_GBACTIVITYSAMPLES + " SET " + KEY_TYPE + "= ? WHERE "
+ KEY_PROVIDER + " = ? AND " + KEY_PROVIDER + " = ? AND "

View File

@ -24,13 +24,13 @@ public interface DBHandler {
List<ActivitySample> getSleepSamples(int tsFrom, int tsTo, SampleProvider provider); 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); void addGBActivitySamples(ActivitySample[] activitySamples);
SQLiteDatabase getWritableDatabase(); 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); int fetchLatestTimestamp(SampleProvider provider);

View File

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

View File

@ -1,19 +1,19 @@
package nodomain.freeyourgadget.gadgetbridge.devices; package nodomain.freeyourgadget.gadgetbridge.devices;
public interface SampleProvider { public interface SampleProvider {
byte PROVIDER_MIBAND = 0; int PROVIDER_MIBAND = 0;
byte PROVIDER_PEBBLE_MORPHEUZ = 1; int PROVIDER_PEBBLE_MORPHEUZ = 1;
byte PROVIDER_PEBBLE_GADGETBRIDGE = 2; int PROVIDER_PEBBLE_GADGETBRIDGE = 2;
byte PROVIDER_PEBBLE_MISFIT = 3; int PROVIDER_PEBBLE_MISFIT = 3;
byte PROVIDER_PEBBLE_HEALTH = 4; 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 { private static final class UnknownSampleProvider implements SampleProvider {
@Override @Override
public int normalizeType(byte rawType) { public int normalizeType(int rawType) {
return ActivityKind.TYPE_UNKNOWN; return ActivityKind.TYPE_UNKNOWN;
} }
@Override @Override
public byte toRawActivityKind(int activityKind) { public int toRawActivityKind(int activityKind) {
return 0; return 0;
} }
@Override @Override
public float normalizeIntensity(short rawIntensity) { public float normalizeIntensity(int rawIntensity) {
return 0; return 0;
} }
@Override @Override
public byte getID() { public int getID() {
return PROVIDER_UNKNOWN; return PROVIDER_UNKNOWN;
} }
} }

View File

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

View File

@ -161,9 +161,9 @@ public class MiBandService {
public static final byte COMMAND_SET_REALTIME_STEP = 0x10; public static final byte COMMAND_SET_REALTIME_STEP = 0x10;
// Test HR // Test HR
public static final byte COMMAND_SET_HR_SLEEP = 0x0; public static final byte COMMAND_SET_HR_SLEEP = 0x0;
public static final byte COMMAND_SET__HR_CONTINUOUS = 0x1; public static final byte COMMAND_SET__HR_CONTINUOUS = 0x1;
public static final byte COMMAND_SET_HR_MANUAL = 0x2; public static final byte COMMAND_SET_HR_MANUAL = 0x2;
/* FURTHER COMMANDS: unchecked therefore left commented /* FURTHER COMMANDS: unchecked therefore left commented

View File

@ -1,11 +1,11 @@
package nodomain.freeyourgadget.gadgetbridge.devices.miband; package nodomain.freeyourgadget.gadgetbridge.devices.miband;
import java.util.Arrays;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.util.CheckSums; import nodomain.freeyourgadget.gadgetbridge.util.CheckSums;
import java.util.Arrays;
public class UserInfo { public class UserInfo {
private final String btAddress; private final String btAddress;
@ -91,7 +91,7 @@ public class UserInfo {
aliasFrom = 11; aliasFrom = 11;
} }
byte[] aliasBytes = alias.substring(0, Math.min(alias.length(), 19-aliasFrom)).getBytes(); byte[] aliasBytes = alias.substring(0, Math.min(alias.length(), 19 - aliasFrom)).getBytes();
System.arraycopy(aliasBytes, 0, sequence, aliasFrom, aliasBytes.length); System.arraycopy(aliasBytes, 0, sequence, aliasFrom, aliasBytes.length);
byte[] crcSequence = Arrays.copyOf(sequence, 19); byte[] crcSequence = Arrays.copyOf(sequence, 19);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,21 +7,21 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public class GBActivitySample implements ActivitySample { public class GBActivitySample implements ActivitySample {
private final int timestamp; private final int timestamp;
private final SampleProvider provider; private final SampleProvider provider;
private final short intensity; private final int intensity;
private final short steps; private final int steps;
private final byte type; private final int type;
private final short customShortValue; private final int customValue;
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type) { public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type) {
this(provider, timestamp, intensity, steps, type, (short) 0); 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.timestamp = timestamp;
this.provider = provider; this.provider = provider;
this.intensity = intensity; this.intensity = intensity;
this.steps = steps; this.steps = steps;
this.customShortValue = customShortValue; this.customValue = customValue;
this.type = type; this.type = type;
validate(); validate();
} }
@ -36,8 +36,8 @@ public class GBActivitySample implements ActivitySample {
if (timestamp < 0) { if (timestamp < 0) {
throw new IllegalArgumentException("timestamp must be >= 0"); throw new IllegalArgumentException("timestamp must be >= 0");
} }
if (customShortValue < 0) { if (customValue < 0) {
throw new IllegalArgumentException("customShortValue must be >= 0"); throw new IllegalArgumentException("customValue must be >= 0");
} }
} }
@ -52,7 +52,7 @@ public class GBActivitySample implements ActivitySample {
} }
@Override @Override
public short getRawIntensity() { public int getRawIntensity() {
return intensity; return intensity;
} }
@ -62,12 +62,12 @@ public class GBActivitySample implements ActivitySample {
} }
@Override @Override
public short getSteps() { public int getSteps() {
return steps; return steps;
} }
@Override @Override
public byte getRawKind() { public int getRawKind() {
return type; return type;
} }
@ -77,8 +77,8 @@ public class GBActivitySample implements ActivitySample {
} }
@Override @Override
public short getCustomShortValue() { public int getCustomValue() {
return customShortValue; return customValue;
} }
@Override @Override
@ -87,7 +87,7 @@ public class GBActivitySample implements ActivitySample {
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimeStamp(timestamp)) + "timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimeStamp(timestamp)) +
", intensity=" + getIntensity() + ", intensity=" + getIntensity() +
", steps=" + getSteps() + ", steps=" + getSteps() +
", customShortValue=" + getCustomShortValue() + ", customValue=" + getCustomValue() +
", type=" + getKind() + ", 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_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP;
public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN; public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN;
public static byte[] mapToDBActivityTypes(int types, SampleProvider provider) { public static int[] mapToDBActivityTypes(int types, SampleProvider provider) {
byte[] result = new byte[3]; int[] result = new int[3];
int i = 0; int i = 0;
if ((types & ActivityKind.TYPE_ACTIVITY) != 0) { if ((types & ActivityKind.TYPE_ACTIVITY) != 0) {
result[i++] = provider.toRawActivityKind(TYPE_ACTIVITY); 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 * 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 * 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 * Returns the raw intensity value as recorded by the SampleProvider
*/ */
short getRawIntensity(); int getRawIntensity();
/** /**
* Returns the normalized intensity value between 0 and 1 * 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 * Returns the number of steps performed during the period of this sample
*/ */
short getSteps(); int getSteps();
short getCustomShortValue(); int getCustomValue();
} }

View File

@ -29,28 +29,28 @@ public class ActivityUser {
public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg"; public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg";
public int getActivityUserWeightKg() { public int getActivityUserWeightKg() {
if(activityUserWeightKg == null) { if (activityUserWeightKg == null) {
fetchPreferences(); fetchPreferences();
} }
return activityUserWeightKg; return activityUserWeightKg;
} }
public int getActivityUserGender() { public int getActivityUserGender() {
if(activityUserGender == null) { if (activityUserGender == null) {
fetchPreferences(); fetchPreferences();
} }
return activityUserGender; return activityUserGender;
} }
public int getActivityUserYearOfBirth() { public int getActivityUserYearOfBirth() {
if(activityUserYearOfBirth == null) { if (activityUserYearOfBirth == null) {
fetchPreferences(); fetchPreferences();
} }
return activityUserYearOfBirth; return activityUserYearOfBirth;
} }
public int getActivityUserHeightCm() { public int getActivityUserHeightCm() {
if(activityUserHeightCm == null) { if (activityUserHeightCm == null) {
fetchPreferences(); fetchPreferences();
} }
return activityUserHeightCm; return activityUserHeightCm;

View File

@ -22,7 +22,7 @@ public class CalendarEvents {
// needed for miband: // needed for miband:
// time // time
private static final String[] EVENT_INSTANCE_PROJECTION = new String[] { private static final String[] EVENT_INSTANCE_PROJECTION = new String[]{
Instances._ID, Instances._ID,
Instances.BEGIN, Instances.BEGIN,
Instances.END, Instances.END,
@ -67,9 +67,9 @@ public class CalendarEvents {
evtCursor.getString(5), evtCursor.getString(5),
evtCursor.getString(6), evtCursor.getString(6),
evtCursor.getString(7) evtCursor.getString(7)
); );
calendarEventList.add(calEvent); calendarEventList.add(calEvent);
} while(evtCursor.moveToNext()); } while (evtCursor.moveToNext());
return true; return true;
} }
@ -100,7 +100,7 @@ public class CalendarEvents {
} }
public int getBeginSeconds() { public int getBeginSeconds() {
return (int)(begin/1000); return (int) (begin / 1000);
} }
public long getEnd() { public long getEnd() {
@ -112,11 +112,11 @@ public class CalendarEvents {
} }
public int getDurationSeconds() { public int getDurationSeconds() {
return (int)((getDuration())/1000); return (int) ((getDuration()) / 1000);
} }
public short getDurationMinutes() { public short getDurationMinutes() {
return (short)(getDurationSeconds()/60); return (short) (getDurationSeconds() / 60);
} }

View File

@ -1,7 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.service; package nodomain.freeyourgadget.gadgetbridge.service;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import android.widget.Toast; import android.widget.Toast;
@ -11,10 +10,8 @@ import java.util.EnumSet;
import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; 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.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class DeviceSupportFactory { 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. * Performs this operation. The whole operation is asynchronous, i.e.
* this method quickly returns before the actual operation is finished. * this method quickly returns before the actual operation is finished.
* Calls #prePerform() and, if successful, #doPerform(). * Calls #prePerform() and, if successful, #doPerform().
*
* @throws IOException * @throws IOException
*/ */
@Override @Override
@ -48,6 +49,7 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
/** /**
* Hook for subclasses to perform something before #doPerform() is invoked. * Hook for subclasses to perform something before #doPerform() is invoked.
*
* @throws IOException * @throws IOException
*/ */
protected void prePerform() throws IOException { protected void prePerform() throws IOException {
@ -58,6 +60,7 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
* successfully. * successfully.
* Note that subclasses HAVE TO call #operationFinished() when the entire * Note that subclasses HAVE TO call #operationFinished() when the entire
* opreation is done (successful or not). * opreation is done (successful or not).
*
* @throws IOException * @throws IOException
*/ */
protected abstract void doPerform() 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 * You MUST call this method when the operation has finished, either
* successfull or unsuccessfully. * successfull or unsuccessfully.
*
* @throws IOException * @throws IOException
*/ */
protected void operationFinished() throws IOException { protected void operationFinished() throws IOException {

View File

@ -422,7 +422,7 @@ public final class BtLEQueue {
for (byte b : characteristic.getValue()) { for (byte b : characteristic.getValue()) {
content += String.format(" 0x%1x", b); content += String.format(" 0x%1x", b);
} }
LOG.debug("characteristic changed: " + characteristic.getUuid() + " value: " + content ); LOG.debug("characteristic changed: " + characteristic.getUuid() + " value: " + content);
} }
if (!checkCorrectGattInstance(gatt, "characteristic changed")) { if (!checkCorrectGattInstance(gatt, "characteristic changed")) {
return; return;

View File

@ -74,7 +74,7 @@ public interface GattCallback {
* @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int) * @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int)
*/ */
void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status); int status);
/** /**
* @param gatt * @param gatt
@ -83,7 +83,7 @@ public interface GattCallback {
* @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int) * @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)
*/ */
void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
int status); int status);
// //
// /** // /**
// * @see BluetoothGattCallback#onReliableWriteCompleted(BluetoothGatt, int) // * @see BluetoothGattCallback#onReliableWriteCompleted(BluetoothGatt, int)

View File

@ -41,7 +41,7 @@ public class DeviceInfo extends AbstractInfo {
public static int getInt(byte[] data, int from, int len) { public static int getInt(byte[] data, int from, int len) {
int ret = 0; int ret = 0;
for(int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
ret |= (data[from + i] & 255) << i * 8; ret |= (data[from + i] & 255) << i * 8;
} }
return ret; return ret;

View File

@ -141,7 +141,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
// is not available. And at this point, we don't even know whether we support it, because // is not available. And at this point, we don't even know whether we support it, because
// no device info is available yet. We would have to do the check in a custom NotifyAction. // no device info is available yet. We would have to do the check in a custom NotifyAction.
// if (supportsHeartRate()) { // if (supportsHeartRate()) {
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable); builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable);
// } // }
return this; return this;
@ -206,12 +206,12 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
static final byte[] reboot = new byte[]{MiBandService.COMMAND_REBOOT}; static final byte[] reboot = new byte[]{MiBandService.COMMAND_REBOOT};
static final byte[] startHeartMeasurementManual = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_MANUAL, 1}; static final byte[] startHeartMeasurementManual = new byte[]{0x15, MiBandService.COMMAND_SET_HR_MANUAL, 1};
static final byte[] stopHeartMeasurementManual = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_MANUAL, 0}; static final byte[] stopHeartMeasurementManual = new byte[]{0x15, MiBandService.COMMAND_SET_HR_MANUAL, 0};
static final byte[] startHeartMeasurementContinuous = new byte[]{ 0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 1}; static final byte[] startHeartMeasurementContinuous = new byte[]{0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 1};
static final byte[] stopHeartMeasurementContinuous = new byte[]{ 0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 0}; static final byte[] stopHeartMeasurementContinuous = new byte[]{0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 0};
static final byte[] startHeartMeasurementSleep = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_SLEEP, 1}; static final byte[] startHeartMeasurementSleep = new byte[]{0x15, MiBandService.COMMAND_SET_HR_SLEEP, 1};
static final byte[] stopHeartMeasurementSleep = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_SLEEP, 0}; static final byte[] stopHeartMeasurementSleep = new byte[]{0x15, MiBandService.COMMAND_SET_HR_SLEEP, 0};
static final byte[] startRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 1}; static final byte[] startRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 1};
static final byte[] stopRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 0}; static final byte[] stopRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 0};
@ -283,6 +283,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} }
return this; return this;
}*/ }*/
/** /**
* Part of device initialization process. Do not call manually. * 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); LOG.error("Unable to reboot MI", ex);
} }
} }
@Override @Override
public void onHearRateTest() { public void onHearRateTest() {
if (supportsHeartRate()) { if (supportsHeartRate()) {
@ -673,11 +675,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) { } else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
handleRealtimeSteps(characteristic.getValue()); handleRealtimeSteps(characteristic.getValue());
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) { } else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
handleRealtimeSteps(characteristic.getValue()); handleRealtimeSteps(characteristic.getValue());
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) { } else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
logHeartrate(characteristic.getValue()); logHeartrate(characteristic.getValue());
} } else {
else {
LOG.info("Unhandled characteristic changed: " + characteristicUUID); LOG.info("Unhandled characteristic changed: " + characteristicUUID);
logMessageContent(characteristic.getValue()); logMessageContent(characteristic.getValue());
} }
@ -698,7 +699,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) { } else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
logHeartrate(characteristic.getValue()); logHeartrate(characteristic.getValue());
} else { } else {
LOG.info("Unhandled characteristic read: "+ characteristicUUID); LOG.info("Unhandled characteristic read: " + characteristicUUID);
logMessageContent(characteristic.getValue()); logMessageContent(characteristic.getValue());
} }
} }
@ -927,11 +928,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
if (availableSlots > 0) { if (availableSlots > 0) {
CalendarEvents upcomingEvents = new CalendarEvents(); CalendarEvents upcomingEvents = new CalendarEvents();
List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext()); List<CalendarEvents.CalendarEvent> mEvents = upcomingEvents.getCalendarEventList(getContext());
int iteration = 0; int iteration = 0;
ArrayList<GBAlarm> alarmList = new ArrayList<>(); ArrayList<GBAlarm> alarmList = new ArrayList<>();
for(CalendarEvents.CalendarEvent mEvt : mEvents) { for (CalendarEvents.CalendarEvent mEvt : mEvents) {
if (iteration >= availableSlots || iteration > 2) { if (iteration >= availableSlots || iteration > 2) {
break; break;
} }

View File

@ -41,8 +41,9 @@ public abstract class AbstractMiBandOperation extends AbstractBTLEOperation<MiBa
* Enables or disables certain kinds of notifications that could interfere with this * Enables or disables certain kinds of notifications that could interfere with this
* operation. Call this method once initially to disable other notifications, and once * operation. Call this method once initially to disable other notifications, and once
* when this operation has finished. * when this operation has finished.
*
* @param builder * @param builder
* @param enable true to enable, false to disable the other notifications * @param enable true to enable, false to disable the other notifications
*/ */
protected void enableOtherNotifications(TransactionBuilder builder, boolean enable) { protected void enableOtherNotifications(TransactionBuilder builder, boolean enable) {
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable) builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable)

View File

@ -314,7 +314,7 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples
int timestampInSeconds = (int) (activityStruct.activityDataTimestampProgress.getTimeInMillis() / 1000); int timestampInSeconds = (int) (activityStruct.activityDataTimestampProgress.getTimeInMillis() / 1000);
if ((activityStruct.activityDataHolderProgress % bpm) != 0) { if ((activityStruct.activityDataHolderProgress % bpm) != 0) {
throw new IllegalStateException("Unexpected data, progress should be mutiple of " + bpm +": " + activityStruct.activityDataHolderProgress); throw new IllegalStateException("Unexpected data, progress should be mutiple of " + bpm + ": " + activityStruct.activityDataHolderProgress);
} }
int numSamples = activityStruct.activityDataHolderProgress / bpm; int numSamples = activityStruct.activityDataHolderProgress / bpm;
ActivitySample[] samples = new ActivitySample[numSamples]; ActivitySample[] samples = new ActivitySample[numSamples];

View File

@ -191,10 +191,10 @@ public class UpdateFirmwareOperation extends AbstractMiBandOperation {
if ((i > 0) && (i % 50 == 0)) { if ((i > 0) && (i % 50 == 0)) {
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), new byte[]{MiBandService.COMMAND_SYNC}); builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), new byte[]{MiBandService.COMMAND_SYNC});
builder.add(new SetProgressAction("Firmware update in progress", true, (int)(((float) firmwareProgress) / len * 100), getContext())); builder.add(new SetProgressAction("Firmware update in progress", true, (int) (((float) firmwareProgress) / len * 100), getContext()));
} }
LOG.info("Firmware update progress:" + firmwareProgress + " total len:" + len + " progress:" + (int)(((float) firmwareProgress) / len * 100)); LOG.info("Firmware update progress:" + firmwareProgress + " total len:" + len + " progress:" + (int) (((float) firmwareProgress) / len * 100));
} }
if (!(len % packetLength == 0)) { if (!(len % packetLength == 0)) {

View File

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

View File

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

View File

@ -93,7 +93,7 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler {
DBHandler db = null; DBHandler db = null;
try { try {
db = GBApplication.acquireDB(); db = GBApplication.acquireDB();
db.addGBActivitySample(recording_base_timestamp + index * 600, SampleProvider.PROVIDER_PEBBLE_MORPHEUZ, intensity, (byte) 0, type, (short)0); db.addGBActivitySample(recording_base_timestamp + index * 600, SampleProvider.PROVIDER_PEBBLE_MORPHEUZ, intensity, (byte) 0, type, (short) 0);
} catch (GBException e) { } catch (GBException e) {
LOG.error("Error acquiring database", e); LOG.error("Error acquiring database", e);
} finally { } finally {

View File

@ -77,7 +77,7 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
//byte[] weatherMessage=encodeTimeStylePebbleWeather(); //byte[] weatherMessage=encodeTimeStylePebbleWeather();
ByteBuffer buf = ByteBuffer.allocate(ackMessage.length + testMessage.length ); ByteBuffer buf = ByteBuffer.allocate(ackMessage.length + testMessage.length);
// encode ack and put in front of push message (hack for acknowledging the last message) // encode ack and put in front of push message (hack for acknowledging the last message)
buf.put(ackMessage); buf.put(ackMessage);
@ -98,7 +98,7 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
return weatherMessage; return weatherMessage;
} }
@Override @Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) { public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeTimeStylePebbleConfig(); sendBytes.encodedBytes = encodeTimeStylePebbleConfig();

View File

@ -19,7 +19,7 @@ class DatalogSession {
this.itemSize = itemSize; this.itemSize = itemSize;
} }
boolean handleMessage (ByteBuffer buf, int length) { boolean handleMessage(ByteBuffer buf, int length) {
return true; return true;
} }

View File

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

View File

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

View File

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