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

makibes hr3.

added quite hours.
This commit is contained in:
Cre3per 2019-10-09 15:42:03 +02:00 committed by Andreas Shimokawa
parent 5570ac8349
commit 4437220c54
5 changed files with 128 additions and 13 deletions

View File

@ -25,6 +25,9 @@ public final class MakibesHR3Constants {
// TODO: breaking someone else's device support.
public static final String PREF_HEADS_UP_SCREEN = "activate_display_on_lift_wrist";
public static final String PREF_LOST_REMINDER = "disconnect_notification";
public static final String PREF_DO_NOT_DISTURB = "do_not_disturb_no_auto";
public static final String PREF_DO_NOT_DISTURB_START = "do_not_disturb_no_auto_start";
public static final String PREF_DO_NOT_DISTURB_END = "do_not_disturb_no_auto_end";
public static final UUID UUID_SERVICE = UUID.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
public static final UUID UUID_CHARACTERISTIC_CONTROL = UUID.fromString("6e400002-b5a3-f393-e0a9-e50e24dcca9e");

View File

@ -16,6 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import android.app.Activity;
import android.content.Context;
@ -35,6 +39,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSett
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.MakibesHR3ActivitySampleDao;
@ -75,6 +80,34 @@ public class MakibesHR3Coordinator extends AbstractDeviceCoordinator {
}
}
/**
* @param startOut out Only hour/minute are used.
* @param endOut out Only hour/minute are used.
* @return True if quite hours are enabled.
*/
public static boolean getQuiteHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) {
String doNotDisturb = sharedPrefs.getString(MakibesHR3Constants.PREF_DO_NOT_DISTURB, getContext().getString(R.string.p_off));
if (doNotDisturb.equals(getContext().getString(R.string.p_off))) {
return false;
} else {
String start = sharedPrefs.getString(MakibesHR3Constants.PREF_DO_NOT_DISTURB_START, "00:00");
String end = sharedPrefs.getString(MakibesHR3Constants.PREF_DO_NOT_DISTURB_END, "00:00");
DateFormat df = new SimpleDateFormat("HH:mm");
try {
startOut.setTime(df.parse(start));
endOut.setTime(df.parse(end));
return true;
} catch (Exception e) {
LOG.error("Unexpected exception in MiBand2Coordinator.getTime: " + e.getMessage());
return false;
}
}
}
@NonNull
@Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
@ -191,7 +224,8 @@ public class MakibesHR3Coordinator extends AbstractDeviceCoordinator {
return new int[]{
R.xml.devicesettings_timeformat,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_disconnectnotification
R.xml.devicesettings_disconnectnotification,
R.xml.devicesettings_donotdisturb_no_auto
};
}
}

View File

