public ShadeItemViewModel(FEZHAT.Motor shadeMotor, int operationDuration, string windowName, FEZHAT.RgbLed rgbLed) { this.shadeMotor = shadeMotor; this.operationDuration = operationDuration; this.windowName = windowName; this.rgbLed = rgbLed; operationTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) }; operationTimer.Tick += OperationTimer_Tick; }
private async Task ReceiveCommands() { Debug.WriteLine("\nDevice waiting for commands from IoTHub...\n"); Message receivedMessage; string messageData; while (true) { try { receivedMessage = await _deviceClient.ReceiveAsync(); if (receivedMessage != null) { messageData = Encoding.ASCII.GetString(receivedMessage.GetBytes()); Debug.WriteLine("\t{0}>Recieve message:{1}", DateTime.Now.ToLocalTime(), messageData); tbReceiveStats.Text = "Recieve - " + messageData + " - @" + DateTime.Now; var command = messageData.ToLower(); if (command.StartsWith("fezhat:")) { var units = command.Split(new char[] { ':' }); var unit = units[1].Split(new char[] { ',' }); foreach (var order in unit) { FEZHAT.RgbLed targetLed = null; var frags = order.Split(new char[] { '=' }); switch (frags[0].ToUpper()) { case "D2": targetLed = _fezhat.D2; break; case "D3": targetLed = _fezhat.D3; break; } var orderedColor = FEZHAT.Color.Black; switch (frags[1].ToLower()) { case "black": orderedColor = FEZHAT.Color.Black; break; case "red": orderedColor = FEZHAT.Color.Red; break; case "green": orderedColor = FEZHAT.Color.Green; break; case "yellow": orderedColor = FEZHAT.Color.Yellow; break; case "blue": orderedColor = FEZHAT.Color.Blue; break; case "magenta": orderedColor = FEZHAT.Color.Magneta; break; case "cyan": orderedColor = FEZHAT.Color.Cyan; break; case "white": orderedColor = FEZHAT.Color.White; break; } targetLed.Color = orderedColor; } } await _deviceClient.CompleteAsync(receivedMessage); } } catch (Exception ex) { Debug.WriteLine(ex.Message); IndicateDebug(FEZHAT.Color.Red, 3600); } await Task.Delay(TimeSpan.FromSeconds(10)); } }