Skip to content

Commit

Permalink
Improve notification support for InfiniTime (PineTime) :
Browse files Browse the repository at this point in the history
 - 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 (InfiniTimeOrg/InfiniTime#109).

 These 2 features are enabled only if the firmware version is >= 0.9.
  • Loading branch information
JF002 authored and Gitea committed Oct 23, 2020
1 parent c85e30c commit 9d6ac2b
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -227,8 +232,19 @@ public boolean useAutoConnect() {
@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());
}
Expand Down Expand Up @@ -573,9 +589,24 @@ private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.
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
*/
Expand Down

0 comments on commit 9d6ac2b

Please sign in to comment.