public void Disable() { this.IsEnabled = false; if (_encoder != null) { _encoder.Rotated -= HandlEncoderRotation; } else if (_buttonNext != null && _buttonPrevious != null) { _buttonPrevious.Clicked -= HandleButtonPrevious; _buttonNext.Clicked -= HandleButtonNext; } _buttonSelect.Clicked -= HandleEncoderClick; _display.Clear(); }
protected void UpdateInfoScreen() { // if we're in the menu, get out. if (_inMenu) { return; } _display.Clear(); _display.WriteLine("Super Coop 3000!", 0); _display.WriteLine("Current Temp: " + _tempSensor.Temperature.ToString("F1") + "C", 1); //_display.WriteLine("Target Temp: " + _targetTemp.ToString("F0") + "C", 2); _display.WriteLine("Click for more.", 3); }
protected void InitializePeripherals() { // display //_display = new Lcd2004(new MCP23008()); _display = new Lcd2004(N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D13); _display.Clear(); _display.WriteLine("Display up!", 0); // rotary encoder _encoder = new RotaryEncoderWithButton(N.Pins.GPIO_PIN_D4, N.Pins.GPIO_PIN_D5, N.Pins.GPIO_PIN_D7, CircuitTerminationType.CommonGround); // door stuff _doorServo = new ContinuousRotationServo(N.PWMChannels.PWM_PIN_D6, NamedServoConfigs.IdealContinuousRotationServo); _openEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D2, CircuitTerminationType.CommonGround); _closeEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D3, CircuitTerminationType.CommonGround); _display.WriteLine("Door stuff up!", 1); // temp stuff _heatLampRelay = new SoftPwm(N.Pins.GPIO_PIN_D0, 0, 1f / 60f); _tempSensor = new AnalogTemperature(N.AnalogChannels.ANALOG_PIN_A0, AnalogTemperature.KnownSensorType.LM35, updateInterval: 5000, temperatureChangeNotificationThreshold: 1.0f); _display.WriteLine("Temp stuff up!", 2); //==== now wire up all the peripheral events // Analog Temp Sensor. Setup to notify at half a degree changes _tempSensor.TemperatureChanged += (object sender, SensorFloatEventArgs e) => { _currentTemp = e.CurrentValue; Debug.Print("Current Temp: " + _currentTemp.ToString("N1")); UpdateInfoScreen(); }; _encoder.Clicked += (s, e) => { // if the menu isn't displayed, display it. otherwise // encoder click events are handled by menu if (!_inMenu) { this.DisplayMenu(); } }; Debug.Print("Peripherals initialized."); }
protected void RenderCurrentMenuPage() { // clear the display _display.Clear(); // if there are no items to render, get out. if (_currentMenuPage.MenuItems.Count <= 0) { return; } // if the scroll position is above the display area, move the display "window" if (_currentMenuPage.ScrollPosition < _topDisplayLine) { _topDisplayLine = _currentMenuPage.ScrollPosition; } // if the scroll position is below the display area, move the display "window" if (_currentMenuPage.ScrollPosition > _topDisplayLine + _display.DisplayConfig.Height - 1) { _topDisplayLine = _currentMenuPage.ScrollPosition - _display.DisplayConfig.Height + 1; } Debug.Print("Scroll: " + _currentMenuPage.ScrollPosition.ToString() + ", start: " + _topDisplayLine.ToString() + ", end: " + (_topDisplayLine + _display.DisplayConfig.Height - 1).ToString()); byte lineNumber = 0; for (int i = _topDisplayLine; i <= (_topDisplayLine + _display.DisplayConfig.Height - 1); i++) { if (i < _currentMenuPage.MenuItems.Count) { IMenuItem item = _currentMenuPage.MenuItems[i] as IMenuItem; // trim and add selection string lineText = GetItemText(item, (i == _currentMenuPage.ScrollPosition)); _display.WriteLine(lineText, lineNumber); lineNumber++; } } }
/// <summary> /// Configures the hardware perihperals (LCD, temp sensor, relays, etc.) /// so they can be used by the application. /// </summary> protected void InitializePeripherals() { // pushbutton (for testing) _pushButton = new PushButton( (H.Cpu.Pin) 0x15, CircuitTerminationType.Floating); // Rotary Encoder _encoder = new RotaryEncoderWithButton( N.Pins.GPIO_PIN_D7, N.Pins.GPIO_PIN_D6, N.Pins.GPIO_PIN_D5, CircuitTerminationType.CommonGround); // LCD //_display = new Lcd2004(new MCP23008()); _display = new Lcd2004(N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D13); _display.Clear(); Debug.Print("Display up."); _display.WriteLine("Display up!", 0); // Analog Temp Sensor. Setup to notify at half a degree changes _tempSensor = new AnalogTemperature(N.AnalogChannels.ANALOG_PIN_A0, AnalogTemperature.KnownSensorType.LM35, temperatureChangeNotificationThreshold: 0.5F); Debug.Print("TempSensor up."); _display.WriteLine("Temp Sensor up!", 1); // Heater driven by Software PWM _heaterRelayPwm = new SoftPwm(N.Pins.GPIO_PIN_D2, 0.5f, 1.0f / 30.0f); Debug.Print("Heater PWM up."); _display.WriteLine("Heater PWM up!", 2); // Fan Relay _fanRelay = new Relay(N.Pins.GPIO_PIN_D3); Debug.Print("Fan up."); _display.WriteLine("Fan up!", 3); // output status Debug.Print("Peripherals up"); _display.WriteLine("Peripherals online!", 0); }