Added getting RileyLink battery level

This commit is contained in:
Artiom Kenibasov 2020-12-18 23:41:23 +01:00
parent 96e05f239a
commit 95c6cf6d85
6 changed files with 57 additions and 2 deletions

View file

@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.SET_DEBUG_APP" />
<application> <application>
<activity android:name=".dialog.RileyLinkBLEScanActivity"> <activity android:name=".dialog.RileyLinkBLEScanActivity">

View file

@ -57,6 +57,8 @@ public class RFSpy {
private final UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO); private final UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
private final UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA); private final UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA);
private final UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION); private final UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION);
private final UUID batteryServiceUUID = UUID.fromString(GattAttributes.SERVICE_BATTERY);
private final UUID batteryLevelUUID = UUID.fromString(GattAttributes.CHARA_BATTERY_UNK);
//private UUID responseCountUUID = UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT); //private UUID responseCountUUID = UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT);
private RileyLinkFirmwareVersion firmwareVersion; private RileyLinkFirmwareVersion firmwareVersion;
private String bleVersion; // We don't use it so no need of sofisticated logic private String bleVersion; // We don't use it so no need of sofisticated logic
@ -111,6 +113,19 @@ public class RFSpy {
} }
public Integer getBatteryLevel() {
BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID);
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
Integer value = (int) result.value[0];
aapsLogger.debug(LTag.PUMPBTCOMM, "BLE battery level: " + value.toString());
return value;
} else {
aapsLogger.error(LTag.PUMPBTCOMM, "getBatteryLevel failed with code: " + result.resultCode);
return -1;
}
}
// This gets the version from the BLE113, not from the CC1110. // This gets the version from the BLE113, not from the CC1110.
// I.e., this gets the version from the BLE interface, not from the radio. // I.e., this gets the version from the BLE interface, not from the radio.
public String getVersion() { public String getVersion() {
@ -424,6 +439,8 @@ public class RFSpy {
* Reset RileyLink Configuration (set all updateRegisters) * Reset RileyLink Configuration (set all updateRegisters)
*/ */
public void resetRileyLinkConfiguration() { public void resetRileyLinkConfiguration() {
//TODO: Please move me to an appropriate place!
rileyLinkServiceData.batteryLevel = this.getBatteryLevel();
if (this.currentFrequencyMHz != null) if (this.currentFrequencyMHz != null)
this.setBaseFrequency(this.currentFrequencyMHz); this.setBaseFrequency(this.currentFrequencyMHz);
} }

View file

@ -49,6 +49,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
TextView lastUsedFrequency; TextView lastUsedFrequency;
TextView lastDeviceContact; TextView lastDeviceContact;
TextView firmwareVersion; TextView firmwareVersion;
TextView batteryLevel;
boolean first = false; boolean first = false;
@ -76,12 +77,14 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
this.lastUsedFrequency = getActivity().findViewById(R.id.rls_t1_last_used_frequency); this.lastUsedFrequency = getActivity().findViewById(R.id.rls_t1_last_used_frequency);
this.lastDeviceContact = getActivity().findViewById(R.id.rls_t1_last_device_contact); this.lastDeviceContact = getActivity().findViewById(R.id.rls_t1_last_device_contact);
this.firmwareVersion = getActivity().findViewById(R.id.rls_t1_firmware_version); this.firmwareVersion = getActivity().findViewById(R.id.rls_t1_firmware_version);
this.batteryLevel = getActivity().findViewById(R.id.rls_t1_battery_level);
if (!first) { if (!first) {
// 7-12 // 7-14
int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, // int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12, R.id.rls_t1_tv13}; R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12, R.id.rls_t1_tv13,
R.id.rls_t1_tv14};
for (int id : ids) { for (int id : ids) {
@ -114,6 +117,12 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 +
"\nCC110: " + rileyLinkServiceData.versionCC110); "\nCC110: " + rileyLinkServiceData.versionCC110);
} }
Integer batteryLevel = rileyLinkServiceData.batteryLevel;
if (batteryLevel == null || batteryLevel <= 0) {
this.batteryLevel.setText("???");
} else {
this.batteryLevel.setText(batteryLevel + "%");
}
} }

View file

@ -43,6 +43,7 @@ public class RileyLinkServiceData {
// radio version // radio version
public String versionCC110; public String versionCC110;
public Integer batteryLevel;
public RileyLinkTargetDevice targetDevice; public RileyLinkTargetDevice targetDevice;

View file

@ -134,6 +134,31 @@
android:text=" " /> android:text=" " />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="16pt"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv14"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_weight="35"
android:gravity="center_vertical"
android:text="@string/rileylink_battery_level" />
<TextView
android:id="@+id/rls_t1_battery_level"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_weight="65"
android:textAlignment="center"
android:gravity="center_vertical"
android:text=" " />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -161,6 +186,7 @@
android:text=" " /> android:text=" " />
</LinearLayout> </LinearLayout>
<!-- Group - Device --> <!-- Group - Device -->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -64,6 +64,7 @@
<string name="key_medtronic_encoding" translatable="false">pref_medtronic_encoding</string> <string name="key_medtronic_encoding" translatable="false">pref_medtronic_encoding</string>
<string name="mdt_last_bolus" translatable="false">%1$.1f %2$s (%3$s)</string> <string name="mdt_last_bolus" translatable="false">%1$.1f %2$s (%3$s)</string>
<string name="rileylink_battery_level">RL Battery level</string>
<plurals name="duration_days"> <plurals name="duration_days">
<item quantity="one">%1$d day</item> <item quantity="one">%1$d day</item>