Ejemplo n.º 1
0
        public KeyboardSettings GetKeyboardSettings()
        {
            KeyboardSettings settings = null;

            try
            {
                var sendBuffer = new byte[2];
                sendBuffer[0] = SerialStartByte;
                sendBuffer[1] = GetSettingsCommand;

                var numBytes = SendCommand(sendBuffer, out byte[] replyBuffer);

                if (numBytes > 0)
                {
                    if (replyBuffer[0] == SerialStartByte && replyBuffer[1] == GetSettingsCommand)
                    {
                        settings = new KeyboardSettings
                        {
                            NumButtons  = replyBuffer[2],
                            NumEncoders = replyBuffer[3],
                            MaxNumKeystrokesPerButton = replyBuffer[4]
                        };
                    }
                }
            }
            catch (Exception)
            {
            }

            return(settings);
        }
Ejemplo n.º 2
0
        public string ReadKeyboard()
        {
            if (Comms.FindKeyboardPort())
            {
                Buttons          = new List <Button>();
                KeyboardSettings = Comms.GetKeyboardSettings();
                if (KeyboardSettings != null)
                {
                    for (byte buttonIndex = 0; buttonIndex < KeyboardSettings.NumButtons; buttonIndex++)
                    {
                        var key = Comms.ReadButton(buttonIndex, KeyboardSettings.MaxNumKeystrokesPerButton);
                        if (key != null)
                        {
                            Buttons.Add(key);
                        }
                        else
                        {
                            return("Failed to read a button. Comms Problem?");
                        }
                    }
                    for (byte encoderIndex = 0; encoderIndex < KeyboardSettings.NumEncoders; encoderIndex++)
                    {
                        var encoderControls = Comms.ReadEncoder(encoderIndex, KeyboardSettings.MaxNumKeystrokesPerButton);
                        if (encoderControls.Length == 3)
                        {
                            Buttons.AddRange(encoderControls);
                        }
                        else
                        {
                            return("Failed to read an encoder. Comms Problem?");
                        }
                    }
                }
                else
                {
                    return("Failed to read keyboard settings. Comms Problem?");
                }
            }
            else
            {
                return("Can't find keyboard");
            }

            return("Ready...");
        }