public RoomWashManager2ProxSensors(ILedControl ledControl, IParamConfig paramConfig) { _ledControl = ledControl; _paramConfig = paramConfig; _ledControl.Connect(); _ledControl.TurnOn(); _ledControl.ChangeColor(69, 69, 69); Thresholds thresholds = _paramConfig.ReadThresholds(); ManagerSensors.Add(ESensorType.PressureSensor, new SensorStatus(thresholds.PsLow, thresholds.PsHigh)); ManagerSensors.Add(ESensorType.DistanceMeter1, new SensorStatus(thresholds.Dm1Low, thresholds.Dm1High)); ManagerSensors.Add(ESensorType.DistanceMeter2, new SensorStatus(thresholds.Dm2Low, thresholds.Dm2High)); ManagerSensors.Add(ESensorType.EmployeeCardReader, new SensorStatus(0, 0)); _lastExitTime = lastEntryTime = lastWashTime = DateTime.Now; // init time references }
public void NewSensorDataReceived(ESensorType sensorType, int sensorValue) { switch (sensorType) { case ESensorType.DistanceMeter1: if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.DistanceMeter1].GetSensorTransition(sensorValue)) { if (!inRoom) { if ((DateTime.Now - _lastExitTime).Milliseconds < 500) { break; // filter noise } inRoom = true; if (null == _activeManInTheRoom) { _activeManInTheRoom = new ManInTheRoom(); } lastEntryTime = ManagerSensors[ESensorType.DistanceMeter1].ChangeTime; _ledControl.ChangeColor(255, 255, 0); // yellow } else { inRoom = false; if (null != _activeManInTheRoom) { _activeManInTheRoom.ExitTime = DateTime.Now; // write to DB _activeManInTheRoom = null; // _lastExitTime = DateTime.Now; // to filter noise } } } break; case ESensorType.EmployeeCardReader: isEmployee = true; if (null == _activeManInTheRoom) { _activeManInTheRoom = new ManInTheRoom(); } _activeManInTheRoom.Id = sensorValue; _activeManInTheRoom.IsEmployee = true; //EmployeeNumber = sensorValue; if (Math.Abs((lastWashTime - lastEntryTime).Milliseconds) < 15000) { hansWaskedOK = true; _ledControl.ChangeColor(0, 0, 255); // green } else { _ledControl.ChangeColor(0, 0, 255); // blue } break; case ESensorType.PressureSensor: if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.PressureSensor].GetSensorTransition(sensorValue)) { lastWashTime = ManagerSensors[ESensorType.PressureSensor].ChangeTime; //if ((lastWashTime - lastEntryTime).Milliseconds < 15000) // less than 15 sec from entry to wash - OK!!! if (inRoom) { if (null != _activeManInTheRoom) { _activeManInTheRoom.Sanitized = true; _activeManInTheRoom.SanitizeTime = lastWashTime; } hansWaskedOK = true; _ledControl.ChangeColor(0, 0, 255); // green } } break; case ESensorType.DistanceMeter2: if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.DistanceMeter2].GetSensorTransition(sensorValue)) { if (inRoom) { if ((DateTime.Now - lastEntryTime).Milliseconds < 1000) { break; // filter noise } _ledControl.ChangeColor(255, 255, 0); // yellow } } break; default: break; } // periodic checks if (inRoom) { if ((!warningOn) && (!hansWaskedOK)) { if ((DateTime.Now - lastEntryTime).Milliseconds > 15000) { warningOn = true; // turn on yellow light } } } if ((DateTime.Now - lastEntryTime).Milliseconds > 60000) { hansWaskedOK = false; warningOn = false; // turn off light after 2 minutes } }
public void NewSensorDataReceived(ESensorType sensorType, int sensorValue) { switch (sensorType) { case ESensorType.DistanceMeter1: if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.DistanceMeter1].GetSensorTransition(sensorValue)) { if (!inRoom) { // if ((DateTime.Now - _lastExitTime).Milliseconds < 500) // break; inRoom = true; if (_activeManInTheRoom == null) { _activeManInTheRoom = new ManInTheRoom(); } lastEntryTime = ManagerSensors[ESensorType.DistanceMeter1].ChangeTime; _ledControl.ChangeColor(255, 255, 0); } else { inRoom = false; if (null != _activeManInTheRoom) { _activeManInTheRoom.ExitTime = DateTime.Now; _logService.SerializeObjectAndSendToDb(_activeManInTheRoom); // write to DB _activeManInTheRoom = null; // _lastExitTime = DateTime.Now; // to filter noise } } } break; case ESensorType.EmployeeCardReader: isEmployee = true; if (null == _activeManInTheRoom) { _activeManInTheRoom = new ManInTheRoom(); } _activeManInTheRoom.Id = sensorValue; _activeManInTheRoom.IsEmployee = true; EmployeeNumber = sensorValue; if ((lastWashTime - lastEntryTime).Milliseconds < 15000) { hansWaskedOK = true; _ledControl.ChangeColor(0, 0, 255); } else { _ledControl.ChangeColor(0, 0, 255); } break; case ESensorType.PressureSensor: if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.PressureSensor].GetSensorTransition(sensorValue)) { lastWashTime = ManagerSensors[ESensorType.PressureSensor].ChangeTime; // if ((lastWashTime - lastEntryTime).Milliseconds < 15000) // less than 15 sec from entry to wash - OK!!! //if (inRoom) //{ if (null != _activeManInTheRoom) { _activeManInTheRoom.Sanitized = true; _activeManInTheRoom.SanitizeTime = lastWashTime; _logService.SerializeObjectAndSendToDb(_activeManInTheRoom); } hansWaskedOK = true; _ledControl.ChangeColor(0, 255, 0); // green //} //else //{ // hansWaskedOK = false; //} } break; default: break; } // var l = ((DateTime.Now - lastEntryTime)).Seconds; //if ((DateTime.Now - lastEntryTime).Seconds > 20) //{ // hansWaskedOK = false; // warningOn = false; // _ledControl.TurnToIdle(); // if (null != _activeManInTheRoom) // { // _activeManInTheRoom.ExitTime = DateTime.Now; // _logService.SerializeObjectAndSendToDb(_activeManInTheRoom); //write to DB // _activeManInTheRoom = null; // // _lastExitTime = DateTime.Now; // to filter noise // turn off light after 2 minutes // } //} }