mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 13:26:50 +01:00
Send user info to the watch, add more daily targets (goals) and send them to the watch.
This commit is contained in:
parent
ca7108c153
commit
8062729ea8
@ -113,5 +113,6 @@ public class ZeTimeConstants {
|
|||||||
|
|
||||||
public static final String PREF_SCREENTIME = "zetime_screentime";
|
public static final String PREF_SCREENTIME = "zetime_screentime";
|
||||||
public static final int MAX_SCREEN_ON_TIME = 0xffff;
|
public static final int MAX_SCREEN_ON_TIME = 0xffff;
|
||||||
|
public static final int MIN_SCREEN_ON_TIME = 0x000a;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,9 @@ public class ActivityUser {
|
|||||||
private int activityUserWeightKg;
|
private int activityUserWeightKg;
|
||||||
private int activityUserSleepDuration;
|
private int activityUserSleepDuration;
|
||||||
private int activityUserStepsGoal;
|
private int activityUserStepsGoal;
|
||||||
|
private int activityUserCaloriesBurnt;
|
||||||
|
private int activityUserDistanceKMeters;
|
||||||
|
private int activityUserActiveTimeMinutes;
|
||||||
|
|
||||||
private static final String defaultUserName = "gadgetbridge-user";
|
private static final String defaultUserName = "gadgetbridge-user";
|
||||||
public static final int defaultUserGender = GENDER_FEMALE;
|
public static final int defaultUserGender = GENDER_FEMALE;
|
||||||
@ -50,6 +53,9 @@ public class ActivityUser {
|
|||||||
public static final int defaultUserWeightKg = 70;
|
public static final int defaultUserWeightKg = 70;
|
||||||
public static final int defaultUserSleepDuration = 7;
|
public static final int defaultUserSleepDuration = 7;
|
||||||
public static final int defaultUserStepsGoal = 8000;
|
public static final int defaultUserStepsGoal = 8000;
|
||||||
|
public static final int defaultUserCaloriesBurnt = 2000;
|
||||||
|
public static final int defaultUserDistanceKMeters = 5;
|
||||||
|
public static final int defaultUserActiveTimeMinutes = 60;
|
||||||
|
|
||||||
public static final String PREF_USER_NAME = "mi_user_alias";
|
public static final String PREF_USER_NAME = "mi_user_alias";
|
||||||
public static final String PREF_USER_YEAR_OF_BIRTH = "activity_user_year_of_birth";
|
public static final String PREF_USER_YEAR_OF_BIRTH = "activity_user_year_of_birth";
|
||||||
@ -58,6 +64,9 @@ public class ActivityUser {
|
|||||||
public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg";
|
public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg";
|
||||||
public static final String PREF_USER_SLEEP_DURATION = "activity_user_sleep_duration";
|
public static final String PREF_USER_SLEEP_DURATION = "activity_user_sleep_duration";
|
||||||
public static final String PREF_USER_STEPS_GOAL = "mi_fitness_goal"; // FIXME: for compatibility
|
public static final String PREF_USER_STEPS_GOAL = "mi_fitness_goal"; // FIXME: for compatibility
|
||||||
|
public static final String PREF_USER_CALORIES_BURNT = "activity_user_calories_burnt";
|
||||||
|
public static final String PREF_USER_DISTANCE_KMETERS = "activity_user_distance_kmeters";
|
||||||
|
public static final String PREF_USER_ACTIVETIME_MINUTES = "activity_user_activetime_minutes";
|
||||||
|
|
||||||
public ActivityUser() {
|
public ActivityUser() {
|
||||||
fetchPreferences();
|
fetchPreferences();
|
||||||
@ -127,6 +136,9 @@ public class ActivityUser {
|
|||||||
activityUserYearOfBirth = prefs.getInt(PREF_USER_YEAR_OF_BIRTH, defaultUserYearOfBirth);
|
activityUserYearOfBirth = prefs.getInt(PREF_USER_YEAR_OF_BIRTH, defaultUserYearOfBirth);
|
||||||
activityUserSleepDuration = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDuration);
|
activityUserSleepDuration = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDuration);
|
||||||
activityUserStepsGoal = prefs.getInt(PREF_USER_STEPS_GOAL, defaultUserStepsGoal);
|
activityUserStepsGoal = prefs.getInt(PREF_USER_STEPS_GOAL, defaultUserStepsGoal);
|
||||||
|
activityUserCaloriesBurnt = prefs.getInt(PREF_USER_CALORIES_BURNT, defaultUserCaloriesBurnt);
|
||||||
|
activityUserDistanceKMeters = prefs.getInt(PREF_USER_DISTANCE_KMETERS, defaultUserDistanceKMeters);
|
||||||
|
activityUserActiveTimeMinutes = prefs.getInt(PREF_USER_ACTIVETIME_MINUTES, defaultUserActiveTimeMinutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getUserBirthday() {
|
public Date getUserBirthday() {
|
||||||
@ -134,4 +146,28 @@ public class ActivityUser {
|
|||||||
cal.set(GregorianCalendar.YEAR, getYearOfBirth());
|
cal.set(GregorianCalendar.YEAR, getYearOfBirth());
|
||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCaloriesBurnt()
|
||||||
|
{
|
||||||
|
if (activityUserCaloriesBurnt < 0) {
|
||||||
|
activityUserCaloriesBurnt = defaultUserCaloriesBurnt;
|
||||||
|
}
|
||||||
|
return activityUserCaloriesBurnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDistanceKMeters()
|
||||||
|
{
|
||||||
|
if (activityUserDistanceKMeters < 0) {
|
||||||
|
activityUserDistanceKMeters = defaultUserDistanceKMeters;
|
||||||
|
}
|
||||||
|
return activityUserDistanceKMeters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getActiveTimeMinutes()
|
||||||
|
{
|
||||||
|
if (activityUserActiveTimeMinutes < 0) {
|
||||||
|
activityUserActiveTimeMinutes = defaultUserActiveTimeMinutes;
|
||||||
|
}
|
||||||
|
return activityUserActiveTimeMinutes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimeSampleProvider;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.entities.ZeTimeActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.ZeTimeActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
||||||
@ -120,8 +121,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
builder.notify(notifyCharacteristic, true);
|
builder.notify(notifyCharacteristic, true);
|
||||||
requestDeviceInfo(builder);
|
requestDeviceInfo(builder);
|
||||||
requestBatteryInfo(builder);
|
requestBatteryInfo(builder);
|
||||||
|
setUserInfo(builder);
|
||||||
setWrist(builder);
|
setWrist(builder);
|
||||||
setScreenTime(builder);
|
setScreenTime(builder);
|
||||||
|
setUserGoals(builder);
|
||||||
requestActivityInfo(builder);
|
requestActivityInfo(builder);
|
||||||
synchronizeTime(builder);
|
synchronizeTime(builder);
|
||||||
|
|
||||||
@ -1183,6 +1186,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
{
|
{
|
||||||
GB.toast(getContext(), "Value for screen on time is greater than 18h! ", Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getContext(), "Value for screen on time is greater than 18h! ", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
value = ZeTimeConstants.MAX_SCREEN_ON_TIME;
|
value = ZeTimeConstants.MAX_SCREEN_ON_TIME;
|
||||||
|
} else if(value < ZeTimeConstants.MIN_SCREEN_ON_TIME)
|
||||||
|
{
|
||||||
|
GB.toast(getContext(), "Value for screen on time is lesser than 10s! ", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
value = ZeTimeConstants.MIN_SCREEN_ON_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] screentime = {ZeTimeConstants.CMD_PREAMBLE,
|
byte[] screentime = {ZeTimeConstants.CMD_PREAMBLE,
|
||||||
@ -1196,4 +1203,84 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
sendMsgToWatch(builder, screentime);
|
sendMsgToWatch(builder, screentime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUserInfo(TransactionBuilder builder)
|
||||||
|
{
|
||||||
|
ActivityUser activityUser = new ActivityUser();
|
||||||
|
byte gender = (byte)activityUser.getGender();
|
||||||
|
int age = activityUser.getAge();
|
||||||
|
int height = activityUser.getHeightCm();
|
||||||
|
int weight = activityUser.getWeightKg()*10; // weight is set and get in 100g granularity
|
||||||
|
|
||||||
|
if(gender == ActivityUser.GENDER_MALE) // translate gender for zetime
|
||||||
|
{
|
||||||
|
gender = 0;
|
||||||
|
} else if(gender == ActivityUser.GENDER_FEMALE)
|
||||||
|
{
|
||||||
|
gender = 1;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
gender = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] userinfo = {ZeTimeConstants.CMD_PREAMBLE,
|
||||||
|
ZeTimeConstants.CMD_USER_INFO,
|
||||||
|
ZeTimeConstants.CMD_SEND,
|
||||||
|
(byte)0x5,
|
||||||
|
(byte)0x0,
|
||||||
|
gender,
|
||||||
|
(byte)age,
|
||||||
|
(byte)height,
|
||||||
|
(byte)(weight & 0xff),
|
||||||
|
(byte)(weight >> 8),
|
||||||
|
ZeTimeConstants.CMD_END};
|
||||||
|
sendMsgToWatch(builder, userinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUserGoals(TransactionBuilder builder)
|
||||||
|
{
|
||||||
|
ActivityUser activityUser = new ActivityUser();
|
||||||
|
int steps = activityUser.getStepsGoal() / 100; // ZeTime expect the steps in 100 increment
|
||||||
|
int calories = activityUser.getCaloriesBurnt();
|
||||||
|
int distance = activityUser.getDistanceKMeters();
|
||||||
|
int sleep = activityUser.getSleepDuration();
|
||||||
|
int activeTime = activityUser.getActiveTimeMinutes();
|
||||||
|
|
||||||
|
// set steps goal
|
||||||
|
byte[] goal = {ZeTimeConstants.CMD_PREAMBLE,
|
||||||
|
ZeTimeConstants.CMD_GOALS,
|
||||||
|
ZeTimeConstants.CMD_SEND,
|
||||||
|
(byte)0x4,
|
||||||
|
(byte)0x0,
|
||||||
|
(byte)0x0,
|
||||||
|
(byte)(steps & 0xff),
|
||||||
|
(byte)(steps >> 8),
|
||||||
|
(byte)0x1,
|
||||||
|
ZeTimeConstants.CMD_END};
|
||||||
|
sendMsgToWatch(builder, goal);
|
||||||
|
|
||||||
|
// set calories goal
|
||||||
|
goal[5] = (byte)0x1;
|
||||||
|
goal[6] = (byte)(calories & 0xff);
|
||||||
|
goal[7] = (byte)(calories >> 8);
|
||||||
|
sendMsgToWatch(builder, goal);
|
||||||
|
|
||||||
|
// set distance goal
|
||||||
|
goal[5] = (byte)0x2;
|
||||||
|
goal[6] = (byte)(distance & 0xff);
|
||||||
|
goal[7] = (byte)(distance >> 8);
|
||||||
|
sendMsgToWatch(builder, goal);
|
||||||
|
|
||||||
|
// set sleep goal
|
||||||
|
goal[5] = (byte)0x3;
|
||||||
|
goal[6] = (byte)(sleep & 0xff);
|
||||||
|
goal[7] = (byte)(sleep >> 8);
|
||||||
|
sendMsgToWatch(builder, goal);
|
||||||
|
|
||||||
|
// set active time goal
|
||||||
|
goal[5] = (byte)0x4;
|
||||||
|
goal[6] = (byte)(activeTime & 0xff);
|
||||||
|
goal[7] = (byte)(activeTime >> 8);
|
||||||
|
sendMsgToWatch(builder, goal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -571,6 +571,10 @@
|
|||||||
<string name="korean">Koreanisch</string>
|
<string name="korean">Koreanisch</string>
|
||||||
<string name="japanese">Japanisch</string>
|
<string name="japanese">Japanisch</string>
|
||||||
|
|
||||||
|
<string name="activity_prefs_calories_burnt">Tägliches Ziel: verbrannte Kalorien</string>
|
||||||
|
<string name="activity_prefs_distance_km">Tägliches Ziel: zurückgelegte Strecke in km</string>
|
||||||
|
<string name="activity_prefs_activetime_minutes">Tägliches Ziel: aktive Zeit in Minuten</string>
|
||||||
|
|
||||||
<!-- ZeTime Preferences -->
|
<!-- ZeTime Preferences -->
|
||||||
<string name="zetime_title_settings">ZeTime Einstellungen</string>
|
<string name="zetime_title_settings">ZeTime Einstellungen</string>
|
||||||
<string name="zetime_title_screentime">Bildschirm-An-Dauer in Sekunden</string>
|
<string name="zetime_title_screentime">Bildschirm-An-Dauer in Sekunden</string>
|
||||||
|
@ -500,6 +500,10 @@
|
|||||||
<string name="charts_legend_heartrate">Heart rate</string>
|
<string name="charts_legend_heartrate">Heart rate</string>
|
||||||
<string name="live_activity_heart_rate">Heart rate</string>
|
<string name="live_activity_heart_rate">Heart rate</string>
|
||||||
|
|
||||||
|
<string name="activity_prefs_calories_burnt">Daily target: calories burnt</string>
|
||||||
|
<string name="activity_prefs_distance_km">Daily target: distance in km</string>
|
||||||
|
<string name="activity_prefs_activetime_minutes">Daily target: active time in minutes</string>
|
||||||
|
|
||||||
<string name="pref_title_pebble_health_store_raw">Store raw record in the database</string>
|
<string name="pref_title_pebble_health_store_raw">Store raw record in the database</string>
|
||||||
<string name="pref_summary_pebble_health_store_raw">Stores the data \"as is\", increasing the database usage to allow for later interpretation.</string>
|
<string name="pref_summary_pebble_health_store_raw">Stores the data \"as is\", increasing the database usage to allow for later interpretation.</string>
|
||||||
<string name="action_db_management">Database management</string>
|
<string name="action_db_management">Database management</string>
|
||||||
|
@ -100,6 +100,27 @@
|
|||||||
android:key="activity_user_sleep_duration"
|
android:key="activity_user_sleep_duration"
|
||||||
android:maxLength="2"
|
android:maxLength="2"
|
||||||
android:title="@string/activity_prefs_sleep_duration" />
|
android:title="@string/activity_prefs_sleep_duration" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="2000"
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="activity_user_calories_burnt"
|
||||||
|
android:maxLength="4"
|
||||||
|
android:title="@string/activity_prefs_calories_burnt" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="5"
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="activity_user_distance_kmeters"
|
||||||
|
android:maxLength="3"
|
||||||
|
android:title="@string/activity_prefs_distance_km" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="60"
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="activity_user_activetime_minutes"
|
||||||
|
android:maxLength="3"
|
||||||
|
android:title="@string/activity_prefs_activetime_minutes" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:key="pref_charts"
|
android:key="pref_charts"
|
||||||
|
Loading…
Reference in New Issue
Block a user