コード例 #1
0
 private void Pin_PinValueChanged(object sender, GPinEventArgs e)
 {
     Dispatcher.RunAsync(() =>
     {
         var value = pin.Read() == PinValue.High;
         if (value != Value)
         {
             _value = value;
             RaisePropertyChanged(() => Value);
         }
     });
 }
コード例 #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
        private static async Task GetPin(HttpListenerContext context, IPin pin)
        {
            var currentState = pin.Read() == PinValue.High;

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