An implementation of IAdcProvider that allows multiple ADC controllers to be registered as a simple collection.
All controllers should be added to the Providers collection before calling AdcProviderManager.GetControllersAsync.
Inheritance: IAdcProvider, IDisposable
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Start GPIO
            var gpioController = GpioController.GetDefault();

            // Create ADC manager
            var adcManager = new AdcProviderManager();

            // Add ADC chips
            adcManager.Providers.Add(
                new ADC0832()
                {
                    ChipSelectPin = gpioController.OpenPin(18),
                    ClockPin = gpioController.OpenPin(23),
                    DataPin = gpioController.OpenPin(24),
                });


            // Get the well-known controller collection back
            var adcControllers = await adcManager.GetControllersAsync();

            // Create light sensor
            var lightSensor = new AnalogSensor()
            {
                AdcChannel = adcControllers[0].OpenChannel(0),
                ReportInterval = 250,
            };

            // Subscribe to events
            lightSensor.ReadingChanged += LightSensor_ReadingChanged;
        }
Exemple #2
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
        }
Exemple #3
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
        }
Exemple #4
0
        private async Task SetupAsync()
        {
            // Start GPIO
            gpioController = GpioController.GetDefault();

            if (gpioController == null)
            {
                Debug.WriteLine("GPIO Controller not found!");
                return;
            }

            // ADC
            // Create the manager
            adcManager = new AdcProviderManager();

            adcManager.Providers.Add(
                new MCP3208()
                {
                    ChipSelectLine = 0,
                    ControllerName = "SPI1",
                });

            // Get the well-known controller collection back
            adcControllers = await adcManager.GetControllersAsync();

            await StartDisplayAsync();
            StartAnalog();
            SetupTimers();
            await TestAndUpdateStateAsync();
        }
        private void StopDevices()
        {
            // Stop cloud reporting if running
            StopCloudReporting();

            // Stop display rendering
            if (display != null)
            {
                GraphicsPanel.AutoUpdate = false;
                GraphicsPanel.Display = null;
            }

            for (int i = devices.Count -1; i >= 0; i--)
            {
                devices[i].Dispose();
                devices.RemoveAt(i);
            }

            if (adcManager != null)
            {
                adcManager.Dispose();
                adcManager = null;
                adcControllers = null;
            }
        }
        private async Task StartDevicesAsync()
        {
            // Start GPIO
            gpioController = GpioController.GetDefault();
            if (gpioController == null)
            {
                AddOutput("GPIO Controller not found!");
                return;
            }

            // ADC
            // Create the manager
            adcManager = new AdcProviderManager();

            // Add providers
            adcManager.Providers.Add(
                new ADC0832()
                {
                    ChipSelectPin = gpioController.OpenPin(18),
                    ClockPin = gpioController.OpenPin(23),
                    DataPin = gpioController.OpenPin(24),
                });

            adcManager.Providers.Add(
                new MCP3208()
                {
                    ChipSelectLine = 0,
                    ControllerName = "SPI1",
                });

            // Get the well-known controller collection back
            adcControllers = await adcManager.GetControllersAsync();

            await StartDisplayAsync();
            StartPushButton();
            StartRotary();
            StartSwitches();
            // StartAnalog();
            // StartTemperature();
            StartThumbstick();

            StartCloudReporting();
        }