예제 #1
0
        public HatDevice(GpioController controller)
        {
            _controller = controller;
            controller.OpenPin(Bl, PinMode.Output);
            _controller.Write(Bl, PinValue.High);

            _oled = new SH1106(controller, Reset, Dc, Cs, SpiClockFrequency);

            _keyPinHelpers = new[]
            {
                new KeyPinHelper(controller, Key1, KeyName.Key1, e => GpioKey1Pressed?.Invoke(this, e),
                                 e => GpioKey1Released?.Invoke(this, e)),
                new KeyPinHelper(controller, Key2, KeyName.Key2, e => GpioKey2Pressed?.Invoke(this, e),
                                 e => GpioKey2Released?.Invoke(this, e)),
                new KeyPinHelper(controller, Key3, KeyName.Key3, e => GpioKey3Pressed?.Invoke(this, e),
                                 e => GpioKey3Released?.Invoke(this, e)),
                new KeyPinHelper(controller, JoystickUp, KeyName.JoystickUp, e => GpioJoystickUpPressed?.Invoke(this, e),
                                 e => GpioJoystickUpReleased?.Invoke(this, e)),
                new KeyPinHelper(controller, JoystickDown, KeyName.JoystickDown, e => GpioJoystickDownPressed?.Invoke(this, e),
                                 e => GpioJoystickDownReleased?.Invoke(this, e)),
                new KeyPinHelper(controller, JoystickLeft, KeyName.JoystickLeft, e => GpioJoystickLeftPressed?.Invoke(this, e),
                                 e => GpioJoystickLeftReleased?.Invoke(this, e)),
                new KeyPinHelper(controller, JoystickRight, KeyName.JoystickRight, e => GpioJoystickRightPressed?.Invoke(this, e),
                                 e => GpioJoystickRightReleased?.Invoke(this, e)),
                new KeyPinHelper(controller, JoystickCenter, KeyName.JoystickCenter, e => GpioJoystickCenterPressed?.Invoke(this, e),
                                 e => GpioJoystickCenterReleased?.Invoke(this, e))
            };

            _ones = new byte[PageSize];
            //Unsafe.InitBlock(ref ones[0], 255, PageSize);
        }
예제 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _oled.Dispose();
                    foreach (var helper in _keyPinHelpers)
                    {
                        helper.Dispose();
                    }
                    _controller.ClosePin(Bl);
                }

                _oled          = null;
                _keyPinHelpers = null;
                _controller    = null;
                _ones          = null;
                _disposedValue = true;
            }
        }