public ADS7830(String I2CBus) { PeripheralManager pioService = PeripheralManager.Instance; II2cDevice _device = pioService.OpenI2cDevice(I2CBus, I2C_ADDRESS); this.device = _device; this.disposed = false; this.read = new byte[1]; this.write = new byte[1]; }
public MMA8453(String I2CBus) { PeripheralManager pioService = PeripheralManager.Instance; II2cDevice _device = pioService.OpenI2cDevice(I2CBus, I2C_ADDRESS); this.device = _device; this.write = new byte[1]; this.write[0] = 0x01; this.read = new byte[6]; this.disposed = false; byte[] initdata = new byte[] { 0x2A, 0x01 }; this.device.Write(initdata, initdata.Length); }
private void FrmShell_Load(object sender, EventArgs e) { //SetDeiveState("YBL-SingleFireThreeKeySwitch", "1", "1", "1", new string[] { "ybl_DD3A0300" }); //SetDeiveState("YBL-SingleFireThreeKeySwitch", "0", "0", "0", new string[] { "ybl_DD3A0300" }); //SetDeiveState("LoRaAirPanel", "1", new string[] { "GIK8330011" }); //peripheralManager = AutofacContainer.ResolveNamed<PeripheralManager>("peripheralManager"); //也可以用反射 peripheralManager = new PeripheralManager(); //webBrowser.Navigate(AppState.WelcomeUrl); //webBrowser.Navigate(Path.Combine(Config.AppRoot, "web\\mySelf\\qms\\html\\admin\\index.html")); //webBrowser.Navigate(Path.Combine(Config.AppRoot, "web\\duogong\\html\\index.html")); webBrowser.Navigate(Path.Combine(Config.AppRoot, "web\\wulianwang\\html\\inde.html")); //webBrowser.Navigate(Path.Combine(Config.AppRoot, "web\\youpingui\\html\\index.html")); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); _manager = PeripheralManager.Instance; // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.myButton); button.Click += delegate { button.Text = $"{count++} clicks!"; }; SetupDemoShowPins(); SetupDemo1(); SetupDemo2(); SetupDemo3(); }
public Motor(PCA9685 pwm, int pwmChannel, String direction1Pin, String direction2Pin) { PeripheralManager manager = PeripheralManager.Instance; this.direction1 = manager.OpenGpio(direction1Pin); this.direction2 = manager.OpenGpio(direction2Pin); this.speed = 0.0; this.pwm = pwm; this.disposed = false; this.pwmChannel = pwmChannel; // Initialize the pin as a high output this.direction1.SetDirection(Gpio.DirectionOutInitiallyHigh); // Low voltage is considered active this.direction1.SetActiveType(Gpio.ActiveHigh); // Initialize the pin as a high output this.direction2.SetDirection(Gpio.DirectionOutInitiallyHigh); // Low voltage is considered active this.direction2.SetActiveType(Gpio.ActiveHigh); }
public PCA9685(String I2CBus, String GPIO_NAME) { PeripheralManager pioService = PeripheralManager.Instance; II2cDevice _device = pioService.OpenI2cDevice(I2CBus, I2C_ADDRESS); this.write5 = new byte[5]; this.write2 = new byte[2]; this.write1 = new byte[1]; this.read1 = new byte[1]; this.disposed = false; this.device = _device; try { PeripheralManager manager = PeripheralManager.Instance; this.outputEnable = manager.OpenGpio(GPIO_NAME); } catch (Exception e) { Log.WriteLine(LogPriority.Info, TAG, "Unable to access GPIO", e); } if (this.outputEnable != null) { // Initialize the pin as a high output this.outputEnable.SetDirection(Gpio.DirectionOutInitiallyHigh); // Low voltage is considered active this.outputEnable.SetActiveType(Gpio.ActiveLow); // Toggle the value to be LOW this.outputEnable.Value = (false); //this.outputEnable.SetDriveMode(GpioPinDriveMode.Output); //this.outputEnable.Write(GpioPinValue.Low); } this.WriteRegister(Register.Mode1, (byte)0x20); this.WriteRegister(Register.Mode2, (byte)0x06); }
private static string GetBoardVariant() { if (sBoardVariant != string.Empty) { return(sBoardVariant); } sBoardVariant = Build.Device; // For the edison check the pin prefix // to always return Edison Breakout pin name when applicable. if (sBoardVariant.Equals(DEVICE_EDISON)) { PeripheralManager pioService = PeripheralManager.Instance; List <string> gpioList = pioService.GpioList.ToList(); if (gpioList.Count != 0) { String pin = gpioList[0]; if (pin.StartsWith("IO")) { sBoardVariant = DEVICE_EDISON_ARDUINO; } } } return(sBoardVariant); }
/// <summary> /// Creates a new instance of the FEZ HAT. /// </summary> /// <returns>The new instance.</returns> public static FezHat Create() { PeripheralManager manager = PeripheralManager.Instance; //var gpioController = GpioController.GetDefault(); //var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector(FezHat.I2cDeviceName)))[0]; FezHat hat = new FezHat(); hat.accelerometer = new MMA8453(I2cDeviceName); hat.analog = new ADS7830(I2cDeviceName); hat.pwm = new PCA9685(I2cDeviceName, "BCM13");//gpioController.OpenPin(13) hat.pwm.OutputEnabled = true; hat.pwm.Frequency = 1500; hat.dio16 = manager.OpenGpio("BCM16"); //gpioController.OpenPin(16); hat.dio26 = manager.OpenGpio("BCM26"); //gpioController.OpenPin(26); hat.dio24 = manager.OpenGpio("BCM24"); //gpioController.OpenPin(24); hat.dio18 = manager.OpenGpio("BCM18"); //gpioController.OpenPin(18);xx hat.dio22 = manager.OpenGpio("BCM22"); //gpioController.OpenPin(22); //hat.dio16.SetDriveMode(GpioPinDriveMode.Input); // Initialize the pin as an input hat.dio16.SetDirection(Gpio.DirectionIn); // High voltage is considered active hat.dio16.SetActiveType(Gpio.ActiveHigh); //hat.dio26.SetDriveMode(GpioPinDriveMode.Input); // Initialize the pin as an input hat.dio26.SetDirection(Gpio.DirectionIn); // High voltage is considered active hat.dio26.SetActiveType(Gpio.ActiveHigh); //hat.dio24.SetDriveMode(GpioPinDriveMode.Output); // Initialize the pin as a high output hat.dio24.SetDirection(Gpio.DirectionOutInitiallyHigh); // Low voltage is considered active hat.dio24.SetActiveType(Gpio.ActiveHigh); //hat.dio18.SetDriveMode(GpioPinDriveMode.Input); // Initialize the pin as an input hat.dio18.SetDirection(Gpio.DirectionIn); // High voltage is considered active hat.dio18.SetActiveType(Gpio.ActiveHigh); //hat.dio22.SetDriveMode(GpioPinDriveMode.Input); // Initialize the pin as an input hat.dio22.SetDirection(Gpio.DirectionIn); // High voltage is considered active hat.dio22.SetActiveType(Gpio.ActiveHigh); hat.motorEnable = manager.OpenGpio("BCM12");//gpioController.OpenPin(12); //hat.motorEnable.SetDriveMode(GpioPinDriveMode.Output); // Initialize the pin as a high output hat.motorEnable.SetDirection(Gpio.DirectionOutInitiallyHigh); // Low voltage is considered active hat.motorEnable.SetActiveType(Gpio.ActiveHigh); hat.motorEnable.Value = true; //hat.MotorA = new Motor(hat.pwm, 14, 27, 23); hat.MotorA = new Motor(hat.pwm, 14, "BCM27", "BCM23"); //hat.MotorB = new Motor(hat.pwm, 13, 6, 5); hat.MotorB = new Motor(hat.pwm, 13, "BCM6", "BCM5"); 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); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.activity_main); _tempValueTxtiew = FindViewById <TextView>(Resource.Id.tempValue); _pressureValueTxtView = FindViewById <TextView>(Resource.Id.pressureValue); _sensorManager = (SensorManager)GetSystemService(SensorService); _dynamicSensorCallback = new DynamicSensorCallback(this); try { _buttonInputDriver = new ButtonInputDriver(BoardDefaults.GetButtonGpioPin(), Google.Android.Things.Contrib.Driver.Button.Button.LogicState.PressedWhenLow, (int)KeyEvent.KeyCodeFromString("KEYCODE_A")); _buttonInputDriver.Register(); Log.Debug(TAG, "Initialized GPIO Button that generates a keypress with KEYCODE_A"); } catch (Exception e) { throw new Exception("Error initializing GPIO button", e); } try { _environmentalSensorDriver = new Bmx280SensorDriver(BoardDefaults.GetI2cBus()); _sensorManager.RegisterDynamicSensorCallback(_dynamicSensorCallback); _environmentalSensorDriver.RegisterTemperatureSensor(); _environmentalSensorDriver.RegisterPressureSensor(); Log.Debug(TAG, "Initialized I2C BMP280"); } catch (Exception e) { throw new Exception("Error initializing BMP280", e); } try { _display = new AlphanumericDisplay(BoardDefaults.GetI2cBus()); _display.SetEnabled(true); _display.Clear(); Log.Debug(TAG, "Initialized I2C Display"); } catch (Exception e) { Log.Error(TAG, "Error initializing display", e); Log.Debug(TAG, "Display disabled"); _display = null; } try { _ledStrip = new Apa102(BoardDefaults.GetSpiBus(), Apa102.Mode.Bgr); _ledStrip.Brightness = LEDSTRIP_BRIGHTNESS; for (int i = 0; i < _rainbow.Length; i++) { float[] hsv = { i * 360f / _rainbow.Length, 1.0f, 1.0f }; _rainbow[i] = Color.HSVToColor(255, hsv); } } catch (Exception e) { Console.WriteLine(e); _ledStrip = null; } try { PeripheralManager pioService = PeripheralManager.Instance; _led = pioService.OpenGpio(BoardDefaults.GetLedGpioPin()); _led.SetEdgeTriggerType(Gpio.EdgeNone); _led.SetDirection(Gpio.DirectionOutInitiallyLow); _led.SetActiveType(Gpio.ActiveHigh); } catch (Exception e) { Console.WriteLine(e); } try { _speaker = new Speaker(BoardDefaults.GetSpeakerPwmPin()); ValueAnimator slide = ValueAnimator.OfFloat(440, 440 * 4); slide.SetDuration(50); slide.RepeatCount = 5; slide.SetInterpolator(new LinearInterpolator()); slide.AddUpdateListener(this); } catch (Exception e) { Console.WriteLine(e); throw; } }