Exemple #1
0
        public SenseHat()
        {
            InitSenseHat().Wait();

            // Recreate the font from the serialized bytes.
            font = SingleColorFont.Deserialize(FontBytes);
        }
Exemple #2
0
        protected override void Execute()
        {
            senseHat.Display.Clear();
            senseHat.Display.Fill(Colors.White);
            senseHat.Display.Direction = DisplayDirection.Deg90;

            var font              = SingleColorFont.Deserialize(FontBytes);
            var characters        = font.GetChars("The quick brown fox jumps over the lazy dog. Hello Raspberry Pi. ");
            var characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor);
            var textScroller      = new TextScroller <SingleColorCharacter>(senseHat.Display, characterRenderer, characters);

            while (!cancellationTokenSource.Token.IsCancellationRequested)
            {
                if (!textScroller.Step())
                {
                    textScroller.Reset();
                }

                senseHat.Display.Clear();

                textScroller.Render();

                senseHat.Display.Update();

                waitEvent.Wait(100);
            }
        }
Exemple #3
0
        private static void SingleColorTinyFontWork()
        {
            var          bitmap = new Bitmap(@"Font\TinyBWFont.png");
            const string chars  = " 0123456789ABCDEF+-%*=.:!?/\\'";

            SingleColorFont tinyFont = SingleColorFontBuilder.GetSingleColorFont(bitmap, chars);

            byte[] fontBytes       = tinyFont.Serialize().ToArray();
            var    fontBytesAsCode = ToCSharp(fontBytes);
        }
        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.
            SingleColorFont font = SingleColorFont.Deserialize(FontBytes);

            // Get the characters to scroll.
            IEnumerable <SingleColorCharacter> characters = font.GetChars(_scrollText);

            // Create the character renderer.
            SingleColorCharacterRenderer characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor);

            // Create the text scroller.
            var textScroller = new TextScroller <SingleColorCharacter>(
                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));
            }
        }
