private async void Setup() { this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); this.timer.Tick += this.OnTick; this.timer.Start(); }
public MainPage() { this.InitializeComponent(); this.Loaded += OnLoaded; var ai = AnalyticsInfo.VersionInfo; Debug.WriteLine(string.Format("Device Family = {0}", ai.DeviceFamily)); _isRunningOnPi = ai.DeviceFamily == "Windows.IoT"; //_isRunningOnPi = Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController"); BUG? Always returns true regardless of the device. if (_isRunningOnPi) { Task.Run(async () => _fezhat = await FEZHAT.CreateAsync()); _buttonMonitor = new DispatcherTimer(); _buttonMonitor.Interval = new TimeSpan(TimeSpan.TicksPerSecond/4); _buttonMonitor.Tick += ButtonMonitorOnTick; _buttonMonitor.Start(); } }
/// <summary> /// Creates a new instance of the FEZ HAT. /// </summary> /// <returns>The new instance.</returns> public static async Task <FEZHAT> CreateAsync() { var gpioController = GpioController.GetDefault(); var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector(FEZHAT.I2cDeviceName)))[0]; var hat = new FEZHAT(); hat.accelerometer = new MMA8453(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(MMA8453.GetAddress(false)))); hat.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); hat.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true))), gpioController.OpenPin(13)); hat.pwm.OutputEnabled = true; hat.pwm.Frequency = 1500; hat.dio16 = gpioController.OpenPin(16); hat.dio26 = gpioController.OpenPin(26); hat.dio24 = gpioController.OpenPin(24); hat.dio18 = gpioController.OpenPin(18); hat.dio22 = gpioController.OpenPin(22); hat.dio24.SetDriveMode(GpioPinDriveMode.Output); hat.dio18.SetDriveMode(GpioPinDriveMode.Input); hat.dio22.SetDriveMode(GpioPinDriveMode.Input); hat.motorEnable = gpioController.OpenPin(12); hat.motorEnable.SetDriveMode(GpioPinDriveMode.Output); hat.motorEnable.Write(GpioPinValue.High); hat.MotorA = new Motor(hat.pwm, 14, 27, 23); hat.MotorB = new Motor(hat.pwm, 13, 6, 5); hat.D2 = new RgbLed(hat.pwm, 1, 0, 2); hat.D3 = new RgbLed(hat.pwm, 4, 3, 15); hat.S1 = new Servo(hat.pwm, 9); hat.S2 = new Servo(hat.pwm, 10); return(hat); }
/// <summary> /// Creates a new instance of the FEZ HAT. /// </summary> /// <returns>The new instance.</returns> public static async Task<FEZHAT> CreateAsync() { var gpioController = GpioController.GetDefault(); var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector(FEZHAT.I2cDeviceName)))[0]; var hat = new FEZHAT(); hat.accelerometer = new MMA8453(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(MMA8453.GetAddress(false)))); hat.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); hat.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true))), gpioController.OpenPin(13)); hat.pwm.OutputEnabled = true; hat.pwm.Frequency = 1500; hat.dio16 = gpioController.OpenPin(16); hat.dio26 = gpioController.OpenPin(26); hat.dio24 = gpioController.OpenPin(24); hat.dio18 = gpioController.OpenPin(18); hat.dio22 = gpioController.OpenPin(22); hat.dio24.SetDriveMode(GpioPinDriveMode.Output); hat.dio18.SetDriveMode(GpioPinDriveMode.Input); hat.dio22.SetDriveMode(GpioPinDriveMode.Input); hat.motorEnable = gpioController.OpenPin(12); hat.motorEnable.SetDriveMode(GpioPinDriveMode.Output); hat.motorEnable.Write(GpioPinValue.High); hat.MotorA = new Motor(hat.pwm, 14, 27, 23); hat.MotorB = new Motor(hat.pwm, 13, 6, 5); hat.D2 = new RgbLed(hat.pwm, 1, 0, 2); hat.D3 = new RgbLed(hat.pwm, 4, 3, 15); hat.S1 = new Servo(hat.pwm, 9); hat.S2 = new Servo(hat.pwm, 10); return hat; }