コード例 #1
0
        public MainPage()
        {
            AppInsights.Client.TrackPageView(nameof(MainPage));

            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            this.InitializeComponent();
            mDeviceClient = DeviceClient.Create(Globals.IOTHUB_URI, new DeviceAuthenticationWithRegistrySymmetricKey(GetUniqueDeviceId(), Globals.DEVICE_KEY), TransportType.Amqp);
            registerKeyEvents();

            var hasGpio = GpioController.GetDefault() != null;

            if (hasGpio)
            {
                mWheels          = new Wheels();
                mObstacleSensors = new ObstacleSensors();
                mObstacleSensors.ValueReadingChanged += MObstacleSensors_ValueReading;
                mPanTiltServo = new PanTiltServo();
            }
            else
            {
                mWheels = new FakeWheels();
            }

            mCamera = new WebSocketCamera();
            mWheels.Init();
            NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
            Task.Run(() =>
            {
                receiveC2dAsync();
            });
        }
コード例 #2
0
        private async Task ConnectToI2CDevices()
        {
            try {
                string aqsFilter = I2cDevice.GetDeviceSelector("I2C1");

                //DeviceInformationCollection collection = await DeviceInformation.FindAllAsync(aqsFilter);
                //if (collection.Count == 0) {
                //    throw new SensorException("I2C device not found");
                //}

                if (LightningProvider.IsLightningEnabled)
                {
                    // Set Lightning as the default provider
                    LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                }

                I2cConnectionSettings i2CSettings = new I2cConnectionSettings(_i2CAddress)
                {
                    BusSpeed = I2cBusSpeed.FastMode
                };

                //_i2CDevice = await I2cDevice.FromIdAsync(collection[0].Id, i2CSettings);
                I2cController controller = await I2cController.GetDefaultAsync();

                if (controller == null)
                {
                    throw new SensorException("I2C device not found");
                }

                _i2CDevice = controller.GetDevice(i2CSettings);
            }
            catch (Exception exception) {
                throw new SensorException("Failed to connect to HTS221", exception);
            }
        }
コード例 #3
0
 public Led()
 {
     if (LightningProvider.IsLightningEnabled)
     {
         LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
     }
 }
コード例 #4
0
        public void Initialize(bool isEnabledByDefault)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            Gpio = GpioController.GetDefault();
            if (Gpio == null)
            {
                return;
            }

            //set pins d0 and d1 as input
            data0 = Gpio.OpenPin(_d0);
            data0.SetDriveMode(GpioPinDriveMode.InputPullUp);
            data0.DebounceTimeout = debounceTimeout;

            data1 = Gpio.OpenPin(_d1);
            data1.SetDriveMode(GpioPinDriveMode.InputPullUp);
            data1.DebounceTimeout = debounceTimeout;

            IsEnabledChanged += OnIsEnabledChanged;
            IsEnabled         = isEnabledByDefault;

            swReadingTimer = new Stopwatch();
            Debug.WriteLine("Initialized", DEBUG_CAT);
        }
コード例 #5
0
 private void ConfigureLightningController()
 {
     if (LightningProvider.IsLightningEnabled)
     {
         LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
     }
 }
コード例 #6
0
        private MainViewModel()
        {
            _LastGateChange = DateTime.Now;
            Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            string szDataFilePath = string.Format("{0}{1}{2}", storageFolder.Path, System.IO.Path.DirectorySeparatorChar, "racedata.db3");

            this.conn = new SQLite.SQLiteConnection(szDataFilePath);
            this.conn.CreateTable <RaceEvent>();
            this.conn.CreateTable <Racer>();
            this.conn.CreateTable <RaceHeat>();
            this.conn.CreateTable <HeatTime>();
            this.conn.CreateTable <RaceResult>();

            _mp          = new MediaPlayer();
            _mp.AutoPlay = false;

            if (!LightningProvider.IsLightningEnabled)
            {
                return;
            }

            LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            OpenPwnPin(27);

            InitGPIO();
            this.SetState(ApplicationState.MainMenu);
        }