Exemple #5
0
        public SenseHat()
        {
            try
            {
                InitSenseHat().Wait();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            // Recreate the font from the serialized bytes.
            font = SingleColorFont.Deserialize(FontBytes);
        }
Exemple #6
0
        private static void SingleColorFontWork()
        {
            var          bitmap = new Bitmap(@"Font\BWFont.png");
            const string chars  = " ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖÉÜabcdefghijklmnopqrstuvwxyzåäöéü0123456789.,?!\"#$%&-+*:;/\\<>()'`=";

            SingleColorFont singleColorFont = SingleColorFontBuilder.GetSingleColorFont(bitmap, chars);

            byte[] fontBytes       = singleColorFont.Serialize().ToArray();
            var    fontBytesAsCode = ToCSharp(fontBytes);

            Tuple <string, Bitmap> tuple = SingleColorFontBuilder.GetFontBitmap(fontBytes);

            tuple.Item2.Save(@"Font\BWFont_recreated.png");
        }
		static TinyFont()
		{
			// These bytes are calculated by the RPi.SenseHat.Tools.
			// See the method "SingleColorTinyFontWork"!
			var fontBytes = new byte[]
			{
				0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x30, 0x00, 0x00, 0x1f, 0x11, 0x1f, 0xff, 0x00, 0x31, 0x00, 0x00,
				0x12, 0x1f, 0x10, 0xff, 0x00, 0x32, 0x00, 0x00, 0x1d, 0x15, 0x17, 0xff, 0x00, 0x33, 0x00, 0x00, 0x15, 0x15, 0x1f,
				0xff, 0x00, 0x34, 0x00, 0x00, 0x07, 0x04, 0x1f, 0xff, 0x00, 0x35, 0x00, 0x00, 0x17, 0x15, 0x1d, 0xff, 0x00, 0x36,
				0x00, 0x00, 0x1f, 0x15, 0x1c, 0xff, 0x00, 0x37, 0x00, 0x00, 0x01, 0x1d, 0x07, 0xff, 0x00, 0x38, 0x00, 0x00, 0x1f,
				0x15, 0x1f, 0xff, 0x00, 0x39, 0x00, 0x00, 0x07, 0x15, 0x1f, 0xff, 0x00, 0x41, 0x00, 0x00, 0x1e, 0x05, 0x1e, 0xff,
				0x00, 0x42, 0x00, 0x00, 0x1f, 0x15, 0x0a, 0xff, 0x00, 0x43, 0x00, 0x00, 0x0e, 0x11, 0x11, 0xff, 0x00, 0x44, 0x00,
				0x00, 0x1f, 0x11, 0x0e, 0xff, 0x00, 0x45, 0x00, 0x00, 0x1f, 0x15, 0x11, 0xff, 0x00, 0x46, 0x00, 0x00, 0x1f, 0x05,
				0x01, 0xff, 0x00, 0x2b, 0x00, 0x00, 0x04, 0x0e, 0x04, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x04, 0x04, 0x04, 0xff, 0x00,
				0x25, 0x00, 0x00, 0x19, 0x04, 0x13, 0xff, 0x00, 0x2a, 0x00, 0x00, 0x15, 0x0e, 0x15, 0xff, 0x00, 0x3d, 0x00, 0x00,
				0x0a, 0x0a, 0x0a, 0xff, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x10, 0x00, 0xff, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x0a, 0x00,
				0xff, 0x00, 0x21, 0x00, 0x00, 0x00, 0x17, 0x00, 0xff, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x15, 0x07, 0xff, 0x00, 0x2f,
				0x00, 0x00, 0x18, 0x04, 0x03, 0xff, 0x00, 0x5c, 0x00, 0x00, 0x03, 0x04, 0x18, 0xff, 0x00, 0x27, 0x00, 0x00, 0x00,
				0x03, 0x00
			};

			Font = SingleColorFont.Deserialize(fontBytes);
		}
        private async void StartScrollInternal()
        {
            try
            {
                SenseHat = await SenseHatFactory.GetSenseHat();
            }
            catch { }

            if (SenseHat == null)
            {
                return;
            }

            SenseHat.Display.Direction = DisplayDirection.Deg270;

            // Get a copy of the rainbow colors.
            SenseHat.Display.Reset();
            SenseHat.Display.CopyScreenToColors(_rainbowColors);

            // Recreate the font from the serialized bytes.
            SingleColorFont font = SingleColorFont.Deserialize(FontBytes);

            // Get the characters to scroll.
            IEnumerable <SingleColorCharacter> characters = font.GetChars(_scrollText);

            // Create the character renderer.
            SingleColorCharacterRenderer characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor);

            // Create the text scroller.
            var textScroller = new TextScroller <SingleColorCharacter>(
                SenseHat.Display,
                characterRenderer,
                characters);

            while (true)
            {
                if (this.scrollTaskCancellationTokenSource.IsCancellationRequested)
                {
                    SenseHat.Display.Clear();
                    SenseHat.Display.Update();
                    break;
                }

                // 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();

                // Pause for a short while.
                await Task.Delay(TimeSpan.FromMilliseconds(50));
            }
        }
Exemple #9
0
        public async Task display()
        {
            try
            {
                _scrollText = "Device Bot - Azure IoT Hub";
                // Get a copy of the rainbow colors.
                senseHat = await SenseHatFactory.GetSenseHat();

                senseHat.Display.Reset();
                senseHat.Display.CopyScreenToColors(_rainbowColors);

                // Recreate the font from the serialized bytes.
                SingleColorFont font = SingleColorFont.Deserialize(FontBytes);

                // Get the characters to scroll.
                IEnumerable <SingleColorCharacter> characters = font.GetChars(_scrollText);

                // Create the character renderer.
                SingleColorCharacterRenderer characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor);

                // Create the text scroller.
                var textScroller = new TextScroller <SingleColorCharacter>(
                    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.
                    //Task.wait(TimeSpan.FromMilliseconds(50));
                    await Task.Delay(500);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }