Beispiel #1
1
        protected GpioTimedModuleBase(GpioController controller, ReadingMode mode, int timerPeriod)
            : base(mode, timerPeriod)
        {
            Controller = controller;

            // Shows an error if there is no GPIO controller
            if (Controller == null)
                throw new ArgumentException("No GPIO controller found.");
        }
Beispiel #2
0
        private void InitGPIO()
        {
            _gpio = GpioController.GetDefault();
            var inGpioPin = _gpio.OpenPin(27);

            inGpioPin.ValueChanged += ConversionReady;
        }
Beispiel #3
0
        public async Task<bool> InitializeComponent()
        {
            var devicefamily = GetForCurrentView().QualifierValues["DeviceFamily"];
            if (devicefamily != "Universal")
                return false;

            if(gpiocontroller==null)
                gpiocontroller = GpioController.GetDefault();

            if (gpiocontroller == null)
            {
                if (Gpios != null)
                {
                    for (int i = 0; i < Gpios.Count(); i++)
                    {
                        Gpios[i] = null;
                    }
                }
                Status = GpioStatus.NoGPIO;
            }
            else
            {
                Status = GpioStatus.Initialized;
                await Task.Delay(200);
                Status = InitializeGpios();
                await Task.Delay(200);
            }

            return true;
        }
		static RasPiManager()
		{
			s_gpio = GpioController.GetDefault();
			s_coll = new Dictionary<int, GpioPin>();

			InitSPI();
		}
Beispiel #5
0
        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 )
                                     };
            */
        }
Beispiel #6
0
        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;
            }

        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new <see cref="SoftPwm"/> instance.
        /// </summary>
        public SoftPwm()
        {
            // Get GPIO
            gpioController = GpioController.GetDefault();

            // Make sure we have it
            if (gpioController == null) { throw new DeviceNotFoundException("GPIO"); }

            // How many pins
            pinCount = gpioController.PinCount;

            // Create pin lookup
            pins = new Dictionary<int, SoftPwmPin>(pinCount);

            // Create
            stopwatch = new Stopwatch();

            // Defaults
            actualFrequency = MIN_FREQUENCY;
            ticksPerSecond = Stopwatch.Frequency;

            // Create the updater. Default to 0 seconds between updates, meaning run as fast as possible.
            // IMPORTANT: Do not use Scheduler.Default, create a new Scheduler.
            // This puts us in parallel priority with other sensors and allows
            // us to run on a separate core if available.
            updater = new ScheduledUpdater(scheduleOptions: new ScheduleOptions(0), scheduler: new Scheduler());
            updater.SetUpdateAction(Update);
        }
        private void InitGPIO()
        {
            this.gpio = GpioController.GetDefault();

            if (gpio == null)
                throw new NullReferenceException("No GPIO controller found!");
        }
Beispiel #9
0
 public RgbLed(GpioController gpioController)
     : base(gpioController)
 {
     this.RedPin = _defaultPin;
     this.BluePin = _defaultPin;
     this.GreenPin = _defaultPin;
     this.Status = RgbLedStatus.Off;
 }
Beispiel #10
0
        public MainPage()
        {
            this.InitializeComponent();

            gpio = GpioController.GetDefault();
            pin4 = gpio.OpenPin(4);
            pin4.SetDriveMode(GpioPinDriveMode.Output);
        }
Beispiel #11
0
        public static void InitGPIO()
        {
            if (controller == null)
                controller = GpioController.GetDefault();

            if (num2pin == null)
                num2pin = new Dictionary<int, GpioPin>();
        }
Beispiel #12
0
        private void initialize()
        {
            controller = GpioController.GetDefault();

            initializeLimitSwitches();
            initializeMotors();
            initializeGoalSensors();
        }
Beispiel #13
0
        protected GpioModuleBase(GpioController controller)
        {
            Controller = controller;

            // Shows an error if there is no GPIO controller
            if (Controller == null)
                throw new ArgumentException("No GPIO controller found.");
        }
Beispiel #14
0
        public XGpio(int pinNumber, GpioController gpio, GpioSharingMode sharingMode, GpioPinDriveMode driveMode)
        {
            _pinNumber = pinNumber;
            _gpio = gpio;
            _sharingMode = sharingMode;
            _driveMode = driveMode;

            _init();
        }
Beispiel #15
0
        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();


        }
Beispiel #16
0
        GpioPin R5;                                                 // Pin for row '5'



        public LEDDriver()
        {
            gpioController = GpioController.GetDefault();           // Initializes a LEDDriver object

            if (gpioController == null)
                throw new NonGpioDeviceException();                 // Device has no GPIO

            InitializeGpioPins();                                   // Initialize GPIO pins
            IdleAnimation();
        }
Beispiel #17
0
		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 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;
 }