コード例 #7
0
        private void InitGPIO()
        {
            //LightningProviderが利用できるかどうか確認
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            var gpio = GpioController.GetDefault();

            //GPIOコントローラーがない場合
            if (gpio == null)
            {
                pin = null;
                return;
            }

            // GPIO の 5 番ピンを開きます
            pin = gpio.OpenPin(LED_PIN);

            // 5番ピンを High に設定します
            pin.Write(GpioPinValue.High);

            // 5番ピンを出力として使うよう設定します
            pin.SetDriveMode(GpioPinDriveMode.Output);
        }
コード例 #8
0
ファイル: MainPage.xaml.cs プロジェクト: we4690/WinAlphaBot
        private async void btnInitialize_Click(object sender, RoutedEventArgs e)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            gpioController = await GpioController.GetDefaultAsync();

            if (gpioController == null)
            {
                return;
            }

            pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());

            if (pwmControllers == null)
            {
                return;
            }
            LeftMotor = new MotorControl(gpioController, pwmControllers[1]);
            LeftMotor.Initialize(LEFTINA, LEFTINB, LEFTPWM);
            RightMotor = new MotorControl(gpioController, pwmControllers[1]);
            RightMotor.Initialize(RIGHTINA, RIGHTINB, RIGHTPWM);
        }
コード例 #9
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // set deferral to keep the Application running at the end of the method.
            deferral = taskInstance.GetDeferral();

            // Set the Lightning Provider as the default if Lightning driver is enabled on the target device
            // Otherwise, the inbox provider will continue to be the default
            if (LightningProvider.IsLightningEnabled)
            {
                // Set Lightning as the default provider
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                Debug.WriteLine("GPIO Using Lightning Provider");
            }
            else
            {
                Debug.WriteLine("GPIO Using Default Provider");
            }

            var gpioController = GpioController.GetDefault(); /* Get the default GPIO controller on the system */

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

            InitGPIO();
        }
コード例 #10
0
ファイル: MainPage.xaml.cs プロジェクト: Modyomran/GPU
        public MainPage()
        {
            InitializeComponent();


            // Check if Lightning is available and use it
            // The Lightning greatly speedups SPI and GPIO to use it you must enable Direct Memory Mapped driver in Device manager
            // For more information see: https://developer.microsoft.com/en-us/windows/iot/docs/lightningproviders

            if (LightningProvider.IsLightningEnabled)
            {
                Debug.WriteLine("Using Lightning");
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            //===============================================================
            // Choose demo here!
            // ------------------------------

            //_currentDemo = OutputDemo;
            //_currentDemo = InputDemo;
            //_currentDemo = InputOutputDemo;
            _currentDemo = KnobToScreenDemo; // <-- Requires a monitor connected to the Raspberry Pi.

            //===============================================================

            Task.Run(async() => await Demo()).ConfigureAwait(false);
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        private bool initializeGpio()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                Windows.Devices.LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                textBlockStatus.Text = "Gpio using low level controller";
            }
            else
            {
                textBlockStatus.Text = "Gpio using default driver";
            }

            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                textBlockStatus.Text = "Gpio initialization error";
                return(false);
            }

            testPin_ = gpio.OpenPin(27);
            testPin_.SetDriveMode(GpioPinDriveMode.Output);
            dht11Pin_ = gpio.OpenPin(5);
            dht11Pin_.SetDriveMode(GpioPinDriveMode.Input);

            textBlockStatus.Text = "Gpio initialized!";
            return(true);
        }
