implemented a way of filtering positions using the subtype

The lidar uses a different I2C address for each of the subtypes so this allows us to be able to control the options for a user for each of the subtypes so that one lidars  address cant be used for another
This commit is contained in:
csawatzky 2025-10-07 12:39:32 -06:00
parent ceaff4da9e
commit 50b33e587d
5 changed files with 54 additions and 11 deletions

View file

@ -164,6 +164,10 @@ export interface ComponentTypeExtension {
filters?: GraphFilters
) => LineChartData;
secondaryComponentSettings?: () => pond.ComponentSettings[]
//(only for I2C) possibly add an optional map here that has a number (subtype) as the key and the addresses available for that subtype
//if the map does not exist then just use the array from the device availability,
//if the map does exist filter the availability after claims to find matching address between them and use that
subtypeI2CMap?: Map<number, number[]>
}
export interface Summary {
@ -1090,3 +1094,31 @@ export const GetNumNodesFromUnitMeasurement = (unitMeasurement: UnitMeasurement)
}
return nodes;
};
export const FilterSubtypeI2C = (
componentType: quack.ComponentType,
subtype: number,
positions: number[]
) => {
console.log("Filter I2C")
console.log(positions)
let filtered: number[] = []
//create an extension using the type and subtype
let ext = extension(componentType, subtype)
//if the extension has a subtype map
if (ext.subtypeI2CMap !== undefined){
//check if any of the position passed in match to the map values according to the subtype
let subtypePositions = ext.subtypeI2CMap.get(subtype)
if(subtypePositions !== undefined){
positions.forEach(position => {
if(subtypePositions.includes(position)){
filtered.push(position)
}
})
}
}else{
filtered = positions
}
//return any matches between the arrays
return filtered
}

View file

@ -95,6 +95,11 @@ export function Lidar(subtype: number = 0): ComponentTypeExtension {
minMeasurementPeriodMs: 1000,
icon: (theme?: "light" | "dark"): string | undefined => {
return theme === "light" ? LidarSensorDarkIcon : LidarSensorLightIcon;
}
},
subtypeI2CMap: new Map<number, number[]>([
[quack.LidarSubtype.LIDAR_SUBTYPE_NONE, [0x62]],
[quack.LidarSubtype.LIDAR_SUBTYPE_LONG_DISTANCE, [0x66]],
[quack.LidarSubtype.LIDAR_SUBTYPE_BENEWAKE_TF02W_MID_RANGE, [0x10]],
])
};
}

View file

@ -5,6 +5,7 @@ import { GetProductAvailability } from "products/DeviceProduct";
import { pond } from "protobuf-ts/pond";
import { quack } from "protobuf-ts/quack";
import { or } from "utils/types";
import { FilterSubtypeI2C } from "./ComponentType";
export type ComponentAvailabilityMap = Map<quack.ComponentType, number[]>;
export type DevicePositions = number[] | ComponentAvailabilityMap | ConfigurablePin[];
@ -47,16 +48,17 @@ const DefaultAvailability: DeviceAvailabilityMap = new Map<quack.AddressType, De
[quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY, DefaultPinArray],
[
quack.AddressType.ADDRESS_TYPE_I2C,
//this will contain all the possible addresses for a component type, if subtypes use specific addresses add a filter to the type describer, see lidar.ts for an example
new Map<quack.ComponentType, number[]>([
[quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18, 0x19, 0x1a]],
[quack.ComponentType.COMPONENT_TYPE_LIGHT, [0x29]],
[quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]],
[quack.ComponentType.COMPONENT_TYPE_STEPPER_MOTOR, [0x14, 0x15, 0x16, 0x17]],
[quack.ComponentType.COMPONENT_TYPE_PH, [0x40]],
[quack.ComponentType.COMPONENT_TYPE_DHT, [0x40, 0x61]], //TODO temp fix, needs to be fixed to use channels similar to PH
[quack.ComponentType.COMPONENT_TYPE_DHT, [0x40, 0x61]],
// [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated?
[quack.ComponentType.COMPONENT_TYPE_AIR_QUALITY, [0x58]],
[quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]],
[quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62, 0x66, 0x10]],
[quack.ComponentType.COMPONENT_TYPE_CAPACITANCE, [0x50]],
[quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE, [0x50]],
[quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]],