Пример #1
0
        private async Task ClearPin(HttpListenerContext context, IPin pin)
        {
            bool currentState = false;

            pin.Write(currentState ? PinValue.High : PinValue.Low);

            await RespondPinValue(context, pin.PinNumber, currentState);

            PinChanged?.Invoke(this, new PinEventArgs(context.Request, pin));
        }
Пример #2
0
        private async Task UpdatePin(HttpListenerContext context, IPin pin)
        {
            var request      = context.Request;
            var inputStream  = request.InputStream;
            var currentState = pin.Read() == PinValue.High;

            using (var streamReader = new StreamReader(inputStream))
            {
                var content = await streamReader.ReadToEndAsync();

                var    obj   = JObject.Parse(content);
                JToken token = null;
                if (obj.TryGetValue("state", out token))
                {
                    switch (token.Type)
                    {
                    case JTokenType.Boolean:
                        currentState = token.Value <bool>();
                        break;

                    case JTokenType.String:
                        var str = token.Value <string>();
                        if (str == "toggle")
                        {
                            currentState = !currentState;
                        }
                        break;
                    }
                }
            }

            pin.Write(currentState ? PinValue.High : PinValue.Low);

            await RespondPinValue(context, pin.PinNumber, currentState);

            PinChanged?.Invoke(this, new PinEventArgs(request, pin));
        }
Пример #3
0
 void OnPinChanged(int port, bool value)
 {
     PinChanged?.Invoke(this, new RelayChangedEventArgs(port, value));
 }
Пример #4
0
 private void btnPin_Click(object sender, EventArgs e)
 {
     SetPinned(!Pinned);
     PinChanged?.Invoke(this, EventArgs.Empty);
 }
Пример #5
0
 private Task OnPinChanged(PinChanged value)
 {
     return(MessageBroker.Publish(PinValueChangedEvent.Create(Uid, value.PinNumber, value.IsRising)));
 }