Exemplo n.º 1
0
        /// <inheritdoc />
        public override IObservable <DeviceState> GetAndObserveState()
        {
            return(Observable
                   .Create <bool>(observer =>
            {
                Controller.RegisterCallbackForPinValueChangedEvent(PinNumber, PinEventTypes.Rising | PinEventTypes.Falling, OnPinChanged);
                observer.OnNext((bool)Controller.Read(PinNumber));

                return Disposable.Create(() => Controller.UnregisterCallbackForPinValueChangedEvent(PinNumber, OnPinChanged));

                void OnPinChanged(object sender, PinValueChangedEventArgs pinValueChangedEventArgs)
                {
                    switch (pinValueChangedEventArgs.ChangeType)
                    {
                    case PinEventTypes.Rising:
                        observer.OnNext(true);
                        break;

                    case PinEventTypes.Falling:
                        observer.OnNext(false);
                        break;

                        // Ignore case None:
                    }
                }
            })
                   .Select(isOn => new DeviceState(PinNumber.ToString(), ImmutableDictionary <string, string> .Empty.SetItem("state", isOn ? "on" : "off"), isPersistedState: true)));
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 public override IObservable <DeviceState> GetAndObserveState()
 => _state
 .DistinctUntilChanged()
 .Select(isOn => new DeviceState(
             PinNumber.ToString(),
             ImmutableDictionary <string, string> .Empty.SetItem("state", isOn ? "on" : "off"),
             isPersistedState: true));
                public string GetBlockCode()
                {
                    string trueval;

                    if (TrueState == StateType.HIGH)
                    {
                        trueval = "HIGH";
                    }
                    else
                    {
                        trueval = "LOW";
                    }
                    string codetemplate = File.ReadAllText("sensor.inf");
                    string code         = codetemplate;

                    code = code.Replace("@description", Description);
                    code = code.Replace("@name", Name);
                    code = code.Replace("@trueval", trueval);
                    code = code.Replace("@pinNumber", PinNumber.ToString());
                    return(code);
                }
Exemplo n.º 4
0
 private string getPin()
 {
     return(PinNumber.ToString().Length == 4 ? "****" : "This user has yet to set up a PIN numner");
 }