Esempio n. 1
0
 private void ToOff()
 {
     bar.Value = bar.Minimum;
     SetValue(StateProperty, false);
     ToggleStateChanged?.Invoke(this, new EventArgs());
 }
Esempio n. 2
0
 /// <summary>
 /// Invoked when the toggle state changes.
 /// </summary>
 private void ToggleStateChangedInternal(object sender, StateChangedEvent eventData)
 {
     ToggleStateChanged?.Invoke(this, eventData);
 }
Esempio n. 3
0
 private void ToOn()
 {
     bar.Value = bar.Maximum;
     SetValue(StateProperty, true);
     ToggleStateChanged?.Invoke(this, new EventArgs());
 }
Esempio n. 4
0
        public void ProcessMessage(Stream stream)
        {
            var headerPart1 = stream.ReadByte();

            if (headerPart1 != 0xFF)
            {
                _logger.WriteLine($"Expected 0xFF header byte 1, recieved '{headerPart1}'");
                return;
            }
            var headerPart2 = stream.ReadByte();

            if (headerPart1 != 0xFA)
            {
                _logger.WriteLine($"Expected 0xFA header byte 2, recieved '{headerPart1}'");
                return;
            }

            var messageId = stream.ReadByte();

            switch (messageId)
            {
            case MessageIds.MESSAGE_INVALID:
            {
                var data = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_INVALID: data={data}");
                InvalidResponse?.Invoke(this, EventArgs.Empty);
            }
            break;

            case MessageIds.MESSAGE_ACKNOWLEDGED:
            {
                var data = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_ACKNOWLEDGED: data={data}");
                AcknowledgedResponse?.Invoke(this, EventArgs.Empty);
            }
            break;

            case MessageIds.MESSAGE_BUTTON_DOWN:
            {
                var column = stream.ReadByte();
                var row    = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_BUTTON_DOWN: column={column},row={row}");
                ButtonDown?.Invoke(this, new ButtonEventArgs(row, column));
            }
            break;

            case MessageIds.MESSAGE_BUTTON_UP:
            {
                var column = stream.ReadByte();
                var row    = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_BUTTON_UP: column={column},row={row}");
                ButtonUp?.Invoke(this, new ButtonEventArgs(row, column));
            }
            break;

            case MessageIds.MESSAGE_TOGGLE_STATE:
            {
                var index = stream.ReadByte();
                var state = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_TOGGLE_STATE: index={index},state={state}");
                ToggleStateChanged?.Invoke(this, new ToggleStateChangeEventArgs(index, state == 1));
            }
            break;

            case MessageIds.MESSAGE_LED_BRIGHTNESS:
            {
                var brightness = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_LED_BRIGHTNESS: brightness={brightness}");
                LEDBrightness?.Invoke(this, new LEDBrightnessEventArgs(brightness));
            }
            break;

            case MessageIds.MESSAGE_VERSION:
            {
                var version = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_VERSION: version={version}");
                VersionResponse?.Invoke(this, new VersionEventArgs(version));
            }
            break;

            case MessageIds.MESSAGE_HEARTBEAT:
            {
                var value = stream.ReadByte();
                _logger.WriteLine($"MESSAGE_HEARTBEAT: value={value}");
                HeartbeatResponse?.Invoke(this, new HeartbeatEventArgs(value));
            }
            break;

            default:
            {
                _logger.WriteLine($"Unexpected message id '{messageId}'");
                throw new ArgumentOutOfRangeException(nameof(messageId), "Unexpected message id");
            }
            }
        }