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

Merge pull request #532 from jpbarraca/alarm

HPlus: Working alarms and small cleanup
This commit is contained in:
Andreas Shimokawa 2017-02-03 14:02:29 +01:00 committed by GitHub
commit 22cf74bbd1
4 changed files with 25 additions and 86 deletions

View File

@ -38,7 +38,8 @@ public final class HPlusConstants {
public static final byte[] CMD_SET_PREF_START = new byte[]{0x4f, 0x5a};
public static final byte[] CMD_SET_PREF_START1 = new byte[]{0x4d};
public static final byte CMD_SET_ALARM = 0x4c;
//public static final byte CMD_SET_ALARM = 0x4c; Unknown
public static final byte CMD_SET_ALARM = 0x0c;
public static final byte CMD_SET_LANGUAGE = 0x22;
public static final byte CMD_SET_TIMEMODE = 0x47;
public static final byte CMD_SET_UNITS = 0x48;

View File

@ -143,19 +143,13 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
qb.where(HPlusHealthActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
}
public static int getFitnessGoal(String address) throws IllegalArgumentException {
ActivityUser activityUser = new ActivityUser();
return activityUser.getStepsGoal();
}
public static byte getLanguage(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_LANGUAGE + "_" + address, HPlusConstants.ARG_LANGUAGE_EN);
}
public static byte getTimeMode(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_TIMEMODE + "_" + address, 0);
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_TIMEMODE + "_" + address, HPlusConstants.ARG_TIMEMODE_24H);
}
public static byte getUnit(String address) {
@ -217,14 +211,6 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
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);
}

View File

@ -30,4 +30,10 @@ public class MakibesF68Coordinator extends HPlusCoordinator {
public DeviceType getDeviceType() {
return DeviceType.MAKIBESF68;
}
@Override
public String getManufacturer() {
return "Makibes";
}
}

View File

@ -26,6 +26,7 @@ import java.util.GregorianCalendar;
import java.util.List;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -109,11 +110,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
//Initialize device
sendUserInfo(builder); //Sync preferences
setSIT(builder); //Sync SIT Interval
setCurrentDate(builder); // Sync Current Date
setDayOfWeek(builder);
setCurrentTime(builder); // Sync Current Time
setLanguage(builder);
requestDeviceInfo(builder);
@ -141,55 +138,9 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport syncPreferences(TransactionBuilder transaction) {
if(deviceType == DeviceType.HPLUS) {
byte gender = HPlusCoordinator.getUserGender(getDevice().getAddress());
byte age = HPlusCoordinator.getUserAge(getDevice().getAddress());
byte bodyHeight = HPlusCoordinator.getUserHeight(getDevice().getAddress());
byte bodyWeight = HPlusCoordinator.getUserWeight(getDevice().getAddress());
int goal = HPlusCoordinator.getGoal(getDevice().getAddress());
byte displayTime = HPlusCoordinator.getScreenTime(getDevice().getAddress());
byte country = HPlusCoordinator.getLanguage(getDevice().getAddress());
byte social = HPlusCoordinator.getSocial(getDevice().getAddress()); // ??
byte allDayHeart = HPlusCoordinator.getAllDayHR(getDevice().getAddress());
byte wrist = HPlusCoordinator.getUserWrist(getDevice().getAddress());
byte alertTimeHour = 0;
byte alertTimeMinute = 0;
if (HPlusCoordinator.getSWAlertTime(getDevice().getAddress())) {
int t = HPlusCoordinator.getAlertTime(getDevice().getAddress());
alertTimeHour = (byte) ((t / 256) & 0xff);
alertTimeMinute = (byte) (t % 256);
setSIT(transaction); //Sync SIT Interval
}
byte unit = HPlusCoordinator.getUnit(getDevice().getAddress());
byte timemode = HPlusCoordinator.getTimeMode((getDevice().getAddress()));
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_PREFS,
gender,
age,
bodyHeight,
bodyWeight,
0,
0,
(byte) ((goal / 256) & 0xff),
(byte) (goal % 256),
displayTime,
country,
0,
social,
allDayHeart,
wrist,
0,
alertTimeHour,
alertTimeMinute,
unit,
timemode
});
}else if(deviceType == DeviceType.MAKIBESF68){
//Makibes doesn't support setting everything at once.
setGender(transaction);
setAge(transaction);
setWeight(transaction);
@ -197,12 +148,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
setGoal(transaction);
setLanguage(transaction);
setScreenTime(transaction);
//setAlarm(transaction, t);
setUnit(transaction);
setTimeMode(transaction);
}
setAllDayHeart(transaction);
return this;
@ -404,12 +351,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setAlarm(TransactionBuilder transaction, Calendar t) {
transaction.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_ALARM,
(byte) (t.get(Calendar.YEAR) / 256),
(byte) (t.get(Calendar.YEAR) % 256),
(byte) (t.get(Calendar.MONTH) + 1),
(byte) t.get(Calendar.HOUR_OF_DAY),
(byte) t.get(Calendar.MINUTE),
(byte) t.get(Calendar.SECOND)});
(byte) t.get(Calendar.MINUTE)});
return this;
}
@ -497,8 +440,11 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
setAlarm(builder, t);
builder.queue(getQueue());
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT, GB.INFO);
return; //Only first alarm
}
GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
}