public Controller(Func<string, int> callback) { _callback = callback; _timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(5000)); _gpio_controller = GpioController.GetDefault(); // Create the Area(s) _areas = new List<Area>() { new Area( "Area 1", new List<Zone>() { new Zone("Zone 1", _gpio_controller.OpenPin(ZONE_1)) }, new Flow("Flow 1", _gpio_controller.OpenPin(FLOW_1)), new OverCurrent("OC 1", _gpio_controller.OpenPin(OC_1)), callback )}; /* _areas = new List<Area>() { new Area( "Area 1", new List<Zone>() { new Zone("Zone 1", _gpio_controller.OpenPin(ZONE_1)), new Zone("Zone 2", _gpio_controller.OpenPin(ZONE_2)), new Zone("Zone 3", _gpio_controller.OpenPin(ZONE_3)) }, new Flow("Flow 1", _gpio_controller.OpenPin(FLOW_1)), new OverCurrent("OC 1", _gpio_controller.OpenPin(OC_1)), callback ), new Area( "Area 2", new List<Zone>() { new Zone("Zone 4", _gpio_controller.OpenPin(ZONE_4)), new Zone("Zone 5", _gpio_controller.OpenPin(ZONE_5)) }, new Flow("Flow 2", _gpio_controller.OpenPin(FLOW_1)), new OverCurrent("OC 2", _gpio_controller.OpenPin(OC_1)), callback ) }; */ }
private void InitializeGpio() { _gpio = GpioController.GetDefault(); _ledPin = _gpio.OpenPin(Gpio5); _ledPin.SetDriveMode(GpioPinDriveMode.Output); _buttonPin = _gpio.OpenPin(Gpio6); _buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp); _buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50); _buttonPin.ValueChanged += buttonPin_ValueChanged; }
public HVAC() { controller = GpioController.GetDefault(); fan = controller.OpenPin(FAN_PIN); heat = controller.OpenPin(HEAT_PIN); cool = controller.OpenPin(COOL_PIN); fan.SetDriveMode(GpioPinDriveMode.OutputOpenDrainPullUp); heat.SetDriveMode(GpioPinDriveMode.OutputOpenDrainPullUp); cool.SetDriveMode(GpioPinDriveMode.OutputOpenDrainPullUp); }
private void InitGPIO() { gpio = GpioController.GetDefault(); if (gpio == null) return; redpin = gpio.OpenPin(0); // GPIO #0 yellowpin = gpio.OpenPin(5); // GPIO #5 greenpin = gpio.OpenPin(6); // GPIO #6 }
private void InitGpio() { gpio = GpioController.GetDefault(); coffeeMakerRelay = gpio.OpenPin(COFFEE_MAKER_RELAY_PIN); coffeeMakerRelay.Write(GpioPinValue.Low); coffeeMakerRelay.SetDriveMode(GpioPinDriveMode.Output); coffeeMakerLED = gpio.OpenPin(COFFEE_MAKER_LED_PIN); coffeeMakerLED.Write(GpioPinValue.Low); coffeeMakerLED.SetDriveMode(GpioPinDriveMode.Output); }
/// <summary> /// Attempts to initialize Gpio for application. This includes doorbell interaction and locking/unlccking of door. /// Returns true if initialization is successful and Gpio can be utilized. Returns false otherwise. /// </summary> public bool Initialize() { // Gets the GpioController gpioController = GpioController.GetDefault(); if(gpioController == null) { // There is no Gpio Controller on this device, return false. return false; } // Opens the GPIO pin that interacts with the doorbel button doorbellPin = gpioController.OpenPin(GpioConstants.ButtonPinID); if (doorbellPin == null) { // Pin wasn't opened properly, return false return false; } // Set a debounce timeout to filter out switch bounce noise from a button press doorbellPin.DebounceTimeout = TimeSpan.FromMilliseconds(25); if (doorbellPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)) { // Take advantage of built in pull-up resistors of Raspberry Pi 2 and DragonBoard 410c doorbellPin.SetDriveMode(GpioPinDriveMode.InputPullUp); } else { // MBM does not support PullUp as it does not have built in pull-up resistors doorbellPin.SetDriveMode(GpioPinDriveMode.Input); } // Opens the GPIO pin that interacts with the door lock system doorLockPin = gpioController.OpenPin(GpioConstants.DoorLockPinID); if(doorLockPin == null) { // Pin wasn't opened properly, return false return false; } // Sets doorbell pin drive mode to output as pin will be used to output information to lock doorLockPin.SetDriveMode(GpioPinDriveMode.Output); // Initializes pin to high voltage. This locks the door. doorLockPin.Write(GpioPinValue.High); //Initialization was successfull, return true return true; }
public async Task Initialize() { Debug.WriteLine("TCS34725::Initialize"); try { var settings = new I2cConnectionSettings(TCS34725_Address); settings.BusSpeed = I2cBusSpeed.FastMode; string aqs = I2cDevice.GetDeviceSelector(I2CControllerName); var dis = await DeviceInformation.FindAllAsync(aqs); colorSensor = await I2cDevice.FromIdAsync(dis[0].Id, settings); // Now setup the LedControlPin gpio = GpioController.GetDefault(); LedControlGPIOPin = gpio.OpenPin(LedControlPin); LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output); } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace); throw; } }
private void InitGPIO() { _gpio = GpioController.GetDefault(); var inGpioPin = _gpio.OpenPin(27); inGpioPin.ValueChanged += ConversionReady; }
private async void initialize() { controller = GpioController.GetDefault(); resetLights(); //IoTHub connection var key = AuthenticationMethodFactory.CreateAuthenticationWithRegistrySymmetricKey(Config.Default.DeviceName, Config.Default.DeviceKey); deviceClient = DeviceClient.Create(Config.Default.IotHubUri, key, TransportType.Http1); //RGB LED PWM controller if (ApiInformation.IsApiContractPresent("Windows.Devices.DevicesLowLevelContract", 1)) { try { //check if the GPIO exists if (controller != null) { var provider = PwmProviderSoftware.GetPwmProvider(); if (provider != null) { var controllers = (await PwmController.GetControllersAsync(provider)); if (controllers != null) { var controller = controllers.FirstOrDefault(); if (controller != null) { controller.SetDesiredFrequency(100); var pinR = controller.OpenPin(ledPinNumberR); var pinG = controller.OpenPin(ledPinNumberG); var pinB = controller.OpenPin(ledPinNumberB); rgbLed = new RgbLed(pinR, pinG, pinB); rgbLed.On(); rgbLed.Color = Colors.White; Task.Delay(50).Wait(); rgbLed.Color = Colors.Black; } } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } await receiveCommands(deviceClient); }
public MainPage() { this.InitializeComponent(); gpio = GpioController.GetDefault(); pin4 = gpio.OpenPin(4); pin4.SetDriveMode(GpioPinDriveMode.Output); }
internal async Task Initialize(byte frequency, byte nodeId, byte networkId) { var settings = new SpiConnectionSettings(0); settings.ClockFrequency = 5000000; /* 5MHz is the rated speed of the ADXL345 accelerometer */ settings.Mode = SpiMode.Mode3; string aqs = SpiDevice.GetDeviceSelector(); /* Get a selector string that will return all SPI controllers on the system */ var dis = await DeviceInformation.FindAllAsync(aqs); /* Find the SPI bus controller devices with our selector string */ _spiDevice = await SpiDevice.FromIdAsync(dis[0].Id, settings); /* Create an SpiDevice with our bus controller and SPI settings */ _spiDevice.ConnectionSettings.Mode = SpiMode.Mode0; _spiDevice.ConnectionSettings.ClockFrequency = 5000; _gpioController = GpioController.GetDefault(); _selectpin = _gpioController.OpenPin(22); _selectpin.SetDriveMode(GpioPinDriveMode.Output); byte[][] config = { new byte[] { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY }, new byte[] { REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00 }, new byte[] { REG_BITRATEMSB, RF_BITRATEMSB_55555}, new byte[] { REG_BITRATELSB, RF_BITRATELSB_55555}, new byte[] { REG_FDEVMSB, RF_FDEVMSB_50000}, new byte[] { REG_FDEVLSB, RF_FDEVLSB_50000}, new byte[] { REG_FRFMSB, RF_FRFMSB_915 }, /* 0x08 */ new byte[] { REG_FRFMID, RF_FRFMID_915 }, /* 0x09 */ new byte[] { REG_FRFLSB, RF_FRFLSB_915 }, new byte[] { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, new byte[] { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, new byte[] { REG_DIOMAPPING2, RF_DIOMAPPING2_CLKOUT_OFF }, new byte[]{ REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN }, new byte[]{ REG_RSSITHRESH, 220 }, new byte[] { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0 }, new byte[]{ REG_SYNCVALUE1, 0x2D }, // attempt to make this compatible with sync1 byte of RFM12B lib /* 0x30 */ new byte[]{ REG_SYNCVALUE2, networkId }, // NETWORK ID /* 0x37 */ new byte[]{ REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF }, /* 0x38 */ new byte[]{ REG_PAYLOADLENGTH, 66 }, // in variable length mode: the max frame size, not used in TX //* 0x39 */ { REG_NODEADRS, nodeID }, // turned off because we're not using address filtering /* 0x3C */ new byte[]{ REG_FIFOTHRESH, RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY | RF_FIFOTHRESH_VALUE }, // TX on FIFO not empty /* 0x3D */ new byte[]{ REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) //for BR-19200: /* 0x3D */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_NONE | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) /* 0x6F */ new byte[]{ REG_TESTDAGC, RF_DAGC_IMPROVED_LOWBETA0 }, // run DAGC continuously in RX mode for Fading Margin Improvement, recommended default for AfcLowBetaOn=0 }; foreach (var configValue in config) { _spiDevice.Write(configValue); } SetHighPower(); }
private void initializeGPIO() { // Initialize GPIO controller gpio = GpioController.GetDefault(); // // Initialize GPIO Pins redPin = gpio.OpenPin(RED_LED_PIN); greenPin = gpio.OpenPin(GREEN_LED_PIN); bedroomLightPin = gpio.OpenPin(BEDROOM_LIGHT_PIN); redPin.SetDriveMode(GpioPinDriveMode.Output); greenPin.SetDriveMode(GpioPinDriveMode.Output); bedroomLightPin.SetDriveMode(GpioPinDriveMode.Output); // Write low initially, this step is not needed redPin.Write(GpioPinValue.Low); greenPin.Write(GpioPinValue.Low); bedroomLightPin.Write(GpioPinValue.Low); }
public MainPage() { this.InitializeComponent(); _eventHubIngest = new EventHubIngest(); _gpioController = GpioController.GetDefault(); if (_gpioController == null) return; _gpioSuccessPin = _gpioController.OpenPin(_ledSuccessPin); _gpioSuccessPin.SetDriveMode(GpioPinDriveMode.Output); _gpioSuccessPin.Write(GpioPinValue.Low); _gpioErrorPin = _gpioController.OpenPin(_ledErrorPin); _gpioErrorPin.SetDriveMode(GpioPinDriveMode.Output); _gpioErrorPin.Write(GpioPinValue.Low); _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(1000); _dispatcherTimer.Tick += (sender, e) => { _gpioSuccessPin.Write(GpioPinValue.High); _gpioErrorPin.Write(GpioPinValue.High); bool ingestTask = _eventHubIngest.TelemetryIngest(new Telemetry() { DeviceId = "Device-78", Humidity = 10, //Read from Sensors Pollution = 100, //Read from Sensors Temperature = 35, //Read from Sensors }); //Check if pins are available if (_gpioController == null || _gpioSuccessPin == null) return; _gpioSuccessPin.Write(ingestTask ? GpioPinValue.Low : GpioPinValue.High); _gpioErrorPin.Write(ingestTask ? GpioPinValue.High : GpioPinValue.Low); }; _dispatcherTimer.Start(); }
public GpioController() { _gpio = Windows.Devices.Gpio.GpioController.GetDefault(); _pins = new Dictionary <byte, GpioPin>(); byte[] pins = { 4, 17, 27, 22, 5, 6, 13, 19, 26, 21, 20, 16, 12, 25, 24, 23, 18 }; for (byte i = 0; i < pins.Length; i++) { _pins.Add(pins[i], _gpio.OpenPin(pins[i], GpioSharingMode.Exclusive)); } }
public MainPage() { this.InitializeComponent(); chamado = false; observer = false; gpio = GpioController.GetDefault(); pin6 = gpio.OpenPin(6); pin6.SetDriveMode(GpioPinDriveMode.Output); pin5 = gpio.OpenPin(5); pin5.SetDriveMode(GpioPinDriveMode.Input); makeConnection(); pin6.Write(GpioPinValue.Low); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(10); timer.Tick += Timer_Tick; timer.Start(); }
public MainPage() { this.InitializeComponent(); this.gpio = GpioController.GetDefault(); this.pin = gpio.OpenPin(CO_PIN); this.pin.SetDriveMode(GpioPinDriveMode.InputPullDown); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(500); timer.Tick += Timer_Tick; timer.Start(); }
private void InitializeGpio() { _gpio = GpioController.GetDefault(); _ledPins = new GpioPin[8]; for (int i = 0; i < 8; i++) { _ledPins[i] = _gpio.OpenPin(_gpios[i]); _ledPins[i].SetDriveMode(GpioPinDriveMode.Output); _ledPins[i].Write(GpioPinValue.High); } }
public void InitalizeLed() { Debug.WriteLine("InternetLed::InitalizeLed"); // Now setup the LedControlPin gpio = GpioController.GetDefault(); LedControlGPIOPin = gpio.OpenPin(LedControlPin); LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output); // Get the current pin value GpioPinValue startingValue = LedControlGPIOPin.Read(); _LedState = (startingValue == GpioPinValue.Low) ? eLedState.On : eLedState.Off; }
private void button2_Click(object sender, RoutedEventArgs e) { _GpioController = GpioController.GetDefault(); _resetEvent = new ManualResetEvent(false); if (this._GpioController != null) { using (GpioPin data = _GpioController.OpenPin(17)) using (GpioPin clock = _GpioController.OpenPin(27)) using (GpioPin strobe = _GpioController.OpenPin(22)) { data.SetDriveMode(GpioPinDriveMode.Output); clock.SetDriveMode(GpioPinDriveMode.Output); strobe.SetDriveMode(GpioPinDriveMode.Output); var display = new TM1638(data, clock, strobe, true, 1); display.setLED(TM1638.TM1638_LED_COLOR.GREEN, 0); display.setLED(TM1638.TM1638_LED_COLOR.RED, 1); display.setLED(TM1638.TM1638_LED_COLOR.ORANGE, 2); } } }
private void InitGpio() { gpioAvailable = false; gpio = GpioController.GetDefault(); if (gpio != null) { pin = gpio.OpenPin(5); if (pin != null) { pin.Write(GpioPinValue.Low); pin.SetDriveMode(GpioPinDriveMode.Output); gpioAvailable = true; } } }
public async void InitHardware() { try { ioController = GpioController.GetDefault(); interruptPin = ioController.OpenPin(InterruptPin); interruptPin.Write(GpioPinValue.Low); interruptPin.SetDriveMode(GpioPinDriveMode.Input); interruptPin.ValueChanged += Interrupt; var collection = await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector()); var settings = new I2cConnectionSettings(Constants.Address) { BusSpeed = I2cBusSpeed.FastMode, SharingMode = I2cSharingMode.Exclusive }; device = await I2cDevice.FromIdAsync(collection[0].Id, settings); await Task.Delay(3); // wait power up sequence readWriteHelper.WriteByte(Constants.PwrMgmt1, 0x80); // reset the device await Task.Delay(100); readWriteHelper.WriteByte(Constants.PwrMgmt1, 0x2); readWriteHelper.WriteByte(Constants.UserCtrl, 0x04); //reset fifo readWriteHelper.WriteByte(Constants.PwrMgmt1, 1); // clock source = gyro x readWriteHelper.WriteByte(Constants.GyroConfig, 0); // +/- 250 degrees sec readWriteHelper.WriteByte(Constants.AccelConfig, 0); // +/- 2g readWriteHelper.WriteByte(Constants.Config, 1); // 184 Hz, 2ms delay readWriteHelper.WriteByte(Constants.SmplrtDiv, 19); // set rate 50Hz readWriteHelper.WriteByte(Constants.FifoEn, 0x78); // enable accel and gyro to read into fifo readWriteHelper.WriteByte(Constants.UserCtrl, 0x40); // reset and enable fifo readWriteHelper.WriteByte(Constants.IntEnable, 0x1); } catch (Exception ex) { Debug.WriteLine(ex); } }
private async Task<bool> InitHardwarePrivate() { try { IoController = GpioController.GetDefault(); InterruptPin = IoController.OpenPin(INTERRUPT_PIN); InterruptPin.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 50); InterruptPin.Write(GpioPinValue.High); InterruptPin.SetDriveMode(GpioPinDriveMode.Input); InterruptPin.ValueChanged += Interrupt; var settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE); settings.ClockFrequency = 10000000; // max frequency for MCSP23S17 is 10Mhz settings.Mode = SpiMode.Mode3; // data read on the rising edge - idle high string spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME); DeviceInformationCollection devices_info = await DeviceInformation.FindAllAsync(spiAqs); await Task.Delay(20); SpiDev = await SpiDevice.FromIdAsync(devices_info[0].Id, settings); Write(IOCONA, 0x28); // BANK=0, SEQOP=1, HAEN=1 (Enable Addressing) interrupt not configured Write(IODIRA, 0x00); // GPIOA As Output Write(IODIRB, 0xFF); // GPIOB As Input Write(GPPUB, 0xFF); // configure pull ups Write(DEFVALB, 0x00); // normally high, only applicable if INTCONB == 0x0xFF Write(INTCONB, 0x00); // interrupt occurs upon pin change Write(GPINTENB, 0x00); // disable all interrupts Write(GPIOA, 0); // drive all outputs low // test read ReadGPA(); SendEvent(); return true; } catch(Exception ex) { SpiDev = null; SendEvent(); return false; } }
private async Task InitGpio() { gpioAvailable = false; if (ApiInformation.IsTypePresent(typeof(GpioController).ToString())) { gpio = GpioController.GetDefault(); if (gpio != null) { pin = gpio.OpenPin(GPIO12); if (pin != null) { gpioAvailable = true; LedStatus = GpioPinValue.Low; pin.SetDriveMode(GpioPinDriveMode.Output); } } } else { await new MessageDialog("GPIO is unavailable on this device").ShowAsync(); } }
internal async Task InitializeHardware() { try { _ioController = GpioController.GetDefault(); _interruptPin = _ioController.OpenPin(17); _interruptPin.Write(GpioPinValue.Low); _interruptPin.SetDriveMode(GpioPinDriveMode.Input); _interruptPin.ValueChanged += Interrupt; _mpu9150 = new I2CDevice((byte)Mpu9150Setup.Address, I2cBusSpeed.FastMode); await _mpu9150.Open(); await Task.Delay(5); // power up _mpu9150.Write((byte)Mpu9150Setup.PowerManagement1, 0x80);// reset the device await Task.Delay(100); _mpu9150.Write((byte)Mpu9150Setup.PowerManagement1, 0x2 ); _mpu9150.Write((byte)Mpu9150Setup.UserCtrl, 0x04);//reset fifo _mpu9150.Write((byte)Mpu9150Setup.PowerManagement1, 1 ); // clock source = gyro x _mpu9150.Write((byte)Mpu9150Setup.GyroConfig, 0); // +/- 250 degrees sec, max sensitivity _mpu9150.Write((byte)Mpu9150Setup.AccelConfig, 0); // +/- 2g, max sensitivity _mpu9150.Write((byte)Mpu9150Setup.Config, 1);// 184 Hz, 2ms delay _mpu9150.Write((byte)Mpu9150Setup.SampleRateDiv, 19); // set rate 50Hz _mpu9150.Write((byte)Mpu9150Setup.FifoEnable, 0x78); // enable accel and gyro to read into fifo _mpu9150.Write((byte)Mpu9150Setup.UserCtrl, 0x40); // reset and enable fifo _mpu9150.Write((byte)Mpu9150Setup.InterruptEnable, 0x1); } catch (Exception ex) { Debug.WriteLine(ex); } }
private async Task InitGPIO() { // Get the GPIO controller try { gpioController = await GpioController.GetDefaultAsync(); } catch (Exception ex) { throw new Exception("GPIO Initialization failed.", ex); } pinNIRQ = gpioController.OpenPin(NIRQ_PIN, GpioSharingMode.Exclusive); pinNIRQ.SetDriveMode(GpioPinDriveMode.Input); }
private void button_Click(object sender, RoutedEventArgs e) { _GpioController = GpioController.GetDefault(); _resetEvent = new ManualResetEvent(false); if (this._GpioController != null) { using (GpioPin data = _GpioController.OpenPin(17)) using (GpioPin clock = _GpioController.OpenPin(27)) using (GpioPin strobe = _GpioController.OpenPin(22)) { data.SetDriveMode(GpioPinDriveMode.Output); clock.SetDriveMode(GpioPinDriveMode.Output); strobe.SetDriveMode(GpioPinDriveMode.Output); var display = new TM1638(data, clock, strobe, true, 1); display.setDisplayToString("COUCOU !", 0, 0); for (byte i = 0; i < 8; i++) { Task.Delay(500 / 2).Wait(); display.setLED(TM1638.TM1638_LED_COLOR.RED, i); Task.Delay(500 / 2).Wait(); display.setLED(TM1638.TM1638_LED_COLOR.GREEN, i); } Task.Delay(3000 / 2).Wait(); display.setDisplayToString("BISOUS! ", 0, 0); Task.Delay(3000 / 2).Wait(); for (int i = 0; i < 360; i++) { display.setDisplayToString(String.Format("4 {0}", i.ToString().PadRight(3, ' ')), 0, 0); } Task.Delay(3000 / 2).Wait(); //ClearLED for (byte i = 0; i < 8; i++) { display.setLED(TM1638.TM1638_LED_COLOR.OFF, i); } display.clearDisplay(); } } }
private void clear_Click(object sender, RoutedEventArgs e) { _GpioController = GpioController.GetDefault(); _resetEvent = new ManualResetEvent(false); if (this._GpioController != null) { using (GpioPin data = _GpioController.OpenPin(17)) using (GpioPin clock = _GpioController.OpenPin(27)) using (GpioPin strobe = _GpioController.OpenPin(22)) { data.SetDriveMode(GpioPinDriveMode.Output); clock.SetDriveMode(GpioPinDriveMode.Output); strobe.SetDriveMode(GpioPinDriveMode.Output); var display = new TM1638(data, clock, strobe, true, 1); //ClearLED for (byte i = 0; i < 8; i++) { display.setLED(TM1638.TM1638_LED_COLOR.OFF, i); } display.clearDisplay(); } } }
private GpioPin configureGpio(GpioController gpioController, int gpioId, GpioPinValue pinValue, GpioPinDriveMode pinDriveMode) { GpioPin pinTemp; pinTemp = gpioController.OpenPin(gpioId); pinTemp.Write(pinValue); pinTemp.SetDriveMode(pinDriveMode); return pinTemp; }
public RcTransmitter(int pin, Protocol protocol, int repeat = defaultRepeatTransmit) { this.protocol = protocol; this.repeatTransmit = repeat; switch (protocol) { case Protocol.REV: pulseLength = 360; spiFrequency = 10000000; break; case Protocol.HomeEasy: pulseLength = 250; spiFrequency = 10000000; break; case Protocol.Intertechno: default: pulseLength = 350; spiFrequency = 10000000; break; } if (pin == 0 && spiDevice == null) { spiDevice = InitSpi().Result; } else { gpioController = GpioController.GetDefault(); gpioPin = gpioController.OpenPin(pin, GpioSharingMode.Exclusive); gpioPin.Write(GpioPinValue.Low); gpioPin.SetDriveMode(GpioPinDriveMode.Output); } }
/* Initialize the GPIO */ private void InitGpio() { IoController = GpioController.GetDefault(); /* Get the default GPIO controller on the system */ if (IoController == null) { throw new Exception("GPIO does not exist on the current system."); } /* Initialize a pin as output for the Data/Command line on the display */ DataCommandPin = IoController.OpenPin(DATA_COMMAND_PIN); DataCommandPin.Write(GpioPinValue.High); DataCommandPin.SetDriveMode(GpioPinDriveMode.Output); /* Initialize a pin as output for the hardware Reset line on the display */ ResetPin = IoController.OpenPin(RESET_PIN); ResetPin.Write(GpioPinValue.High); ResetPin.SetDriveMode(GpioPinDriveMode.Output); }
//Method to initialize the TCS34725 sensor public async Task Initialize() { Debug.WriteLine("TCS34725::Initialize"); try { //Instantiate the I2CConnectionSettings using the device address of the TCS34725 I2cConnectionSettings settings = new I2cConnectionSettings(TCS34725_Address); //Set the I2C bus speed of connection to fast mode settings.BusSpeed = I2cBusSpeed.FastMode; //Use the I2CBus device selector to create an advanced query syntax string string aqs = I2cDevice.GetDeviceSelector(I2CControllerName); //Use the Windows.Devices.Enumeration.DeviceInformation class to create a //collection using the advanced query syntax string DeviceInformationCollection dis = await DeviceInformation.FindAllAsync(aqs); //Instantiate the the TCS34725 I2C device using the device id of the I2CBus //and the I2CConnectionSettings colorSensor = await I2cDevice.FromIdAsync(dis[0].Id, settings); //Create a default GPIO controller gpio = GpioController.GetDefault(); //Open the LED control pin using the GPIO controller LedControlGPIOPin = gpio.OpenPin(LedControlPin); //Set the pin to output LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output); //Initialize the known color list initColorList(); } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace); throw; } }