@ -1,13 +1,17 @@
// TODO: GB sometimes fails to connect until a connection with WearFit was made. This must be caused
// TODO: by GB, not by Makibes hr3 support. Charging the watch, attempting to pair, delete and
// TODO: re-add might also help. This needs further research.
// TODO: re-add, scan for devices and go back, might also help. This needs further research.
// TODO: All the commands that aren't supported by GB should be added to device specific settings.
// TODO: It'd be cool if we could change the language. There's no official way to do so, but the
// TODO: watch is sold as chinese/english. Screen-on-time would be nice too.
// TODO: Firmware upgrades.
// TODO: Firmware upgrades. WearFit tries to connect to Wake up Technology at
// TODO: http://47.112.119.52/app.php/Api/hardUpdate/type/55
// TODO: But that server resets the connection.
// TODO: The host is supposed to be www.iwhop.com, but that domain no longer exists.
// TODO: I think /app.php is missing a closing php tag.
package nodomain.freeyourgadget.gadgetbridge.service.devices.makibeshr3;
@ -29,10 +33,10 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.UUID;
@ -65,13 +69,10 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.Transaction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(MakibesHR3DeviceSupport.class);
@ -79,7 +80,9 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
private Handler mVibrationHandler = new Handler();
private Vibrator mVibrator;
private CountDownTimer mFetchCountDown = new CountDownTimer(1000, 1000) {
// The delay must be at least as long as it takes the watch to respond.
// Reordering the requests could maybe reduce the delay, but this works fine too.
private CountDownTimer mFetchCountDown = new CountDownTimer(2000, 2000) {
@Override
public void onTick(long millisUntilFinished) {
@ -515,6 +518,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
this.setTimeMode(transaction, sharedPreferences);
this.setDateTime(transaction);
this.setQuiteHours(transaction, sharedPreferences);
this.setHeadsUpScreen(transaction, sharedPreferences);
this.setLostReminder(transaction, sharedPreferences);
@ -547,6 +551,10 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
this.setHeadsUpScreen(transactionBuilder, sharedPreferences);
} else if (key.equals(MakibesHR3Constants.PREF_LOST_REMINDER)) {
this.setLostReminder(transactionBuilder, sharedPreferences);
} else if (key.equals(MakibesHR3Constants.PREF_DO_NOT_DISTURB) ||
key.equals(MakibesHR3Constants.PREF_DO_NOT_DISTURB_START) ||
key.equals(MakibesHR3Constants.PREF_DO_NOT_DISTURB_END)) {
this.setQuiteHours(transactionBuilder, sharedPreferences);
} else {
return;
}
@ -901,8 +909,6 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
int yearHeartRateAfter, int monthHeartRateAfter, int dayHeartRateAfter,
int hourHeartRateAfter, int minuteHeartRateAfter) {
this.fetch(true);
byte[] data = this.craftData(MakibesHR3Constants.CMD_REQUEST_FITNESS,
new byte[]{
(byte) 0x00,
@ -920,6 +926,8 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
transaction.write(this.mControlCharacteristic, data);
this.fetch(true);
return this;
}
@ -937,10 +945,10 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
MakibesHR3ActivitySample latestSample = provider.getLatestActivitySample();
if (true || latestSample == null) {
if (latestSample == null) {
this.requestFitness(transaction,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0);
2000, 0, 0, 0, 0,
2000, 0, 0, 0, 0);
} else {
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date(latestSample.getTimestamp() * 1000l));
@ -1044,6 +1052,33 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
return this;
}
private MakibesHR3DeviceSupport setQuiteHours(TransactionBuilder transactionBuilder,
boolean enable,
int hourStart, int minuteStart,
int hourEnd, int minuteEnd) {
byte[] data = this.craftData(MakibesHR3Constants.CMD_SET_QUITE_HOURS, new byte[]{
(byte) (enable ? 0x01 : 0x00),
(byte) hourStart, (byte) minuteStart,
(byte) hourEnd, (byte) minuteEnd
});
transactionBuilder.write(this.mControlCharacteristic, data);
return this;
}
private MakibesHR3DeviceSupport setQuiteHours(TransactionBuilder transactionBuilder,
SharedPreferences sharedPreferences) {
Calendar start = new GregorianCalendar();
Calendar end = new GregorianCalendar();
boolean enable = MakibesHR3Coordinator.getQuiteHours(sharedPreferences, start, end);
return this.setQuiteHours(transactionBuilder, enable,
start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE),
end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE));
}
private MakibesHR3DeviceSupport setHeadsUpScreen(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) {
return this.setHeadsUpScreen(transactionBuilder,
MakibesHR3Coordinator.shouldEnableHeadsUpScreen(sharedPreferences));

View File

@ -162,6 +162,15 @@
<item>MM/dd/yyyy</item>
</string-array>
<string-array name="do_not_disturb_no_auto">
<item>@string/mi2_dnd_off</item>
<item>@string/mi2_dnd_scheduled</item>
</string-array>
<string-array name="do_not_disturb_no_auto_values">
<item>@string/p_off</item>
<item>@string/p_scheduled</item>
</string-array>
<string-array name="mi2_do_not_disturb">
<item>@string/mi2_dnd_off</item>
<item>@string/mi2_dnd_automatic</item>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
android:icon="@drawable/ic_do_not_disturb"
android:key="screen_do_not_disturb_no_auto"
android:persistent="false"
android:summary="@string/mi2_prefs_do_not_disturb_summary"
android:title="@string/mi2_prefs_do_not_disturb">
<!-- workaround for missing toolbar -->
<PreferenceCategory android:title="@string/mi2_prefs_do_not_disturb" />
<ListPreference
android:defaultValue="@string/p_off"
android:entries="@array/do_not_disturb_no_auto"
android:entryValues="@array/do_not_disturb_no_auto_values"
android:key="do_not_disturb_no_auto"
android:summary="%s"
android:title="@string/mi2_prefs_do_not_disturb" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="01:00"
android:key="do_not_disturb_no_auto_start"
android:title="@string/mi2_prefs_do_not_disturb_start" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="06:00"
android:key="do_not_disturb_no_auto_end"
android:title="@string/mi2_prefs_do_not_disturb_end" />
</PreferenceScreen>
</androidx.preference.PreferenceScreen>