/// <summary> /// Collects sensor data at interval of 1 second. To get data of specific room, do not call this function instead update value to property I2C_Slave_Address and this function will collect data from that slave. /// </summary> public static void CollectData() { if (AlreadyRunning == false) { AlreadyRunning = true; Sensors = new SensorSturct(); Sensors.AmbientLight = new Library.Core.Sensors.AmbientLight(); Sensors.PassiveIR = new Library.Core.Sensors.PassiveIR(); Sensors.Temperature = new Library.Core.Sensors.Temperature(); Task Task_CollectSensorData = new Task(async () => { while (true) { var Response = await Library.Communication.I2C_Helper.WriteRead(I2C_Slave_Address, Library.Communication.I2C_Helper.Mode.Mode0); // Update Ambient Light Sensors.AmbientLight.RawData = (short)Response[0]; //Update PIR State Sensors.PassiveIR.HumanDetected = (((byte)Response[1]) == 1) ? true : false; // Update Temperature Sensors.Temperature.Celsius = (byte)Response[3]; Sensors.Temperature.Celsius *= (((byte)Response[2])==0)?-1:1; // Update Temperature Sign. Refer mode 0 for details. Debug.WriteLine(Sensors.AmbientLight.RawData); Debug.WriteLine(Sensors.PassiveIR.HumanDetected.ToString()); Debug.WriteLine(Sensors.Temperature.Celsius); Debug.WriteLine("======================="); await Task.Delay(1000); } }); Task_CollectSensorData.Start(); Task_CollectSensorData.Wait(); } }
/// <summary> /// Collects sensor data at interval of 1 second. To get data of specific room, do not call this function instead update value to property I2C_Slave_Address and this function will collect data from that slave. /// </summary> public static void CollectData() { if (AlreadyRunning == false) { AlreadyRunning = true; Sensors = new SensorSturct(); Sensors.AmbientLight = new Library.Core.Sensors.AmbientLight(); Sensors.PassiveIR = new Library.Core.Sensors.PassiveIR(); Sensors.Temperature = new Library.Core.Sensors.Temperature(); Task Task_CollectSensorData = new Task(async() => { while (true) { var Response = await Library.Communication.I2C_Helper.WriteRead(I2C_Slave_Address, Library.Communication.I2C_Helper.Mode.Mode0); // Update Ambient Light Sensors.AmbientLight.RawData = (short)Response[0]; //Update PIR State Sensors.PassiveIR.HumanDetected = (((byte)Response[1]) == 1) ? true : false; // Update Temperature Sensors.Temperature.Celsius = (byte)Response[3]; Sensors.Temperature.Celsius *= (((byte)Response[2]) == 0)?-1:1; // Update Temperature Sign. Refer mode 0 for details. Debug.WriteLine(Sensors.AmbientLight.RawData); Debug.WriteLine(Sensors.PassiveIR.HumanDetected.ToString()); Debug.WriteLine(Sensors.Temperature.Celsius); Debug.WriteLine("======================="); await Task.Delay(1000); } }); Task_CollectSensorData.Start(); Task_CollectSensorData.Wait(); } }