private void UpdateSensors() { foreach (IHardware hardware in comp.Hardware) { if (hardware.HardwareType != HardwareType.CPU) { continue; } hardware.Update(); cpuSensors = hardware.Sensors.ToList <ISensor>(); cpuSensors.RemoveAll(sens => sens.SensorType != SensorType.Temperature); } OnSensorUpdated?.Invoke(this, new EventArgs()); }
public async void NewAcc(Accelerometer sender, AccelerometerReadingChangedEventArgs args) { var reading = args == null?sender?.GetCurrentReading() : args.Reading; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this[ACCELERATOR] = reading == null ? this[ACCELERATOR].New() : this[ACCELERATOR].New(reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ, 0); if (this[ACCELERATOR].IsChanged) { OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); OnSensorUpdated?.Invoke(this[ACCELERATOR]); } }); if (SensorSwitches.A.HasValue && (SensorSwitches.A.Value == 1 || SensorSwitches.A.Value == 3)) { SensorSwitches.A = 0; } }
public async void NewLight(LightSensor sender, LightSensorReadingChangedEventArgs args) { var reading = args == null?sender?.GetCurrentReading() : args.Reading; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this[LIGHTSENSOR] = reading == null ? this[LIGHTSENSOR].New() : this[LIGHTSENSOR].New(reading.IlluminanceInLux, 0, 0, 0); if (this[LIGHTSENSOR].IsChanged) { OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); OnSensorUpdated?.Invoke(this[LIGHTSENSOR]); } }); if (SensorSwitches.P.HasValue && (SensorSwitches.P.Value == 1 || SensorSwitches.P.Value == 3)) { SensorSwitches.P = 0; } }
public async void NewQuan(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args) { var reading = args == null?sender?.GetCurrentReading() : args.Reading; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this[QUANTIZATION] = reading == null ? this[QUANTIZATION].New(0, 0, 0, 0) : this[QUANTIZATION].New(reading.Quaternion.X, reading.Quaternion.Y, reading.Quaternion.Z, reading.Quaternion.W); if (this[QUANTIZATION].IsChanged) { OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); OnSensorUpdated?.Invoke(this[QUANTIZATION]); } }); if (SensorSwitches.Q.HasValue && (SensorSwitches.Q.Value == 1 || SensorSwitches.Q.Value == 3)) { SensorSwitches.Q = 0; } }
public async void NewLoc(Geolocator sender, PositionChangedEventArgs args) { var reading = args == null ? (sender == null ? null : (await sender.GetGeopositionAsync())) : args.Position; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this[LOCATION] = reading == null ? this[LOCATION].New(0, 0, 0, 0) : this[LOCATION].New(reading.Coordinate.Point.Position.Latitude, reading.Coordinate.Point.Position.Longitude, reading.Coordinate.Point.Position.Altitude, 0); if (this[LOCATION].IsChanged) { OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); OnSensorUpdated?.Invoke(this[LOCATION]); } }); if (SensorSwitches.L.HasValue && (SensorSwitches.L.Value == 1 || SensorSwitches.L.Value == 3)) { SensorSwitches.L = 0; } }
public async void NewCom(Compass sender, CompassReadingChangedEventArgs args) { var reading = args == null?sender?.GetCurrentReading() : args.Reading; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this[COMPASS] = reading == null ? this[COMPASS].New(0, 0, 0, 0) : this[COMPASS].New(reading.HeadingMagneticNorth, reading.HeadingTrueNorth ?? 0, 0, 0); if (this[COMPASS].IsChanged) { OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); OnSensorUpdated?.Invoke(this[COMPASS]); } }); if (SensorSwitches.M.HasValue && (SensorSwitches.M.Value == 1 || SensorSwitches.M.Value == 3)) { SensorSwitches.M = 0; } }
public async void NewGyro(Gyrometer sender, GyrometerReadingChangedEventArgs args) { var reading = args == null?sender?.GetCurrentReading() : args.Reading; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this[GYROSCOPE] = reading == null ? this[GYROSCOPE].New(0, 0, 0, 0) : this[GYROSCOPE].New(reading.AngularVelocityX, reading.AngularVelocityY, reading.AngularVelocityZ, 0); if (this[GYROSCOPE].IsChanged) { OnPropertyChanged(new PropertyChangedEventArgs("ItemsList")); OnSensorUpdated?.Invoke(this[GYROSCOPE]); } }); if (SensorSwitches.G.HasValue && (SensorSwitches.G.Value == 1 || SensorSwitches.G.Value == 3)) { SensorSwitches.G = 0; } }
public void UpdateSensorFromMessage(Message mes) { //if internal node message if (mes.sensorId == 255) { return; } if (mes.messageType != MessageType.C_PRESENTATION && mes.messageType != MessageType.C_SET) { return; } Node node = GetNode(mes.nodeId); Sensor sensor = node.GetSensor(mes.sensorId); if (sensor == null) { sensor = node.AddSensor(mes.sensorId); LogInfo($"Node[{sensor.nodeId}] Sensor[{sensor.sensorId}] registered"); db?.AddSensor(sensor); OnNewSensor?.Invoke(sensor); } if (mes.messageType == MessageType.C_SET) { sensor.dataType = (SensorDataType)mes.subType; sensor.state = mes.payload; LogInfo($"Node[{sensor.nodeId}] Sensor[{sensor.sensorId}] datatype: [{sensor.dataType}] state: [{sensor.state}]"); db?.UpdateSensor(sensor); OnSensorUpdated?.Invoke(sensor); } else if (mes.messageType == MessageType.C_PRESENTATION) { try { sensor.type = ((SensorType)mes.subType); sensor.SetDefaultDataType(); } catch { LogError($"Can`t set sensor type for Node[{mes.nodeId}] Sensor[{mes.sensorId}]: [{mes.subType}]"); return; } if (!String.IsNullOrEmpty(mes.payload)) { sensor.description = mes.payload; } LogInfo($"Node[{sensor.nodeId}] Sensor[{sensor.sensorId}] presented type: [{sensor.type}]"); LogInfo($"Node[{sensor.nodeId}] Sensor[{sensor.sensorId}] datatype set to default: [{sensor.dataType}]"); if (!String.IsNullOrEmpty(sensor.description)) { LogInfo($"Node[{sensor.nodeId}] Sensor[{sensor.sensorId}] description: [{sensor.description}]"); } db?.UpdateSensor(sensor); OnSensorUpdated?.Invoke(sensor); } }