Even Realities G1: Handle MTU change as the device expects

The Glasses expect a notification when the MTU chagnes, so forward the
new MTU value to the glasses.
This commit is contained in:
jrthomas270
2025-10-04 10:48:30 -07:00
parent e8f7a1fad3
commit b10669d933
3 changed files with 37 additions and 6 deletions
@@ -179,24 +179,27 @@ public class G1Communications {
protected abstract int getHeaderSize();
}
public static class CommandSendInit extends CommandHandler {
public CommandSendInit() {
public static class CommandSendMtu extends CommandHandler {
private final byte mtu;
public CommandSendMtu(byte mtu) {
super(true, null);
this.mtu = mtu;
}
@Override
public byte[] serialize() {
return new byte[] { G1Constants.CommandId.INIT.id, (byte)0xFB };
return new byte[] { G1Constants.CommandId.SET_MTU.id, mtu };
}
@Override
public boolean responseMatches(byte[] payload) {
return payload[0] == G1Constants.CommandId.INIT.id;
return payload[0] == G1Constants.CommandId.SET_MTU.id;
}
@Override
public String getName() {
return "send_init";
return "send_mtu";
}
}
@@ -112,7 +112,7 @@ public class G1Constants {
SYSTEM((byte) 0x23),
HEARTBEAT((byte) 0x25),
BATTERY_LEVEL((byte) 0x2C),
INIT((byte) 0x4D),
SET_MTU((byte) 0x4D),
NOTIFICATION((byte) 0x4B),
FW_INFO_RESPONSE((byte) 0x6E),
DEBUG_LOG((byte) 0xF4),
@@ -282,6 +282,34 @@ public class G1DeviceSupport extends AbstractBTLEMultiDeviceSupport {
// Below are all the onXXX() handlers overridden from the base class. //
////////////////////////////////////////////////////////////////////////
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
// If the status was not successful, don't forward to the glasses.
if (status != BluetoothGatt.GATT_SUCCESS) {
return;
}
// The glasses expect to be forwarded the MTU, so when it is changed, also notify the side
// that it changed on.
String address = gatt.getDevice().getAddress();
if (getDevice(G1Constants.Side.LEFT.getDeviceIndex()) != null) {
String leftAddress = getDevice(G1Constants.Side.LEFT.getDeviceIndex()).getAddress();
if (address.equals(leftAddress) && leftSide != null) {
leftSide.send(new G1Communications.CommandSendMtu((byte)mtu));
}
}
if (getDevice(G1Constants.Side.RIGHT.getDeviceIndex()) != null) {
String rightAddress =
getDevice(G1Constants.Side.RIGHT.getDeviceIndex()).getAddress();
if (address.equals(rightAddress) && rightSide != null) {
rightSide.send(new G1Communications.CommandSendMtu((byte)mtu));
}
}
}
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,