1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

Merge pull request #470 from jpbarraca/hplus

Add preliminary support for HPlus devices: Zeblaze Zeband and others
This commit is contained in:
Carsten Pfeiffer 2016-12-25 21:33:52 +01:00 committed by GitHub
commit a84bc16503
10 changed files with 1524 additions and 0 deletions

View File

@ -60,6 +60,7 @@ public class GBDaoGenerator {
addPebbleHealthActivityKindOverlay(schema, user, device);
addPebbleMisfitActivitySample(schema, user, device);
addPebbleMorpheuzActivitySample(schema, user, device);
addHPlusHealthActivitySample(schema, user, device);
new DaoGenerator().generateAll(schema, "app/src/main/java");
}
@ -221,6 +222,19 @@ public class GBDaoGenerator {
return activitySample;
}
private static Entity addHPlusHealthActivitySample(Schema schema, Entity user, Entity device) {
Entity activitySample = addEntity(schema, "HPlusHealthActivitySample");
addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device);
activitySample.addByteArrayProperty("rawHPlusHealthData");
activitySample.addIntProperty("rawHPlusCalories").notNull();
activitySample.addIntProperty("rawHPlusDistance").notNull();
activitySample.addIntProperty(SAMPLE_RAW_INTENSITY).notNull().codeBeforeGetterAndSetter(OVERRIDE);
activitySample.addIntProperty(SAMPLE_STEPS).notNull().codeBeforeGetterAndSetter(OVERRIDE);
activitySample.addIntProperty(SAMPLE_RAW_KIND).notNull().codeBeforeGetterAndSetter(OVERRIDE);
addHeartRateProperties(activitySample);
return activitySample;
}
private static void addCommonActivitySampleProperties(String superClass, Entity activitySample, Entity user, Entity device) {
activitySample.setSuperclass(superClass);
activitySample.addImport(MAIN_PACKAGE + ".devices.SampleProvider");

View File

@ -24,6 +24,7 @@ public interface SampleProvider<T extends AbstractActivitySample> {
int PROVIDER_PEBBLE_MISFIT = 3;
int PROVIDER_PEBBLE_HEALTH = 4;
int PROVIDER_MIBAND2 = 5;
int PROVIDER_HPLUS = 6;
int PROVIDER_UNKNOWN = 100;
// TODO: can also be removed

View File

@ -0,0 +1,99 @@
package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
import java.util.UUID;
/**
* Message constants reverse-engineered by João Paulo Barraca, jpbarraca@gmail.com.
*
* @author João Paulo Barraca &lt;jpbarraca@gmail.com&gt;
*/
public final class HPlusConstants {
public static final UUID UUID_CHARACTERISTIC_CONTROL = UUID.fromString("14702856-620a-3973-7c78-9cfff0876abd");
public static final UUID UUID_CHARACTERISTIC_MEASURE = UUID.fromString("14702853-620a-3973-7c78-9cfff0876abd");
public static final UUID UUID_SERVICE_HP = UUID.fromString("14701820-620a-3973-7c78-9cfff0876abd");
public static final byte COUNTRY_CN = 1;
public static final byte COUNTRY_OTHER = 2;
public static final byte CLOCK_24H = 0;
public static final byte CLOCK_12H = 1;
public static final byte UNIT_METRIC = 0;
public static final byte UNIT_IMPERIAL = 1;
public static final byte SEX_MALE = 0;
public static final byte SEX_FEMALE = 1;
public static final byte HEARTRATE_MEASURE_ON = 11;
public static final byte HEARTRATE_MEASURE_OFF = 22;
public static final byte HEARTRATE_ALLDAY_ON = 10;
public static final byte HEARTRATE_ALLDAY_OFF = -1;
public static final byte[] COMMAND_SET_INIT1 = new byte[]{0x50,0x00,0x25,(byte) 0xb1,0x4a,0x00,0x00,0x27,0x10,0x05,0x02,0x00,(byte) 0xff,0x0a,(byte) 0xff,0x00,(byte) 0xff,(byte) 0xff,0x00,0x01};
public static final byte[] COMMAND_SET_INIT2 = new byte[]{0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,(byte) 0xe0,0x0c,0x12,0x16,0x0a,0x10,0x00,0x00,0x00,0x00};
public static final byte[] COMMAND_SET_PREF_START = new byte[]{0x4f, 0x5a};
public static final byte[] COMMAND_SET_PREF_START1 = new byte[]{0x4d};
public static final byte COMMAND_SET_PREF_COUNTRY = 0x22;
public static final byte COMMAND_SET_PREF_TIMEMODE = 0x47;
public static final byte COMMAND_SET_PREF_UNIT = 0x48;
public static final byte COMMAND_SET_PREF_SEX = 0x2d;
public static final byte COMMAND_SET_PREF_DATE = 0x08;
public static final byte COMMAND_SET_PREF_TIME = 0x09;
public static final byte COMMAND_SET_PREF_WEEK = 0x2a;
public static final byte COMMAND_SET_PREF_SIT = 0x1e;
public static final byte COMMAND_SET_PREF_WEIGHT = 0x05;
public static final byte COMMAND_SET_PREF_HEIGHT = 0x04;
public static final byte COMMAND_SET_PREF_AGE = 0x2c;
public static final byte COMMAND_SET_PREF_GOAL = 0x26;
public static final byte COMMAND_SET_PREF_SCREENTIME = 0x0b;
public static final byte COMMAND_SET_PREF_BLOOD = 0x4e; //??
public static final byte COMMAND_SET_PREF_FINDME = 0x0a;
public static final byte COMMAND_SET_PREF_SAVE = 0x17;
public static final byte COMMAND_SET_PREF_END = 0x4f;
public static final byte COMMAND_SET_DISPLAY_ALERT = 0x23;
public static final byte COMMAND_SET_PREF_ALLDAYHR = 53;
public static final byte COMMAND_SET_INCOMING_CALL = 0x41;
public static final byte[] COMMAND_FACTORY_RESET = new byte[] {-74, 90};
public static final byte COMMAND_SET_CONF_SAVE = 0x17;
public static final byte COMMAND_SET_CONF_END = 0x4f;
public static final byte COMMAND_SET_PREFS = 0x50;
public static final byte COMMAND_SET_SIT_INTERVAL = 0x51;
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;
public static final byte COMMAND_ACTION_INCOMING_SMS = 0x40;
public static final byte COMMAND_ACTION_DISPLAY_TEXT = 0x43;
public static final byte[] COMMAND_ACTION_INCOMING_CALL = new byte[] {6, -86};
public static final byte COMMAND_ACTION_DISPLAY_TEXT_CENTER = 0x23;
public static final byte COMMAND_ACTION_DISPLAY_TEXT_NAME = 0x3F;
public static final byte COMMAND_ACTION_DISPLAY_TEXT_NAME_CN = 0x3E; //Text in GB2312?
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";
public static final String PREF_HPLUS_TIMEMODE = "hplus_timemode";
public static final String PREF_HPLUS_WRIST = "hplus_wrist";
public static final String PREF_HPLUS_SWALERT = "hplus_sw_alert";
public static final String PREF_HPLUS_ALERT_TIME = "hplus_alert_time";
public static final String PREF_HPLUS_SIT_START_TIME = "hplus_sit_start_time";
public static final String PREF_HPLUS_SIT_END_TIME = "hplus_sit_end_time";
public static final String PREF_HPLUS_COUNTRY = "hplus_country";
}

View File

@ -0,0 +1,226 @@
package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
/*
* @author João Paulo Barraca &lt;jpbarraca@gmail.com&gt;
*/
import android.annotation.TargetApi;
import android.app.Activity;
import android.bluetooth.le.ScanFilter;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.ParcelUuid;
import android.support.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.UserInfo;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Collections;
public class HPlusCoordinator extends AbstractDeviceCoordinator {
private static final Logger LOG = LoggerFactory.getLogger(HPlusCoordinator.class);
private static Prefs prefs = GBApplication.getPrefs();
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid mi2Service = new ParcelUuid(HPlusConstants.UUID_SERVICE_HP);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(mi2Service).build();
return Collections.singletonList(filter);
}
@NonNull
@Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
if (candidate.supportsService(HPlusConstants.UUID_SERVICE_HP)) {
return DeviceType.HPLUS;
}
String name = candidate.getDevice().getName();
LOG.debug("Looking for: " + name);
if (name != null && name.startsWith("HPLUS")) {
return DeviceType.HPLUS;
}
return DeviceType.UNKNOWN;
}
@Override
public DeviceType getDeviceType() {
return DeviceType.HPLUS;
}
@Override
public Class<? extends Activity> getPairingActivity() {
return null;
}
@Override
public Class<? extends Activity> getPrimaryActivity() {
return ChartsActivity.class;
}
@Override
public InstallHandler findInstallHandler(Uri uri, Context context) {
return null;
}
@Override
public boolean supportsActivityDataFetching() {
return true;
}
@Override
public boolean supportsActivityTracking() {
return true;
}
@Override
public SampleProvider<? extends ActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
return new HPlusSampleProvider(device, session);
}
@Override
public boolean supportsScreenshots() {
return false;
}
@Override
public boolean supportsAlarmConfiguration() {
return true;
}
@Override
public boolean supportsHeartRateMeasurement(GBDevice device) {
return true;
}
@Override
public int getTapString() {
return R.string.tap_connected_device_for_activity;
}
@Override
public String getManufacturer() {
return "Zeblaze";
}
@Override
public boolean supportsAppsManagement() {
return false;
}
@Override
public Class<? extends Activity> getAppsManagementActivity() {
return null;
}
@Override
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
// nothing to delete, yet
}
public static int getFitnessGoal(String address) throws IllegalArgumentException {
ActivityUser activityUser = new ActivityUser();
return activityUser.getStepsGoal();
}
public static byte getCountry(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_COUNTRY + "_" + address, 10);
}
public static byte getTimeMode(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_TIMEMODE + "_" + address, 0);
}
public static byte getUnit(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_UNIT + "_" + address, 0);
}
public static byte getUserWeight(String address) {
ActivityUser activityUser = new ActivityUser();
return (byte) (activityUser.getWeightKg() & 0xFF);
}
public static byte getUserHeight(String address) {
ActivityUser activityUser = new ActivityUser();
return (byte) (activityUser.getHeightCm() & 0xFF);
}
public static byte getUserAge(String address) {
ActivityUser activityUser = new ActivityUser();
return (byte) (activityUser.getAge() & 0xFF);
}
public static byte getUserSex(String address) {
ActivityUser activityUser = new ActivityUser();
return (byte) (activityUser.getGender() & 0xFF);
}
public static int getGoal(String address) {
ActivityUser activityUser = new ActivityUser();
return activityUser.getStepsGoal();
}
public static byte getScreenTime(String address) {
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) & 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) & 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

