Example #1
0
        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
            }
        }
Example #2
0
        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
            //    }
            //}
        }