private void SetupGpio() { if (_gpio_setup) { return; } ctrl = GpioController.GetDefault(); if (null == ctrl) { throw new DeviceNotFoundException("No GPIO controller on this device"); } /* * If you get exceptions one the next couple of lines, particularly a message that the pin * is already in use, or inaccessible, then please ensure you add the line * <DeviceCapability Name="lowLevel" /> * to the capabilities section of package.appxmanifest in the calling app. */ DatPin = ctrl.OpenPin(DAT); ClockPin = ctrl.OpenPin(CLK); ClockPin.SetDriveMode(GpioPinDriveMode.Output); DatPin.SetDriveMode(GpioPinDriveMode.Output); Show(); _gpio_setup = true; }
private void ReleaseClockLock() { DatPin.Write(GpioPinValue.Low); for (int count = 0; count < 32; count++) { ClockPin.Write(GpioPinValue.High); ClockPin.Write(GpioPinValue.Low); } }
private void write_byte(byte input) { int value; byte modded = Convert.ToByte(input); for (int count = 0; count < 8; count++) { value = modded & 128; DatPin.Write(value == 128 ? GpioPinValue.High : GpioPinValue.Low); ClockPin.Write(GpioPinValue.High); modded = Convert.ToByte((modded << 1) % 256); ClockPin.Write(GpioPinValue.Low); } }