@ -0,0 +1,82 @@
package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
/*
* @author João Paulo Barraca &lt;jpbarraca@gmail.com&gt;
*/
import android.content.Context;
import android.support.annotation.NonNull;
import java.util.Collections;
import java.util.List;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class HPlusSampleProvider extends AbstractSampleProvider<HPlusHealthActivitySample> {
private GBDevice mDevice;
private DaoSession mSession;
public HPlusSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
mSession = session;
mDevice = device;;
}
public int getID() {
return SampleProvider.PROVIDER_HPLUS;
}
public int normalizeType(int rawType) {
return rawType;
}
public int toRawActivityKind(int activityKind) {
return activityKind;
}
@NonNull
@Override
protected de.greenrobot.dao.Property getTimestampSampleProperty() {
return HPlusHealthActivitySampleDao.Properties.Timestamp;
}
@Override
public HPlusHealthActivitySample createActivitySample() {
return new HPlusHealthActivitySample();
}
@Override
protected de.greenrobot.dao.Property getRawKindSampleProperty() {
return HPlusHealthActivitySampleDao.Properties.RawKind;
}
@Override
public float normalizeIntensity(int rawIntensity) {
return rawIntensity; //TODO: Calculate actual value
}
@NonNull
@Override
protected de.greenrobot.dao.Property getDeviceIdentifierSampleProperty() {
return HPlusHealthActivitySampleDao.Properties.DeviceId;
}
@Override
public AbstractDao<HPlusHealthActivitySample, ?> getSampleDao() {
return getSession().getHPlusHealthActivitySampleDao();
}
}

