diff --git a/src/device/DeviceWizard.tsx b/src/device/DeviceWizard.tsx index cf0a061..3bb7fb9 100644 --- a/src/device/DeviceWizard.tsx +++ b/src/device/DeviceWizard.tsx @@ -226,7 +226,6 @@ export default function DeviceWizard(props: Props) { */ const adjustAvailablePositions = (port: PortInformation, availability: DeviceAvailabilityMap) => { let currentAvailability = availability; - console.log(port) switch (port.addressType) { case quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY: currentAvailability.set(port.addressType, [{ address: port.address, label: port.label }]); diff --git a/src/models/Device.ts b/src/models/Device.ts index 6ee074d..f4ea4ee 100644 --- a/src/models/Device.ts +++ b/src/models/Device.ts @@ -181,6 +181,59 @@ export class Device { return max } + private versionComparison(deviceVersion: string, requiredVersion: string): boolean { + const parse = (v: string) => { + const [core, pre] = v.split("-"); + const parts = core.split(".").map(n => parseInt(n, 10)); + + let preLabel = ""; + let preNum = 0; + + if (pre) { + const match = pre.match(/^([a-zA-Z]+)(\d*)$/); + if (match) { + preLabel = match[1].toLowerCase(); + preNum = match[2] ? parseInt(match[2], 10) : 0; + } + } + + return { parts, preLabel, preNum }; + }; + + const rank = (label: string): number => { + switch (label) { + case "alpha": return 1; + case "beta": return 2; + case "rc": return 3; + default: return 0; // release + } + }; + + const a = parse(deviceVersion); + const b = parse(requiredVersion); + + // Compare major/minor/patch + const len = Math.max(a.parts.length, b.parts.length); + for (let i = 0; i < len; i++) { + const av = a.parts[i] ?? 0; + const bv = b.parts[i] ?? 0; + if (av > bv) return true; + if (av < bv) return false; + } + + // Handle prerelease vs release + if (!a.preLabel && b.preLabel) return true; // release > prerelease + if (a.preLabel && !b.preLabel) return false; + + // Both prereleases → compare rank + if (a.preLabel !== b.preLabel) { + return rank(a.preLabel) >= rank(b.preLabel); + } + + // Same prerelease label → compare numeric suffix + return a.preNum >= b.preNum; + } + public featureSupported(feature: string): boolean { let versions = featureVersions.get(feature); if (!versions) { @@ -188,27 +241,27 @@ export class Device { } switch (this.settings.platform) { case pond.DevicePlatform.DEVICE_PLATFORM_PHOTON: - return this.status.firmwareVersion >= versions.photon; + return this.versionComparison(this.status.firmwareVersion, versions.photon); case pond.DevicePlatform.DEVICE_PLATFORM_ELECTRON: - return this.status.firmwareVersion >= versions.electron; + return this.versionComparison(this.status.firmwareVersion, versions.electron); case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR: - return this.status.firmwareVersion >= versions.v2Cell; + return this.versionComparison(this.status.firmwareVersion, versions.v2Cell); case pond.DevicePlatform.DEVICE_PLATFORM_V2_WIFI: - return this.status.firmwareVersion >= versions.v2Wifi; + return this.versionComparison(this.status.firmwareVersion, versions.v2Wifi); case pond.DevicePlatform.DEVICE_PLATFORM_V2_WIFI_S3: - return this.status.firmwareVersion >= versions.v2WifiS3; + return this.versionComparison(this.status.firmwareVersion, versions.v2WifiS3); case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_S3: - return this.status.firmwareVersion >= versions.v2CellS3; + return this.versionComparison(this.status.firmwareVersion, versions.v2CellS3); case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_BLACK: - return this.status.firmwareVersion >= versions.v2CellBlack; + return this.versionComparison(this.status.firmwareVersion, versions.v2CellBlack); case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_GREEN: - return this.status.firmwareVersion >= versions.v2CellGreen; + return this.versionComparison(this.status.firmwareVersion, versions.v2CellGreen); case pond.DevicePlatform.DEVICE_PLATFORM_V2_WIFI_BLUE: - return this.status.firmwareVersion >= versions.v2WifiBlue; + return this.versionComparison(this.status.firmwareVersion, versions.v2WifiBlue); case pond.DevicePlatform.DEVICE_PLATFORM_V2_CELLULAR_BLUE: - return this.status.firmwareVersion >= versions.v2CellBlue; + return this.versionComparison(this.status.firmwareVersion, versions.v2CellBlue); case pond.DevicePlatform.DEVICE_PLATFORM_V2_ETHERNET_BLUE: - return this.status.firmwareVersion >= versions.v2EthBlue; + return this.versionComparison(this.status.firmwareVersion, versions.v2EthBlue); default: return false; } diff --git a/src/pages/Device.tsx b/src/pages/Device.tsx index 7344659..ef9b673 100644 --- a/src/pages/Device.tsx +++ b/src/pages/Device.tsx @@ -169,7 +169,6 @@ export default function DevicePage() { const loadPortScan = () => { deviceAPI.listFoundComponents(parseInt(deviceID)) .then(resp => { - console.log(resp.data) if (resp.data.foundComponents?.i2c || resp.data.foundComponents?.oneWire){ setScannedAddresses(pond.ListFoundComponentsResponse.fromObject(resp.data).foundComponents ?? undefined) }