public DebounceViewModel(KeypadSerial keypad)
 {
     Debounce                   = new DebounceModel(keypad);
     writeValuesTimer           = new Timer(500);
     writeValuesTimer.Elapsed  += WriteValuesTimerElapsed;
     writeValuesTimer.AutoReset = false;
     writeValuesTimer.Enabled   = false;
 }
 public CountersViewModel(KeypadSerial keypad)
 {
     Counters = new CountersModel(keypad);
     // Create a timer with a second interval
     ReadTimer = new Timer(1000);
     // Hook up the Elapsed event for the timer.
     ReadTimer.Elapsed  += ReadCounters;
     ReadTimer.AutoReset = true;
     ReadTimer.Enabled   = true;
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("Attempting to connect to keypad...");
                    using (keypad = new KeypadSerial())
                    {
                        try
                        {
                            keypad.Open();
                            keypad.KeyChanged += (object sender, KeypadActionEventArgs e) =>
                            {
                                Console.WriteLine(e.KeyChanged);
                            };
                            Console.WriteLine("Press keypad keys to test key events.");
                            Console.WriteLine("Enter a byte value to test keypad LEDs.");
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            // port already opened by someone else
                        }
                        catch (System.IO.IOException ex)
                        {
                            // port not connected
                        }
                        catch (Exception ex)
                        {
                            // unknown
                            throw ex;
                        }

                        int parsedInt;
                        while (true)
                        {
                            string userInput = Console.ReadLine();
                            if (int.TryParse(userInput, out parsedInt))
                            {
                                if (parsedInt < 256)
                                {
                                    keypad.SendByte((byte)parsedInt);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Caught exception: {e.GetType()} : {e.Message}");
                    Console.WriteLine("Retrying connection in 5 seconds...");
                    Thread.Sleep(5000);
                }
            }
        }
Beispiel #4
0
 public TopViewModel()
 {
     Keypad                 = new KeypadSerial();
     CurrentPage            = Page.Keybinds;
     keybindsVm             = new KeybindsViewModel(Keypad);
     countersVm             = new CountersViewModel(Keypad);
     debounceVm             = new DebounceViewModel(Keypad);
     lightingVm             = new LightingViewModel(Keypad);
     debugVm                = new DebugViewModel(Keypad);
     TopView.DeviceChanged += CheckConnection;
 }
        public DebugViewModel(KeypadSerial _keypad)
        {
            writeTimer    = new Timer(WriteBaseColourAll);
            WriteInterval = 1;
            keypad        = _keypad;

            Leds = new ObservableCollection <SelectableItem>()
            {
                new SelectableItem("LED 0"),
                new SelectableItem("LED 1"),
                new SelectableItem("LED 2"),
                new SelectableItem("LED 3"),
                new SelectableItem("LED 4"),
                new SelectableItem("LED 5"),
                new SelectableItem("LED 6"),
                new SelectableItem("LED 7"),
                new SelectableItem("LED 8"),
                new SelectableItem("LED 9"),
                new SelectableItem("LED 10"),
                new SelectableItem("LED 11")
            };
            EepromContents = new ObservableCollection <EepromByte>();
        }
 public KeybindsViewModel(KeypadSerial _keypad)
 {
     Keybinds = new KeybindsModel(_keypad);
 }
Beispiel #7
0
 public KeybindsModel(KeypadSerial _keypad)
 {
     keypad = _keypad;
 }
 public CountersModel(KeypadSerial _keypad)
 {
     keypad = _keypad;
 }
 public LightingViewModel(KeypadSerial _keypad)
 {
     keypad = _keypad;
 }