View File

@ -13,6 +13,7 @@ public enum DeviceType {
MIBAND2(11),
VIBRATISSIMO(20),
LIVEVIEW(30),
HPLUS(40),
TEST(1000);
private final int key;

View File

@ -15,6 +15,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Suppo
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.vibratissimo.VibratissimoSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class DeviceSupportFactory {
@ -96,6 +97,9 @@ public class DeviceSupportFactory {
case LIVEVIEW:
deviceSupport = new ServiceDeviceSupport(new LiveviewSupport(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
case HPLUS:
deviceSupport = new ServiceDeviceSupport(new HPlusSupport(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
}
if (deviceSupport != null) {
deviceSupport.setContext(gbDevice, mBtAdapter, mContext);

View File

@ -0,0 +1,86 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
public class HPlusSleepRecord {
private long bedTimeStart;
private long bedTimeEnd;
private int deepSleepSeconds;
private int spindleSeconds;
private int remSleepSeconds;
private int wakeupTime;
private int wakeupCount;
private int enterSleepSeconds;
private byte[] rawData;
HPlusSleepRecord(byte[] data) {
rawData = data;
int year = data[2] * 256 + data[1];
int month = data[3];
int day = data[4];
enterSleepSeconds = data[6] * 256 + data[5];
spindleSeconds = data[8] * 256 + data[7];
deepSleepSeconds = data[10] * 256 + data[9];
remSleepSeconds = data[12] * 256 + data[11];
wakeupTime = data[14] * 256 + data[13];
wakeupCount = data[16] * 256 + data[15];
int hour = data[17];
int minute = data[18];
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
c.set(Calendar.HOUR, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
bedTimeStart = (c.getTimeInMillis() / 1000L);
bedTimeEnd = bedTimeStart + enterSleepSeconds + spindleSeconds + deepSleepSeconds + remSleepSeconds + wakeupTime;
}
byte[] getRawData() {
return rawData;
}
public long getBedTimeStart() {
return bedTimeStart;
}
public long getBedTimeEnd() {
return bedTimeEnd;
}
public int getDeepSleepSeconds() {
return deepSleepSeconds;
}
public int getSpindleSeconds() {
return spindleSeconds;
}
public int getRemSleepSeconds() {
return remSleepSeconds;
}
public int getWakeupTime() {
return wakeupTime;
}
public int getWakeupCount() {
return wakeupCount;
}
public int getEnterSleepSeconds() {
return enterSleepSeconds;
}
}

View File

@ -22,6 +22,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.UnknownDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.liveview.LiveviewCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
@ -167,6 +168,7 @@ public class DeviceHelper {
result.add(new PebbleCoordinator());
result.add(new VibratissimoCoordinator());
result.add(new LiveviewCoordinator());
result.add(new HPlusCoordinator());
return result;
}