コード例 #12
0
        private async Task Tml_Init(int irqPinNumber, int resetPinNumber)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            GpioController gpio = GpioController.GetDefault();

            pinIRQ   = gpio.OpenPin(irqPinNumber);
            pinRESET = gpio.OpenPin(resetPinNumber);

            pinRESET.Write(GpioPinValue.High);

            pinIRQ.SetDriveMode(GpioPinDriveMode.Input);
            pinRESET.SetDriveMode(GpioPinDriveMode.Output);

            I2cConnectionSettings settings = new I2cConnectionSettings(NXP_NCI_I2C_ADDR)
            {
                BusSpeed    = I2cBusSpeed.FastMode,
                SharingMode = I2cSharingMode.Shared
            };

            //string aqs = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME);
            //DeviceInformationCollection dis = await DeviceInformation.FindAllAsync(aqs);
            //i2c7120 = await I2cDevice.FromIdAsync(dis[0].Id, settings);

            I2cController i2cController = await I2cController.GetDefaultAsync();

            i2c7120 = i2cController.GetDevice(settings);
        }
コード例 #13
0
        private void LoadUserCode(object sender, RoutedEventArgs e)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }
            else
            {
                return;
            }

            GpioController _controller = GpioController.GetDefault();

            if (_controller == null)
            {
                return;
            }

            SideIR = _controller.OpenPin(21);
            SideIR.Write(GpioPinValue.Low);
            SideIR.SetDriveMode(GpioPinDriveMode.Input);
            SideIR.ValueChanged += TriggerPin_ValueChanged;

            FrontIR = _controller.OpenPin(4);
            FrontIR.Write(GpioPinValue.Low);
            FrontIR.SetDriveMode(GpioPinDriveMode.Input);
            FrontIR.ValueChanged += OnFrontIRChange;
        }
コード例 #14
0
        private async void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();

                var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());

                var pwmController = pwmControllers[1]; // the on-device controller
                pwmController.SetDesiredFrequency(50); // try to match 50Hz


                internetLed = new InternetLed();

                _pin18 = pwmController.OpenPin(18);

                while (true)
                {
                    await internetLed.GetThrottleFromWeb();

                    double test = internetLed.getThrottle() / 100.0;

                    _pin18.SetActiveDutyCyclePercentage(internetLed.getThrottle() / 100.0);
                    _pin18.Start();


                    await Task.Delay(200);
                }
            }
        }
コード例 #15
0
        private async void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();

                var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());

                var pwmController = pwmControllers[1]; // the on-device controller
                pwmController.SetDesiredFrequency(50); // try to match 50Hz

                _pin27 = pwmController.OpenPin(27);
                _pin27.SetActiveDutyCyclePercentage(0);
                _pin27.Start();
            }

            var gpioController = await GpioController.GetDefaultAsync();

            if (gpioController == null)
            {
                StatusMessage.Text = "There is no GPIO controller on this device.";
                return;
            }
            _pin22 = gpioController.OpenPin(22);
            _pin22.SetDriveMode(GpioPinDriveMode.Output);
            _pin22.Write(GpioPinValue.Low);
        }
        public MainPage()
        {
            this.InitializeComponent();

            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();

                System.Diagnostics.Debug.WriteLine("Lightning Success");
            }



            configSensors(); //Initialises the relevant sensors
            //Updates Readings Every 1/2 seconds.
            readPressure();
            readTemperature();


            //Initialising Dispatch Timer
            uiTimer          = new DispatcherTimer();
            uiTimer.Interval = TimeSpan.FromMilliseconds(2000);
            uiTimer.Tick    += UiTimer_Tick;
            Task.Delay(20).Wait();
            uiTimer.Start();
        }
コード例 #17
0
        private async void OnPageLoad(object sender, RoutedEventArgs e)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            var gpioController = await GpioController.GetDefaultAsync();

            if (gpioController == null)
            {
                return;
            }

            var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());


            pwmController = pwmControllers[1];       //hard code from examples to use index 1
            pwmController.SetDesiredFrequency(1000); //do *not* debug over this line, it will crash
            rightDrive = pwmController.OpenPin(13);
            rightDrive.SetActiveDutyCyclePercentage(0.5);
            rightDrive.Start();
            leftDrive = pwmController.OpenPin(12);
            leftDrive.SetActiveDutyCyclePercentage(0.5);
            leftDrive.Start();
        }
