// TODO: is loader button a thing? public Buttons() { //// the buttons are multiplexed so that the board can be woken up by user, or by the RTC //// so to get that interrupt to fire you need to do this: //// TODO: work out which buttons and why! _muxWakeButtonFlowControl = new GpioController().OpenPin(Pinout.GpioPin.MUX_EXT_BUTTON_WAKE_PE4); _muxWakeButtonFlowControl.SetPinMode(PinMode.Output); _muxWakeButtonFlowControl.Write(PinValue.High); //_muxWakeButtonFlowControl.ValueChanged += MuxWakeButtonFlowControl_ValueChanged; _userButton = new GpioButton(buttonPin: Pinout.GpioPin.BUTTON_USER_BOOT1_PK7); _userButton.Press += _userButton_Press; _wakeButton = new GpioButton(buttonPin: Pinout.GpioPin.BUTTON_WAKE_PA0); _wakeButton.Press += WakeButton_Press; _diagnosticButton = new GpioButton(buttonPin: Pinout.GpioPin.BUTTON_DIAGNOSTIC_PB7); _diagnosticButton.Press += DiagnosticButton_Press; }
public static void DisplayModes(ArduinoBoard board) { const int ButtonPin = 2; const int MaxMode = 10; Length stationAltitude = Length.FromMeters(650); int mode = 0; var gpioController = board.CreateGpioController(); GpioButton button = new GpioButton(ButtonPin, gpioController, false, PinMode.Input, TimeSpan.FromMilliseconds(200)); CharacterDisplay disp = new CharacterDisplay(board); Console.WriteLine("Display output test"); Console.WriteLine("The button on GPIO 2 changes modes"); Console.WriteLine("Press x to exit"); disp.Output.ScrollUpDelay = TimeSpan.FromMilliseconds(500); AutoResetEvent buttonClicked = new AutoResetEvent(false); void ChangeMode(object?sender, EventArgs pinValueChangedEventArgs) { mode++; if (mode > MaxMode) { // Don't change back to 0 mode = 1; } buttonClicked.Set(); } button.Press += ChangeMode; var device = board.CreateI2cDevice(new I2cConnectionSettings(0, Bmp280.DefaultI2cAddress)); Bmp280?bmp; try { bmp = new Bmp280(device); bmp.StandbyTime = StandbyTime.Ms250; bmp.SetPowerMode(Bmx280PowerMode.Normal); } catch (IOException) { bmp = null; Console.WriteLine("BMP280 not available"); } DhtSensor?dht = board.GetCommandHandler <DhtSensor>(); if (dht == null) { // Note that this is a software error, hardware support is not tested here. Console.WriteLine("DHT Sensor module missing"); return; } OpenHardwareMonitor hardwareMonitor = new OpenHardwareMonitor(); hardwareMonitor.EnableDerivedSensors(); TimeSpan sleeptime = TimeSpan.FromMilliseconds(500); string modeName = string.Empty; string previousModeName = string.Empty; int firstCharInText = 0; while (true) { if (Console.KeyAvailable && Console.ReadKey(true).KeyChar == 'x') { break; } // Default sleeptime = TimeSpan.FromMilliseconds(500); switch (mode) { case 0: modeName = "Display ready"; disp.Output.ReplaceLine(1, "Button for mode"); // Just text break; case 1: { modeName = "Time"; disp.Output.ReplaceLine(1, DateTime.Now.ToLongTimeString()); sleeptime = TimeSpan.FromMilliseconds(200); break; } case 2: { modeName = "Date"; disp.Output.ReplaceLine(1, DateTime.Now.ToShortDateString()); break; } case 3: modeName = "Temperature / Barometric Pressure"; if (bmp != null && bmp.TryReadTemperature(out Temperature temp) && bmp.TryReadPressure(out Pressure p2)) { Pressure p3 = WeatherHelper.CalculateBarometricPressure(p2, temp, stationAltitude); disp.Output.ReplaceLine(1, string.Format(CultureInfo.CurrentCulture, "{0:s1} {1:s1}", temp, p3)); }