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)); }
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)); }
void OnPinChanged(int port, bool value) { PinChanged?.Invoke(this, new RelayChangedEventArgs(port, value)); }
private void btnPin_Click(object sender, EventArgs e) { SetPinned(!Pinned); PinChanged?.Invoke(this, EventArgs.Empty); }
private Task OnPinChanged(PinChanged value) { return(MessageBroker.Publish(PinValueChangedEvent.Create(Uid, value.PinNumber, value.IsRising))); }