Created
December 4, 2019 03:32
-
-
Save adrianstevens/eb29073f9cf2c2e8ead00d9d0b40a9e8 to your computer and use it in GitHub Desktop.
Example of accessing the static Device class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Meadow.Foundation; | |
using Meadow.Foundation.Displays.Tft; | |
using Meadow.Foundation.Graphics; | |
using Meadow.Hardware; | |
namespace Therm | |
{ | |
/// <summary> | |
/// This controller is in charge of the physical display, including rendering. | |
/// | |
/// It's also wired up to handle input on the display in the future that may | |
/// change the desired climate. | |
/// </summary> | |
public class DisplayController | |
{ | |
.... | |
// internals | |
protected ISpiBus _spiBus; | |
protected ST7789 _display; | |
protected GraphicsLibrary _graphics; | |
public DisplayController() | |
{ | |
InitializeDisplay(); | |
} | |
/// <summary> | |
/// intializes the physical display peripheral, as well as the backing | |
/// graphics library. | |
/// </summary> | |
protected void InitializeDisplay() | |
{ | |
// our display needs mode3 | |
var spiConfig = new SpiClockConfiguration( | |
6000, | |
SpiClockConfiguration.Mode.Mode3); | |
// initialize our SPI bus, with that config | |
_spiBus = ThermApp.Device.CreateSpiBus( | |
IOMap.DisplaySpiClock.Item2, | |
IOMap.DisplayMosi.Item2, | |
IOMap.DisplayMiso.Item2, | |
spiConfig); | |
// new up the actual display on the SPI bus | |
_display = new ST7789( | |
device: ThermApp.Device, | |
spiBus: _spiBus, | |
chipSelectPin: null, | |
dcPin: IOMap.DisplayDCPin.Item2, | |
resetPin: IOMap.DisplayResetPin.Item2, | |
width: 240, height: 240); | |
// create our graphics surface that we'll draw onto and then blit | |
// to the display with. | |
_graphics = new GraphicsLibrary(_display); | |
// my display is upside down | |
_graphics.CurrentRotation = GraphicsLibrary.Rotation._180Degrees; | |
Console.WriteLine("Clear display"); | |
// finally, clear the display so it's ready for action | |
_graphics.Clear(true); | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment