public async Task initSenseHat() { // Create sensehat object senseHat = await SenseHatFactory.Singleton.Create(); // Init font tinyFont = new TinyFont(); // Init display display = senseHat.Display; // Get a copy of the rainbow colors. senseHat.Display.Reset(); // Recreate the font from the serialized bytes. BwFont font = BwFont.Deserialize(FontBytes); // Get the characters to scroll. IEnumerable<BwCharacter> characters = font.GetChars("Error"); // Create the character renderer. BwCharacterRenderer characterRenderer = new BwCharacterRenderer(GetCharacterColor); // Create the text scroller. textScroller = new TextScroller<BwCharacter>(senseHat.Display, characterRenderer, characters); // Update forecast for first time getWeather(currentCity); // Check joystick every 100 ms joystickPollTimer = ThreadPoolTimer.CreatePeriodicTimer(pollJoystick, TimeSpan.FromMilliseconds(50)); // Check sensor every 2 s updateSensorsTimer = ThreadPoolTimer.CreatePeriodicTimer(updateSensors, TimeSpan.FromSeconds(2)); // Get updated weather every 1 minute forecastUpdateTimer = ThreadPoolTimer.CreatePeriodicTimer(updateForecast, TimeSpan.FromMinutes(1)); }
public override void Run() { // Get a copy of the rainbow colors. SenseHat.Display.Reset(); SenseHat.Display.CopyScreenToColors(_rainbowColors); // Recreate the font from the serialized bytes. BwFont font = BwFont.Deserialize(FontBytes); // Get the characters to scroll. IEnumerable<BwCharacter> characters = font.GetChars(_scrollText); // Create the character renderer. BwCharacterRenderer characterRenderer = new BwCharacterRenderer(GetCharacterColor); // Create the text scroller. var textScroller = new TextScroller<BwCharacter>( SenseHat.Display, characterRenderer, characters); while (true) { // Step the scroller. if (!textScroller.Step()) { // Reset the scroller when reaching the end. textScroller.Reset(); } // Draw the background. FillDisplay(textScroller.ScrollPixelOffset); // Draw the scroll text. textScroller.Render(); // Update the physical display. SenseHat.Display.Update(); // Should the drawing mode change? if (SenseHat.Joystick.Update() && (SenseHat.Joystick.EnterKey == KeyState.Pressing)) { // The middle button is just pressed. SwitchToNextScrollMode(); } // Pause for a short while. Sleep(TimeSpan.FromMilliseconds(50)); } }
public void Write(ISenseHatDisplay display, string twoCharText, Color color, int offsetY = 0) { BwCharacter[] chars = Font.GetChars(twoCharText).ToArray(); if (chars.Length == 0) { return; } if (chars.Length > 2) { throw new ArgumentException("Max two characters are allowed!", nameof(twoCharText)); } var characterRenderer = new BwCharacterRenderer(pixelMap => color); int x = 0; foreach (BwCharacter character in chars) { characterRenderer.Render(display, character, x, offsetY); x += 4; } }