forked from Blendman974/faceclaw
G1 support: Preserve connections after flashing, debug
This commit is contained in:
1 parent
595b462b2e
commit
b353483ac2
38 files changed
+1291
-178
No files matched your search
@@ -1,12 +1,26 @@
|
||||
import { classifyAdvertisement, hasEvenManufacturerSignature, type EvenAdvertisement } from './even-advertisement'
|
||||
import { classifyAdvertisement, g1FromName, hasEvenManufacturerSignature, type EvenAdvertisement } from './even-advertisement'
|
||||
import { hexToBytes } from '../util/hex-util'
|
||||
|
||||
export type IosAdvertisement = { identifier: string; name: string; manufacturerData: string; rssi: number; connectable: boolean }
|
||||
export type IosDevice = EvenAdvertisement & { identifier: string }
|
||||
|
||||
/**
|
||||
* A G1 arm advertises no full MAC, and CoreBluetooth hides the real one. Faceclaw's addresses are MAC-shaped everywhere, so its
|
||||
* address on this phone is made from the peripheral identifier. It's stable as long as the identifier is, which on firmware
|
||||
* 0.5.66 and later is across installs too, and it only has to mean something on this phone: nobody types it in.
|
||||
*/
|
||||
export function g1IosAddress(identifier: string): string {
|
||||
return identifier.replace(/-/g, '').slice(0, 12).toUpperCase().replace(/(..)(?=.)/g, '$1:')
|
||||
}
|
||||
|
||||
/** Only a full vendor-advertised MAC may bind a manually entered address. */
|
||||
export function identifyIosPeripheral(raw: IosAdvertisement): IosDevice | null {
|
||||
if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(raw.identifier)) return null
|
||||
if (g1FromName(raw.name)) {
|
||||
const arm = classifyAdvertisement({ ...raw, address: g1IosAddress(raw.identifier), source: 'scan', bonded: false,
|
||||
txPower: null, seenAtMs: Date.now() })
|
||||
return arm && { ...arm, identifier: raw.identifier.toUpperCase() }
|
||||
}
|
||||
if (!hasEvenManufacturerSignature(hexToBytes(raw.manufacturerData))) return null
|
||||
const candidate = classifyAdvertisement({ ...raw, address: '', source: 'scan', bonded: false,
|
||||
txPower: null, seenAtMs: Date.now() })
|
||||
|
||||
Reference in new issue
Block a user