Example #1
0
        /// <summary>
        /// This demonstrates the use of a large font on a 20x4 display. This is useful especially when showing values that should be readable from farther away,
        /// such as the time, or a temperature.
        /// </summary>
        /// <param name="lcd">The display</param>
        public static void LargeValueDemo(Hd44780 lcd)
        {
            LcdValueUnitDisplay value = new LcdValueUnitDisplay(lcd, CultureInfo.CurrentCulture);

            value.InitForRom("A00");
            value.Clear();
            Console.WriteLine("Big clock test");
            while (!Console.KeyAvailable)
            {
                value.DisplayTime(DateTime.Now, "T");
                Thread.Sleep(200);
            }

            Console.ReadKey(true);
            Console.WriteLine("Showing fake temperature");
            value.DisplayValue("24.2 °C", "Temperature");
            Console.ReadKey(true);

            Console.WriteLine("Now showing a text");
            CancellationTokenSource src = new CancellationTokenSource();

            value.DisplayBigTextAsync("The quick brown fox jumps over the lazy dog at 10.45PM on May, 3rd", TimeSpan.FromSeconds(0.5), src.Token);
            Console.ReadKey(true);
            src.Cancel();
        }
Example #2
0
        public void UseWithoutInitializationThrows()
        {
            _displayMock.Setup(x => x.Size).Returns(new Size(20, 4));
            _displayMock.Setup(x => x.NumberOfCustomCharactersSupported).Returns(8);
            LcdValueUnitDisplay display = new LcdValueUnitDisplay(_displayMock.Object, CultureInfo.InvariantCulture);
            DateTime            time    = new DateTime(2020, 5, 3, 21, 35, 10);

            Assert.Throws <InvalidOperationException>(() => display.DisplayTime(time));
        }
Example #3
0
        public void LargeValueDisplayInitializes()
        {
            int numChars = 0;

            _displayMock.Setup(x => x.Size).Returns(new Size(20, 4));
            _displayMock.Setup(x => x.NumberOfCustomCharactersSupported).Returns(8);
            _displayMock.Setup(x => x.CreateCustomCharacter(It.IsAny <int>(), It.Is <byte[]>(y => y.Length == 8))).Callback(() => numChars++);
            _displayMock.SetupSet(x => x.BlinkingCursorVisible  = false);
            _displayMock.SetupSet(x => x.UnderlineCursorVisible = false);
            _displayMock.SetupSet(x => x.BacklightOn            = true);
            _displayMock.SetupSet(x => x.DisplayOn = true);
            _displayMock.Setup(x => x.Clear());
            LcdValueUnitDisplay display = new LcdValueUnitDisplay(_displayMock.Object, CultureInfo.InvariantCulture);

            // This would throw in case the character map was not available
            display.InitForRom("A00");
            Assert.Equal(7, numChars);
        }
Example #4
0
        public void UseDisplay()
        {
            // this are the raw byte values that are sent to the display. Since we're really using byte positions 0-7, this looks a bit weird
            const string firstLine  = "\0\u0006\u0002 \0\u0006 \0\u0006\u0002\u0006\u0006\u0006       ";
            const string secondLine = " \0\u0003\0\u0003\u0006\u0007 \0\u0003\u0006         ";
            const string thirdLine  = "\0\u0003   \u0006\u0007 \u0001\u0002\u0005\u0005\u0002       ";
            const string fourthLine = "\u0006\u0006\u0003  \u0006 \u0001\u0006\u0003\u0001\u0006\u0003       ";

            // Enable this expectation to be able to see how things get printed (if the above needs updating)
            // const string testLine = "0:\0 1:\u0001 2:\u0002 3:\u0003 4:\u0004 5:\u0005 6:\u0006 7:\u0007 8:\u0008";
            // _displayMock.Setup(x => x.Write(testLine));
            Assert.Equal(20, firstLine.Length);
            Assert.Equal(20, secondLine.Length);
            Assert.Equal(20, thirdLine.Length);
            Assert.Equal(20, fourthLine.Length);
            _displayMock.Setup(x => x.Size).Returns(new Size(20, 4));
            _displayMock.Setup(x => x.NumberOfCustomCharactersSupported).Returns(8);
            _displayMock.Setup(x => x.CreateCustomCharacter(It.IsAny <int>(), It.Is <byte[]>(y => y.Length == 8)));
            _displayMock.SetupSet(x => x.BlinkingCursorVisible  = false);
            _displayMock.SetupSet(x => x.UnderlineCursorVisible = false);
            _displayMock.SetupSet(x => x.BacklightOn            = true);
            _displayMock.SetupSet(x => x.DisplayOn = true);
            _displayMock.Setup(x => x.Clear());
            LcdValueUnitDisplay display = new LcdValueUnitDisplay(_displayMock.Object, CultureInfo.InvariantCulture);

            display.InitForRom("A00");

            _displayMock.Setup(x => x.SetCursorPosition(0, 0));
            _displayMock.Setup(x => x.Write(firstLine));
            _displayMock.Setup(x => x.SetCursorPosition(0, 1));
            _displayMock.Setup(x => x.Write(secondLine));
            _displayMock.Setup(x => x.SetCursorPosition(0, 2));
            _displayMock.Setup(x => x.Write(thirdLine));
            _displayMock.Setup(x => x.SetCursorPosition(0, 3));
            _displayMock.Setup(x => x.Write(fourthLine));
            DateTime time = new DateTime(2020, 5, 3, 21, 35, 10);

            display.DisplayTime(time);
        }