private static void AddressOrReset() { Console.WriteLine("Enter 1 or 2 to select a mode:\n1. Change address.\n2. Reset chip."); if (int.TryParse(Console.ReadLine(), out int mode)) { switch (mode) { case 1: { Console.WriteLine("Enter a new address:"); if (ushort.TryParse(Console.ReadLine(), out ushort address)) { _expander.ChangeAddress(address); Console.WriteLine("Change address."); _expander.SaveAddress(); #if WIRING_PI _expander = Pi.I2C.GetGpioExpander(); #endif #if NOT_WIRING_PI _expander = I2cBus.Create(1).GetGpioExpander(); #endif Console.WriteLine("Save address."); } else { Console.WriteLine("Invalid new address value."); } break; } case 2: { _expander.Reset(); Console.WriteLine("Reset chip."); break; } default: { Console.WriteLine("Invalid mode value."); break; } } } }
/// <summary> /// Constructs SenseHat instance /// </summary> public SenseHat(I2cBus?i2cBus = null, bool shouldDispose = false) { _shouldDispose = shouldDispose || i2cBus == null; _i2cBus = i2cBus ?? I2cBus.Create(DefaultI2cBusId); Debug.Assert(SenseHatLedMatrixI2c.I2cAddress == SenseHatJoystick.I2cAddress, $"Default addresses for {nameof(SenseHatLedMatrixI2c)} and {nameof(SenseHatJoystick)} were expected to be the same"); I2cDevice joystickAndLedMatrixI2cDevice = _i2cBus.CreateDevice(SenseHatLedMatrixI2c.I2cAddress); _ledMatrix = new SenseHatLedMatrixI2c(joystickAndLedMatrixI2cDevice); _joystick = new SenseHatJoystick(joystickAndLedMatrixI2cDevice); _gyro = new SenseHatAccelerometerAndGyroscope(_i2cBus.CreateDevice(SenseHatAccelerometerAndGyroscope.I2cAddress)); _mag = new SenseHatMagnetometer(_i2cBus.CreateDevice(SenseHatMagnetometer.I2cAddress)); _temp = new SenseHatTemperatureAndHumidity(_i2cBus.CreateDevice(SenseHatTemperatureAndHumidity.I2cAddress)); _press = new SenseHatPressureAndTemperature(_i2cBus.CreateDevice(SenseHatPressureAndTemperature.I2cAddress)); }
public static I2cBus CreateI2cBusForBme280() { return(I2cBus.Create(Bme280I2cBusId)); }
public static void Main(string[] args) { Console.WriteLine("Enter the device address:"); int expanderAddress = int.TryParse(Console.ReadLine(), out int address) ? address : GpioExpander.DefaultAddress; try { #if WIRING_PI Pi.Init <BootstrapWiringPi>(); _expander = Pi.I2C.GetGpioExpander(expanderAddress); #endif #if NOT_WIRING_PI _expander = I2cBus.Create(1).GetGpioExpander(expanderAddress); #endif } catch (Exception error) { Console.WriteLine($"Fail initialization GPIO Expander. Error: {error}"); return; } if (args.Length == 0) { Console.WriteLine("Select a mode:\n1. {0}\n2. {1}\n3. {2}\n4. {3}\n5. {4}\n6. {5}\n7. {6}\n", nameof(Analog1), nameof(Analog2), nameof(Digital), nameof(Port), nameof(Pwm), "Address/Reset", nameof(Adc)); switch (Console.ReadLine()) { case nameof(Analog1): { Analog1(); break; } case nameof(Analog2): { Analog2(); break; } case nameof(Digital): { Digital(); break; } case nameof(Port): { Port(); break; } case nameof(Pwm): { Pwm(); break; } case nameof(Adc): { Adc(); break; } case "Address": case "Reset": { AddressOrReset(); break; } default: { Console.WriteLine("Invalid program mode."); break; } } } else if (args[0].Equals("Freq", StringComparison.OrdinalIgnoreCase)) { FindFreq(); } else { Console.WriteLine("Invalid app mode."); } _expander?.Dispose(); Console.WriteLine("Application is shutting down..."); }
/// <inheritdoc /> protected override I2cBusManager CreateI2cBusCore(int busNumber, int[]?pins) { return(new I2cBusManager(this, busNumber, pins, I2cBus.Create(busNumber))); }