コード例 #18
0
        private async void LoadUserCode(object sender, RoutedEventArgs e)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }
            else
            {
                return;
            }
            var controllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());

            if (controllers.Count <= 1)
            {
                return;
            }
            driveControl = controllers[1];
            if (driveControl == null)
            {
                return;
            }
            if (driveControl == null)
            {
                return;
            }
            driveControl.SetDesiredFrequency(1000);
        }
コード例 #19
0
        private async Task InitLCD()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            var i2c = await I2cController.GetDefaultAsync();

            if (i2c == null)
            {
                LCD = null;
                return;
            }

            LCD = i2c.GetDevice(new I2cConnectionSettings(LCD_Addr));

            //LCD初期化
            await Task.Delay(50);

            await WriteCmd(0x38, 1);
            await WriteCmd(0x39, 1);
            await WriteCmd(0x14, 1);
            await WriteCmd(0x71, 1);
            await WriteCmd(0x56, 1);
            await WriteCmd(0x6c, 250);
            await WriteCmd(0x38, 1);
            await WriteCmd(0x0c, 1);
            await WriteCmd(0x01, 200);
        }
コード例 #20
0
        private void InitGPIO()
        {
            LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                return;
            }

            pushButton = gpio.OpenPin(17);
            pushButton.SetDriveMode(GpioPinDriveMode.Input); // VERY IMPORTANT. DO NOT SET OUTPUT
            pushButton.ValueChanged += PushButton_ValueChanged;

            FinishGates = new List <FinishGate>();
            FinishGate Track1FinishGate = new FinishGate(1, gpio, 4, InHeatVM.HeatStopWatch);

            Track1FinishGate.TrackCompleted += InHeatVM.TrackFinishGate_TrackCompleted;
            this.FinishGates.Add(Track1FinishGate);
            FinishGate Track2FinishGate = new FinishGate(2, gpio, 5, InHeatVM.HeatStopWatch);

            Track2FinishGate.TrackCompleted += InHeatVM.TrackFinishGate_TrackCompleted;
            this.FinishGates.Add(Track2FinishGate);
            FinishGate Track3FinishGate = new FinishGate(3, gpio, 6, InHeatVM.HeatStopWatch);

            Track3FinishGate.TrackCompleted += InHeatVM.TrackFinishGate_TrackCompleted;
            this.FinishGates.Add(Track3FinishGate);
            FinishGate Track4FinishGate = new FinishGate(4, gpio, 7, InHeatVM.HeatStopWatch);

            Track4FinishGate.TrackCompleted += InHeatVM.TrackFinishGate_TrackCompleted;
            this.FinishGates.Add(Track4FinishGate);
        }
コード例 #21
0
        private void LoadUserCode(object sender, RoutedEventArgs e)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }
            else
            {
                return;
            }

            GpioController _controller = GpioController.GetDefault();

            if (_controller == null)
            {
                return;
            }
            //TriggerPin = _controller.OpenPin(25);
            //TriggerPin.Write(GpioPinValue.Low);
            //TriggerPin.SetDriveMode(GpioPinDriveMode.Output);
            EchoPin = _controller.OpenPin(7);
            EchoPin.Write(GpioPinValue.Low);
            EchoPin.SetDriveMode(GpioPinDriveMode.Input);
            //disable for now...
            EchoPin.ValueChanged += OnEchoResponse;
            distanceTimer         = new Stopwatch();
            distanceTimer.Reset();
            SendTriggers = new Task(() => FakePWM());
            //SendTriggers.Start();
        }
