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:
commit
22cf74bbd1
@ -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_START = new byte[]{0x4f, 0x5a};
|
||||||
public static final byte[] CMD_SET_PREF_START1 = new byte[]{0x4d};
|
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_LANGUAGE = 0x22;
|
||||||
public static final byte CMD_SET_TIMEMODE = 0x47;
|
public static final byte CMD_SET_TIMEMODE = 0x47;
|
||||||
public static final byte CMD_SET_UNITS = 0x48;
|
public static final byte CMD_SET_UNITS = 0x48;
|
||||||
|
@ -143,19 +143,13 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
|||||||
qb.where(HPlusHealthActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
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) {
|
public static byte getLanguage(String address) {
|
||||||
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_LANGUAGE + "_" + address, HPlusConstants.ARG_LANGUAGE_EN);
|
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_LANGUAGE + "_" + address, HPlusConstants.ARG_LANGUAGE_EN);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte getTimeMode(String address) {
|
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) {
|
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);
|
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) {
|
public static int getSITStartTime(String address) {
|
||||||
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_START_TIME + "_" + address, 0);
|
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_START_TIME + "_" + address, 0);
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,10 @@ public class MakibesF68Coordinator extends HPlusCoordinator {
|
|||||||
public DeviceType getDeviceType() {
|
public DeviceType getDeviceType() {
|
||||||
return DeviceType.MAKIBESF68;
|
return DeviceType.MAKIBESF68;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getManufacturer() {
|
||||||
|
return "Makibes";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import java.util.GregorianCalendar;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
@ -109,11 +110,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
//Initialize device
|
//Initialize device
|
||||||
sendUserInfo(builder); //Sync preferences
|
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);
|
requestDeviceInfo(builder);
|
||||||
|
|
||||||
@ -141,55 +138,9 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
private HPlusSupport syncPreferences(TransactionBuilder transaction) {
|
private HPlusSupport syncPreferences(TransactionBuilder transaction) {
|
||||||
|
|
||||||
if(deviceType == DeviceType.HPLUS) {
|
if(deviceType == DeviceType.HPLUS) {
|
||||||
byte gender = HPlusCoordinator.getUserGender(getDevice().getAddress());
|
setSIT(transaction); //Sync SIT Interval
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
setGender(transaction);
|
||||||
setAge(transaction);
|
setAge(transaction);
|
||||||
setWeight(transaction);
|
setWeight(transaction);
|
||||||
@ -197,12 +148,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
setGoal(transaction);
|
setGoal(transaction);
|
||||||
setLanguage(transaction);
|
setLanguage(transaction);
|
||||||
setScreenTime(transaction);
|
setScreenTime(transaction);
|
||||||
//setAlarm(transaction, t);
|
|
||||||
setUnit(transaction);
|
setUnit(transaction);
|
||||||
setTimeMode(transaction);
|
setTimeMode(transaction);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
setAllDayHeart(transaction);
|
setAllDayHeart(transaction);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -404,12 +351,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
private HPlusSupport setAlarm(TransactionBuilder transaction, Calendar t) {
|
private HPlusSupport setAlarm(TransactionBuilder transaction, Calendar t) {
|
||||||
|
|
||||||
transaction.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_ALARM,
|
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.HOUR_OF_DAY),
|
||||||
(byte) t.get(Calendar.MINUTE),
|
(byte) t.get(Calendar.MINUTE)});
|
||||||
(byte) t.get(Calendar.SECOND)});
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -497,8 +440,11 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
setAlarm(builder, t);
|
setAlarm(builder, t);
|
||||||
builder.queue(getQueue());
|
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
|
return; //Only first alarm
|
||||||
}
|
}
|
||||||
|
GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user