mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 20:36:51 +01:00
Pebble 2: save heart rate values to database (hopefully)
This commit is contained in:
parent
1012236989
commit
163a7bdf15
@ -26,20 +26,21 @@ import de.greenrobot.daogenerator.Schema;
|
||||
*/
|
||||
public class GBDaoGenerator {
|
||||
|
||||
public static final String VALID_FROM_UTC = "validFromUTC";
|
||||
public static final String VALID_TO_UTC = "validToUTC";
|
||||
private static final String VALID_FROM_UTC = "validFromUTC";
|
||||
private static final String VALID_TO_UTC = "validToUTC";
|
||||
private static final String MAIN_PACKAGE = "nodomain.freeyourgadget.gadgetbridge";
|
||||
private static final String MODEL_PACKAGE = MAIN_PACKAGE + ".model";
|
||||
private static final String VALID_BY_DATE = MODEL_PACKAGE + ".ValidByDate";
|
||||
private static final String OVERRIDE = "@Override";
|
||||
public static final String SAMPLE_RAW_INTENSITY = "rawIntensity";
|
||||
public static final String SAMPLE_STEPS = "steps";
|
||||
public static final String SAMPLE_RAW_KIND = "rawKind";
|
||||
public static final String TIMESTAMP_FROM = "timestampFrom";
|
||||
public static final String TIMESTAMP_TO = "timestampTo";
|
||||
private static final String SAMPLE_RAW_INTENSITY = "rawIntensity";
|
||||
private static final String SAMPLE_STEPS = "steps";
|
||||
private static final String SAMPLE_RAW_KIND = "rawKind";
|
||||
private static final String SAMPLE_HEART_RATE = "heartRate";
|
||||
private static final String TIMESTAMP_FROM = "timestampFrom";
|
||||
private static final String TIMESTAMP_TO = "timestampTo";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Schema schema = new Schema(13, MAIN_PACKAGE + ".entities");
|
||||
Schema schema = new Schema(14, MAIN_PACKAGE + ".entities");
|
||||
|
||||
Entity userAttributes = addUserAttributes(schema);
|
||||
Entity user = addUserInfo(schema, userAttributes);
|
||||
@ -172,7 +173,7 @@ public class GBDaoGenerator {
|
||||
}
|
||||
|
||||
private static void addHeartRateProperties(Entity activitySample) {
|
||||
activitySample.addIntProperty("heartRate").notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
||||
activitySample.addIntProperty(SAMPLE_HEART_RATE).notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
||||
}
|
||||
|
||||
private static Entity addPebbleHealthActivitySample(Schema schema, Entity user, Entity device) {
|
||||
@ -181,6 +182,7 @@ public class GBDaoGenerator {
|
||||
activitySample.addByteArrayProperty("rawPebbleHealthData").codeBeforeGetter(OVERRIDE);
|
||||
activitySample.addIntProperty(SAMPLE_RAW_INTENSITY).notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
||||
activitySample.addIntProperty(SAMPLE_STEPS).notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
||||
addHeartRateProperties(activitySample);
|
||||
return activitySample;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.database.schema;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySampleDao;
|
||||
|
||||
/*
|
||||
* adds heart rate column to health table
|
||||
*/
|
||||
|
||||
public class GadgetbridgeUpdate_14 implements DBUpdateScript {
|
||||
@Override
|
||||
public void upgradeSchema(SQLiteDatabase db) {
|
||||
if (!DBHelper.existsColumn(PebbleHealthActivitySampleDao.TABLENAME, PebbleHealthActivitySampleDao.Properties.HeartRate.columnName, db)) {
|
||||
String ADD_COLUMN_HEART_RATE = "ALTER TABLE " + PebbleHealthActivitySampleDao.TABLENAME + " ADD COLUMN "
|
||||
+ PebbleHealthActivitySampleDao.Properties.HeartRate.columnName + " INTEGER NOT NULL;";
|
||||
db.execSQL(ADD_COLUMN_HEART_RATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downgradeSchema(SQLiteDatabase db) {
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ public class SchemaMigration {
|
||||
|
||||
private DBUpdateScript getUpdateScript(SQLiteDatabase db, int version) {
|
||||
try {
|
||||
Class<?> updateClass = getClass().getClassLoader().loadClass(getClass().getPackage().getName() + ".schema." + classNamePrefix + version);
|
||||
Class<?> updateClass = getClass().getClassLoader().loadClass(getClass().getPackage().getName() + "." + classNamePrefix + version);
|
||||
return (DBUpdateScript) updateClass.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
|
@ -89,7 +89,8 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
||||
deviceId, userId,
|
||||
stepsRecord.getRawData(),
|
||||
stepsRecord.intensity,
|
||||
stepsRecord.steps
|
||||
stepsRecord.steps,
|
||||
stepsRecord.heart_rate
|
||||
);
|
||||
samples[j].setProvider(sampleProvider);
|
||||
}
|
||||
@ -108,6 +109,8 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
||||
int orientation;
|
||||
int intensity;
|
||||
int light_intensity;
|
||||
int heart_rate;
|
||||
|
||||
byte[] rawData;
|
||||
|
||||
StepsRecord(int timestamp, short version, byte[] rawData) {
|
||||
@ -123,6 +126,13 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
||||
this.orientation = record.get() & 0xff;
|
||||
this.intensity = record.getShort() & 0xffff;
|
||||
this.light_intensity = record.get() & 0xff;
|
||||
if (version >= 7) {
|
||||
// skip 7 bytes
|
||||
record.getInt();
|
||||
record.getShort();
|
||||
record.get();
|
||||
this.heart_rate = record.get();
|
||||
}
|
||||
}
|
||||
|
||||
byte[] getRawData() {
|
||||
|
Loading…
Reference in New Issue
Block a user