コード例 #22
0
        /// <summary>
        ///
        /// </summary>
        private async void InitSensor()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            var i2c = await I2cController.GetDefaultAsync();

            SENSOR = i2c.GetDevice(new I2cConnectionSettings(SensorAddr));

            //SENSOR初期化
            uint osrs_t   = 3;
            uint osrs_p   = 3;
            uint osrs_h   = 3;
            uint mode     = 3;
            uint t_sb     = 5;
            uint filter   = 0;
            uint spi3w_en = 0;

            uint ctrlMeasReg = (osrs_t << 5) | (osrs_p << 2) | mode;
            uint configReg   = (t_sb << 5) | (filter << 2) | spi3w_en;
            uint ctrlHumReg  = osrs_h;

            SENSOR.Write(new byte[] { 0xf2, (byte)ctrlHumReg });
            SENSOR.Write(new byte[] { 0xf4, (byte)ctrlMeasReg });
            SENSOR.Write(new byte[] { 0xf5, (byte)configReg });

            await Task.Delay(10);


            //キャリブレーションデータ読み込み
            //温度
            T1 = ReadUInt16((byte)Register.dig_T1);
            T2 = (Int16)ReadUInt16((byte)Register.dig_T2);
            T3 = (Int16)ReadUInt16((byte)Register.dig_T3);

            //気圧
            P1 = ReadUInt16((byte)Register.dig_P1);
            P2 = (Int16)ReadUInt16((byte)Register.dig_P2);
            P3 = (Int16)ReadUInt16((byte)Register.dig_P3);
            P4 = (Int16)ReadUInt16((byte)Register.dig_P4);
            P5 = (Int16)ReadUInt16((byte)Register.dig_P5);
            P6 = (Int16)ReadUInt16((byte)Register.dig_P6);
            P7 = (Int16)ReadUInt16((byte)Register.dig_P7);
            P8 = (Int16)ReadUInt16((byte)Register.dig_P8);
            P9 = (Int16)ReadUInt16((byte)Register.dig_P9);

            //湿度
            H1 = ReadByte((byte)Register.dig_H1);
            H2 = (Int16)ReadUInt16((byte)Register.dig_H2);
            H3 = ReadByte((byte)Register.dig_H3);
            H4 = (short)(ReadByte((byte)Register.dig_H4) << 4 | ReadByte((byte)Register.dig_H4 + 1) & 0xf);
            H5 = (short)(ReadByte((byte)Register.dig_H5 + 1) << 4 | ReadByte((byte)Register.dig_H5) >> 4);
            H6 = (sbyte)ReadByte((byte)Register.dig_H6);

            //Timerのセット(1秒毎)
            periodicTimer = new Timer(this.TimerCallback, null, 0, 1000);
        }
コード例 #23
0
ファイル: Main.cs プロジェクト: Ce-Ma-S/PIR
 public Main() :
     base("PIR")
 {
     if (LightningProvider.IsLightningEnabled)
     {
         LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
     }
 }
コード例 #24
0
 private void InitLightningProvider()
 {
     // Set the Lightning Provider as the default if Lightning driver is enabled on the target device
     if (LightningProvider.IsLightningEnabled)
     {
         LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
     }
 }
コード例 #25
0
        public ServoController(int servoPin)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            ServoPin = servoPin;
        }
コード例 #26
0
ファイル: MainPage.xaml.cs プロジェクト: sanju5486/robot.sl
        private async Task Initialze()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }
            else
            {
                throw new Exception("Lightning drivers not enabled. Please enable Lightning drivers.");
            }

            _camera = new Camera();
            await _camera.Initialize();
            
            SpeedSensor.Initialize();
            SpeedSensor.Start();

            SpeechSynthesis.Initialze();

            await AudioPlayerController.Initialize();

            _accelerometerSensor = new AccelerometerGyroscopeSensor();
            await _accelerometerSensor.Initialize();
            _accelerometerSensor.Start();

            _automaticSpeakController = new AutomaticSpeakController(_accelerometerSensor);

            _motorController = new MotorController();
            await _motorController.Initialize(_automaticSpeakController);

            _servoController = new ServoController();
            await _servoController.Initialize();

            _distanceMeasurementSensor = new DistanceMeasurementSensor();
            await _distanceMeasurementSensor.Initialize(I2C_ADDRESS_SERVO);

            _automaticDrive = new AutomaticDrive(_motorController, _servoController, _distanceMeasurementSensor);

            _speechRecognation = new SpeechRecognition();
            await _speechRecognation.Initialze(_motorController, _servoController, _automaticDrive);
            _speechRecognation.Start();

            _gamepadController = new GamepadController(_motorController, _servoController, _automaticDrive, _accelerometerSensor);

            _camera.Start();

            _httpServerController = new HttpServerController(_motorController, _servoController, _automaticDrive, _camera);

            SystemController.Initialize(_accelerometerSensor, _automaticSpeakController, _motorController, _servoController, _automaticDrive, _camera, _httpServerController, _speechRecognation, _gamepadController);

            await SystemController.SetAudioRenderVolume(AUDIO_RENDER_VOLUME, true);
            await SystemController.SetAudioCaptureVolume(AUDIO_CAPTURE_VOLUME, true);
            
            await AudioPlayerController.PlayAndWaitAsync(AudioName.Welcome);

            _automaticSpeakController.Start();
        }