Beispiel #19
0
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            //Initialize objects
            gpioController = GpioController.GetDefault();
            IAdcControllerProvider MCP3008_SPI0 = new McpClassAdc();
            adcManager = new AdcProviderManager();
            lightVals = new List<double>();
            //Insert 10 dummy values to initialize.
            for (int i = 0; i < 30; i++)
            {
                lightVals.Add(0);
            }

            tempVals = new List<double>();
            for(int i = 0; i < 30; i++)
            {
                tempVals.Add(0);
            }
            //Initialize MCP3008 device.
            //Remember, 8 channels, 10 bit resolution
            //We wired up to SPI0 of pi with Chip select 0.
            ((McpClassAdc)MCP3008_SPI0).ChannelCount = 8;
            ((McpClassAdc)MCP3008_SPI0).ChannelMode = ProviderAdcChannelMode.SingleEnded;
            ((McpClassAdc)MCP3008_SPI0).ChipSelectLine = 0;
            ((McpClassAdc)MCP3008_SPI0).ControllerName = "SPI0";
            ((McpClassAdc)MCP3008_SPI0).ResolutionInBits = 10;
            #region ADC Provider Stuff
            //Add ADC Provider to list of providers
            adcManager.Providers.Add(MCP3008_SPI0);
            //Get all ADC Controllers.
            var adcControllers = await adcManager.GetControllersAsync();
            //This is just how its done. 
            #endregion ADC Provider Stuff
            var lightSensor = new AnalogSensor()
            {
                //Notice access via controller index.
                //You will need to keep tabs on your 
                //ADC providers locations in the list
                //Channel 7 as this is where we wired the photo resistor to.
                AdcChannel = adcControllers[0].OpenChannel(7),
                //every 500 milliseconds, grab read the value.
                ReportInterval = 250
            };
            //Attach a function to the event we fire every 500 milliseconds.
            lightSensor.ReadingChanged += LightSensor_ReadingChanged;

            #region Temp Sensor Cheat Codes
            var tempSensor = new AnalogSensor()
            {
                AdcChannel = adcControllers[0].OpenChannel(6),
                ReportInterval = 250
            };
            tempSensor.ReadingChanged += TempSensor_ReadingChanged;
            #endregion Temp Sensor Cheat Codes
        }
        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
        }
Beispiel #21
0
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            //Initialize objects
            gpioController = GpioController.GetDefault();
            IAdcControllerProvider MCP3008_SPI0 = new MCP3008();
            adcManager = new AdcProviderManager();
            lightVals = new List<double>();
            deviceClient = DeviceClient
                            .CreateFromConnectionString(IoTHubConnString,
                            TransportType.Http1);
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick += BroadcastTelemetry;
            timer.Start();
            //Insert 10 dummy values to initialize.
            for (int i = 0; i < 30; i++)
            {
                lightVals.Add(0);
            }

            tempVals = new List<double>();
            for (int i = 0; i < 30; i++)
            {
                tempVals.Add(0);
            }
            #region ADC Provider Stuff
            //Add ADC Provider to list of providers
            adcManager.Providers.Add(MCP3008_SPI0);
            //Get all ADC Controllers.
            var adcControllers = await adcManager.GetControllersAsync();
            //This is just how its done. 
            #endregion ADC Provider Stuff
            var lightSensor = new AnalogSensor()
            {
                //Notice access via controller index.
                //You will need to keep tabs on your 
                //ADC providers locations in the list
                //Channel 7 as this is where we wired the photo resistor to.
                AdcChannel = adcControllers[0].OpenChannel(7),
                //every 500 milliseconds, grab read the value.
                ReportInterval = 250
            };
            //Attach a function to the event we fire every 500 milliseconds.
            lightSensor.ReadingChanged += LightSensor_ReadingChanged;

            #region Temp Sensor Cheat Codes
            var tempSensor = new AnalogSensor()
            {
                AdcChannel = adcControllers[0].OpenChannel(6),
                ReportInterval = 250
            };
            tempSensor.ReadingChanged += TempSensor_ReadingChanged;
            #endregion Temp Sensor Cheat Codes
        }
Beispiel #22
0
        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));
            }
        }
Beispiel #23
0
 public Gpio()
 {
     if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController"))
     {
         _gpioController = GpioController.GetDefault();
     }
     else
     {
         throw new NotSupportedException("Device doesn't support GPIO");
     }
 }
        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);
            }
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        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();
        }
Beispiel #27
0
        /// <summary>
        /// Initializes the IO Manager.
        /// </summary>
        public void Initialize()
        {
            // Check for GPIO support
            if (ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController"))
            {
                // Get the default GPIO controller
                controller = GpioController.GetDefault();

                // Only enabled if controller was found
                isEnabled = (controller != null);
            }
        }
        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;
        }
Beispiel #29
0
        private void InitGPIO()
        {
            Debug.WriteLine("Initializing GPIO controller.");

            gpioController = GpioController.GetDefault();

            if (gpioController == null)
            {
                Debug.WriteLine("There is no GPIO controller on this device.");
                throw new Exception("There is no GPIO controller on this device.");
            }

            Debug.WriteLine("GPIO controller intialized.");
        }
Beispiel #30
0
 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;
         }
     }
 }
        /// <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;
        }