mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 03:16:51 +01:00
Mi2: Support for setting the fitness goal (steps)
This commit is contained in:
parent
9bebf1d32f
commit
3fdfb7d172
@ -282,6 +282,10 @@ public class MiBand2Service {
|
|||||||
// maybe not really activity data, but steps?
|
// maybe not really activity data, but steps?
|
||||||
public static final byte COMMAND_FETCH_ACTIVITY_DATA = 0x02;
|
public static final byte COMMAND_FETCH_ACTIVITY_DATA = 0x02;
|
||||||
|
|
||||||
|
public static final byte[] COMMAND_SET_FITNESS_GOAL_START = new byte[] { 0x10, 0x0, 0x0 };
|
||||||
|
public static final byte[] COMMAND_SET_FITNESS_GOAL_END = new byte[] { 0, 0 };
|
||||||
|
|
||||||
|
|
||||||
public static byte COMMAND_DATEFORMAT = 0x06;
|
public static byte COMMAND_DATEFORMAT = 0x06;
|
||||||
|
|
||||||
public static final byte[] DATEFORMAT_DATE_TIME = new byte[] { COMMAND_DATEFORMAT, 0x0a, 0x0, 0x03 };
|
public static final byte[] DATEFORMAT_DATE_TIME = new byte[] { COMMAND_DATEFORMAT, 0x0a, 0x0, 0x03 };
|
||||||
|
@ -74,6 +74,20 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final Preference fitnessGoal = findPreference(PREF_MIBAND_FITNESS_GOAL);
|
||||||
|
fitnessGoal.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
GBApplication.deviceService().onSendConfiguration(PREF_MIBAND_FITNESS_GOAL);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,10 +10,12 @@ import android.net.Uri;
|
|||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -388,15 +390,15 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
private MiBand2Support setFitnessGoal(TransactionBuilder transaction) {
|
private MiBand2Support setFitnessGoal(TransactionBuilder transaction) {
|
||||||
LOG.info("Attempting to set Fitness Goal...");
|
LOG.info("Attempting to set Fitness Goal...");
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC8);
|
||||||
if (characteristic != null) {
|
if (characteristic != null) {
|
||||||
int fitnessGoal = MiBandCoordinator.getFitnessGoal(getDevice().getAddress());
|
int fitnessGoal = MiBandCoordinator.getFitnessGoal(getDevice().getAddress());
|
||||||
transaction.write(characteristic, new byte[]{
|
byte[] bytes = ArrayUtils.addAll(
|
||||||
MiBandService.COMMAND_SET_FITNESS_GOAL,
|
MiBand2Service.COMMAND_SET_FITNESS_GOAL_START,
|
||||||
0,
|
BLETypeConversions.fromUint16(fitnessGoal));
|
||||||
(byte) (fitnessGoal & 0xff),
|
bytes = ArrayUtils.addAll(bytes,
|
||||||
(byte) ((fitnessGoal >>> 8) & 0xff)
|
MiBand2Service.COMMAND_SET_FITNESS_GOAL_END);
|
||||||
});
|
transaction.write(characteristic, bytes);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unable to set Fitness Goal");
|
LOG.info("Unable to set Fitness Goal");
|
||||||
}
|
}
|
||||||
@ -419,7 +421,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
case 0: // left hand
|
case 0: // left hand
|
||||||
builder.write(characteristic, MiBand2Service.WEAR_LOCATION_LEFT_WRIST);
|
builder.write(characteristic, MiBand2Service.WEAR_LOCATION_LEFT_WRIST);
|
||||||
break;
|
break;
|
||||||
case 1: // write hand
|
case 1: // right hand
|
||||||
builder.write(characteristic, MiBand2Service.WEAR_LOCATION_RIGHT_WRIST);
|
builder.write(characteristic, MiBand2Service.WEAR_LOCATION_RIGHT_WRIST);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1181,6 +1183,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT:
|
case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT:
|
||||||
setActivateDisplayOnLiftWrist(builder);
|
setActivateDisplayOnLiftWrist(builder);
|
||||||
break;
|
break;
|
||||||
|
case MiBandConst.PREF_MIBAND_FITNESS_GOAL:
|
||||||
|
setFitnessGoal(builder);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
builder.queue(getQueue());
|
builder.queue(getQueue());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -1222,6 +1227,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
enableFurtherNotifications(builder, true);
|
enableFurtherNotifications(builder, true);
|
||||||
setDateDisplay(builder);
|
setDateDisplay(builder);
|
||||||
setWearLocation(builder);
|
setWearLocation(builder);
|
||||||
|
setFitnessGoal(builder);
|
||||||
setActivateDisplayOnLiftWrist(builder);
|
setActivateDisplayOnLiftWrist(builder);
|
||||||
setHeartrateSleepSupport(builder);
|
setHeartrateSleepSupport(builder);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user