コード例 #27
0
 internal void InitGPIO()
 {
     if (!InDesing)
     {
         //Add support if the Controller driver is "Direct Memory Mapped Driver". See https://docs.microsoft.com/en-us/windows/iot-core/develop-your-app/lightningproviders
         if (LightningProvider.IsLightningEnabled)
         {
             LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
         }
     }
 }
コード例 #28
0
        private async Task SetupPWM()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());

                var pwmController = pwmControllers[1];                 // use the on-device controller
                pwmController.SetDesiredFrequency(50);                 // try to match 50Hz
                pin = pwmController.OpenPin(21);
            }
        }
コード例 #29
0
ファイル: MainPage.xaml.cs プロジェクト: eclecticlogic/buzzer
 private void InitGPIO()
 {
     if (LightningProvider.IsLightningEnabled)
     {
         LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
     }
     pins.Add(createButtonPin(5, "1", 21));
     pins.Add(createButtonPin(6, "2", 20));
     pins.Add(createButtonPin(13, "3", 9));
     pins.Add(createButtonPin(19, "4", 10));
     pins.Add(createButtonPin(26, "5", 11));
 }
コード例 #30
0
        public async void InitHardware()
        {
            try
            {
                if (LightningProvider.IsLightningEnabled)
                {
                    LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                }
                else
                {
                    return;
                }
                _ioController = GpioController.GetDefault();
                _interruptPin = _ioController.OpenPin(InterruptPin);
                _interruptPin.Write(GpioPinValue.Low);
                _interruptPin.SetDriveMode(GpioPinDriveMode.Input);
                _interruptPin.ValueChanged += Interrupt;

                //var aqs = I2cDevice.GetDeviceSelector();
                //var collection = await DeviceInformation.FindAllAsync(aqs);
                I2cController controller = await I2cController.GetDefaultAsync();

                var settings = new I2cConnectionSettings(Constants.Address)
                {
                    BusSpeed    = I2cBusSpeed.FastMode,
                    SharingMode = I2cSharingMode.Exclusive
                };
                //Mpu6050Device = await I2cDevice.FromIdAsync(collection[0].Id, settings);
                Mpu6050Device = controller.GetDevice(settings);

                await Task.Delay(3);                           // wait power up sequence

                ReadWrite.WriteByte(Constants.PwrMgmt1, 0x80); // reset the device
                await Task.Delay(100);

                ReadWrite.WriteByte(Constants.PwrMgmt1, 0x2);
                ReadWrite.WriteByte(Constants.UserCtrl, 0x04); //reset fifo

                ReadWrite.WriteByte(Constants.PwrMgmt1, 1);    // clock source = gyro x
                ReadWrite.WriteByte(Constants.GyroConfig, 0);  // +/- 250 degrees sec
                ReadWrite.WriteByte(Constants.AccelConfig, 0); // +/- 2g

                ReadWrite.WriteByte(Constants.Config, 1);      // 184 Hz, 2ms delay
                ReadWrite.WriteByte(Constants.SmplrtDiv, 19);  // set rate 50Hz
                ReadWrite.WriteByte(Constants.FifoEn, 0x78);   // enable accel and gyro to read into fifo
                ReadWrite.WriteByte(Constants.UserCtrl, 0x40); // reset and enable fifo
                ReadWrite.WriteByte(Constants.IntEnable, 0x1);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }