Even Realities G1: Support More BLE Device Names

Some glasses have shown up that have the format G1_X_L instead of the
previously expecte G1_XX_L. Update the regex so it can support any
number of digits in that position.
This commit is contained in:
jrthomas270
2025-10-11 13:03:35 -07:00
parent 2c8fb9a65f
commit 8e7dc26078
2 changed files with 14 additions and 15 deletions
@@ -53,10 +53,10 @@ public class G1DeviceCoordinator extends AbstractBLEDeviceCoordinator {
@Override @Override
protected Pattern getSupportedDeviceName() { protected Pattern getSupportedDeviceName() {
// eg. G1_45_L_F2333, G1_63_R_04935. // eg. G1_45_L_F2333, G1_63_R_04935, G1_2_R_B7D35.
// Note that the G1_XX_L_YYYYY will have a corresponding G1_XX_R_ZZZZZ. The XX will match, // Note that the G1_XX_L_YYYYY will have a corresponding G1_XX_R_ZZZZZ. The XX will match,
// but the trailing 5 characters will not. // but the trailing 5 characters will not.
return Pattern.compile("Even G1_\\d\\d_[L|R]_\\w+"); return Pattern.compile("Even G1_\\d+_[L|R]_\\w+");
} }
@Override @Override
@@ -35,14 +35,13 @@ public class G1Constants {
// Extract the L or R at the end of the device prefix. // Extract the L or R at the end of the device prefix.
public static Side getSideFromFullName(String deviceName) { public static Side getSideFromFullName(String deviceName) {
int prefixSize = "Even G1_XX_X".length(); // Name will be "G1_XX_[L|R]_YYYYY"
int firstUnderScore = deviceName.indexOf('_');
if (firstUnderScore < 0) return null;
int prefixSize = deviceName.indexOf('_', firstUnderScore);
if (prefixSize < 0) return null;
if (deviceName.length() < prefixSize) { char side = deviceName.charAt(prefixSize+1);
return null;
}
String prefix = deviceName.substring(0, prefixSize);
char side = prefix.charAt(prefix.length() - 1);
if (side == 'L' || side == 'R') { if (side == 'L' || side == 'R') {
return side == 'L' ? Side.LEFT : Side.RIGHT; return side == 'L' ? Side.LEFT : Side.RIGHT;
} }
@@ -51,13 +50,13 @@ public class G1Constants {
} }
public static String getNameFromFullName(String deviceName) { public static String getNameFromFullName(String deviceName) {
int prefixSize = "Even G1_XX".length(); // Name will be "G1_XX_[L|R]_YYYYY"
int firstUnderScore = deviceName.indexOf('_');
if (firstUnderScore < 0) return null;
int prefixSize = deviceName.indexOf('_', firstUnderScore);
if (prefixSize < 0) return null;
if (deviceName.length() < prefixSize) { return deviceName.substring(0, prefixSize-1);
return null;
}
return deviceName.substring(0, prefixSize);
} }
public enum Side { public enum Side {