Пример #1
0
        protected virtual void OnStateChanged(BulbStateEnum oldState, BulbStateEnum newState)
        {
            //start the usage stopwatch to report the stats for predictive maintenance
            //Starting when we are going from off to on
            if (oldState != BulbStateEnum.On && oldState != BulbStateEnum.AssumedOn &&
                (newState == BulbStateEnum.On || newState == BulbStateEnum.AssumedOn))
            {
                _usageTimer.Start();
            }

            //if we are going from on to off itis time to report the usage cycle
            if (oldState == BulbStateEnum.On || oldState == BulbStateEnum.AssumedOn &&
                _usageTimer.IsRunning)
            {
                _usageTimer.Stop();

                BulbCycled?.Invoke(this, new BulbCycledEventArgs
                {
                    BulbId    = Id,
                    SecondsOn = _usageTimer.Elapsed.TotalSeconds
                });
                _usageTimer.Reset();
            }

            StateChanged?.Invoke(this, new StateChangedEventArgs
            {
                SourceId        = Id,
                OldState        = (int)oldState,
                NewState        = (int)newState,
                SourceTimestamp = DateTime.UtcNow
            });
        }
Пример #2
0
        public override async Task <bool> TransitionToState(BulbStateEnum newState)
        {
            var oldState = await GetState();

            LastStateRequest = newState;

            _gpioPin.Write(newState == BulbStateEnum.On ? GpioPinValue.Low : GpioPinValue.High);

/*
 *
 *          //HACK: Having trouble getting reliable readings from my ACS712 without a steady power supply using 50w bulbs
 *          var areWeMocking = MyCurrentSensor as MockSensor;
 *          areWeMocking?.SetValue(newState == BulbStateEnum.On ? 1 : 0);
 *
 *          var actualState = await GetState();
 */

            if (CurrentState != BulbStateEnum.InOperable)
            {
                CurrentState = newState;
            }
            if (oldState != newState)
            {
                OnStateChanged(oldState, newState);
            }

            return(true);
        }
Пример #3
0
        public override async Task <bool> TransitionToState(BulbStateEnum newState)
        {
            var oldState = await GetState();

            LastStateRequest = newState;

/*            ((MockSensor)MyCurrentSensor).SetValue(newState == BulbStateEnum.On ? 1 : 0);
 *
 *          var actualState = await GetState();*/
            CurrentState = newState;
            if (oldState != newState)
            {
                OnStateChanged(oldState, newState);
            }

            return(true);
        }
Пример #4
0
 public virtual Task <bool> TransitionToState(BulbStateEnum newState)
 {
     throw new NotImplementedException();
 }