public static Sensor GetSensorByHandle(IntPtr handle) { SensorInformation info = new SensorInformation(); _E(_GetSensorInformation(handle, ref info)); if (SensorDictionary.TryGetValue(info.serial_number, out Sensor s)) { return(s); } return(SensorDictionary[info.serial_number] = SensorFactory(ref info)); }
public static void UpdateSensors() { int ns = _GetSensorCount(); var handles = new HashSet <ulong>(SensorDictionary.Keys); SensorInformation info = new SensorInformation(); for (int i = 0; i < ns; i++) { if (_GetSensorInformationByIndex(i, ref info) == SensorErrorCode.SUCCESS) { SensorDictionary.GetOrAdd(info.serial_number, (sn) => SensorFactory(ref info)); handles.Remove(info.serial_number); } } foreach (ulong key in handles) { SensorDictionary.TryRemove(key, out _); } }