1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 02:46:50 +01:00

Improve notification support for InfiniTime (PineTime) :

- InfiniTime 0.9 now supports messages up to 100 chars (instead of max 18 previously)
 - Remove the hack that was implemented as a workaround to a bug in InfiniTime that would ignore the last character of the notification message (https://github.com/JF002/Pinetime/issues/109).

 These 2 features are enabled only if the firmware version is >= 0.9.
This commit is contained in:
JF 2020-10-21 17:57:33 +02:00 committed by Gitea
parent c85e30cb07
commit 9d6ac2b985

View File

@ -24,6 +24,7 @@ import android.widget.Toast;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -72,6 +73,10 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
private static final Logger LOG = LoggerFactory.getLogger(PineTimeJFSupport.class);
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
private final DeviceInfoProfile<PineTimeJFSupport> deviceInfoProfile;
private final int MaxNotificationLength = 100;
private int firmwareVersionMajor = 0;
private int firmwareVersionMinor = 0;
private int firmwareVersionPatch = 0;
/**
* These are used to keep track when long strings haven't changed,
* thus avoiding unnecessary transfers that are (potentially) very slow.
@ -227,8 +232,19 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
@Override
public void onNotification(NotificationSpec notificationSpec) {
TransactionBuilder builder = new TransactionBuilder("notification");
NewAlert alert = new NewAlert(AlertCategory.CustomHuami, 1, notificationSpec.body + " "); // HACK: no idea why the last byte is swallowed
String message = notificationSpec.body;
if(!IsFirmwareAtLeastVersion0_9()) {
// Firmware versions prior to 0.9 ignore the last characters of the notification message
// Add an space character so that the whole message will be displayed
message += " ";
}
NewAlert alert = new NewAlert(AlertCategory.CustomHuami, 1, message);
AlertNotificationProfile<?> profile = new AlertNotificationProfile<>(this);
if(IsFirmwareAtLeastVersion0_9()) {
// InfiniTime 0.9+ support notification message of up to 100 characters
// Instead of 18 by default
profile.setMaxLength(MaxNotificationLength);
}
profile.newAlert(builder, alert, OverflowStrategy.TRUNCATE);
builder.queue(getQueue());
}
@ -573,9 +589,24 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
LOG.warn("Device info: " + info);
versionCmd.hwVersion = info.getHardwareRevision();
versionCmd.fwVersion = info.getFirmwareRevision();
if(versionCmd.fwVersion != null && !versionCmd.fwVersion.isEmpty()) {
// FW version format : "major.minor.patch". Ex : "0.8.2"
String[] tokens = StringUtils.split(versionCmd.fwVersion, ".");
if(tokens.length == 3) {
firmwareVersionMajor = Integer.parseInt(tokens[0]);
firmwareVersionMinor = Integer.parseInt(tokens[1]);
firmwareVersionPatch = Integer.parseInt(tokens[2]);
}
}
handleGBDeviceEvent(versionCmd);
}
private boolean IsFirmwareAtLeastVersion0_9() {
return firmwareVersionMajor > 0 || firmwareVersionMinor >= 9;
}
/**
* Nordic DFU needs this function to log DFU-related messages
*/