Exemplo n.º 1
0
        public override string Part1(string input)
        {
            var lines = input.Lines();

            return(lines.Select(x => SevenSegmentDisplay.CountUniques(x.Split(" | ")[1]))
                   .Sum().ToString());
        }
        public void TestCharacters(char character, string expected)
        {
            //arrange
            var center       = new StubPinInterface(1);
            var upperLeft    = new StubPinInterface(2);
            var top          = new StubPinInterface(3);
            var upperRight   = new StubPinInterface(4);
            var lowerLeft    = new StubPinInterface(5);
            var bottom       = new StubPinInterface(6);
            var lowerRight   = new StubPinInterface(7);
            var decimalPoint = new StubPinInterface(8);
            var display      = new SevenSegmentDisplay(center, upperLeft, top, upperRight, lowerLeft, bottom, lowerRight, decimalPoint);

            //act
            display.Show(character);

            //assert
            Assert.Equal(expected[1] == '*' ? PowerValue.On : PowerValue.Off, top.Power);
            Assert.Equal(expected[3] == '*' ? PowerValue.On : PowerValue.Off, upperLeft.Power);
            Assert.Equal(expected[5] == '*' ? PowerValue.On : PowerValue.Off, upperRight.Power);
            Assert.Equal(expected[7] == '*' ? PowerValue.On : PowerValue.Off, center.Power);
            Assert.Equal(expected[9] == '*' ? PowerValue.On : PowerValue.Off, lowerLeft.Power);
            Assert.Equal(expected[11] == '*' ? PowerValue.On : PowerValue.Off, lowerRight.Power);
            Assert.Equal(expected[13] == '*' ? PowerValue.On : PowerValue.Off, bottom.Power);

            if (expected.Length > 15)
            {
                Assert.Equal(expected[15] == '*' ? PowerValue.On : PowerValue.Off, decimalPoint.Power);
            }
        }
Exemplo n.º 3
0
        private void executeAddSevenSegmentDisplay(object o)
        {
            SevenSegmentDisplay sevenSegmentDisplay = new SevenSegmentDisplay();

            sevenSegmentDisplay.setOwner(this);
            SevenSegmentDisplayList.Add(sevenSegmentDisplay);
        }
Exemplo n.º 4
0
    public void TestCharacters(char character, string expected)
    {
        //arrange
        var segments = new SevenSegmentDisplay.PinSet
        {
            Center     = new PinStub(1),
            UpperLeft  = new PinStub(2),
            Top        = new PinStub(3),
            UpperRight = new PinStub(4),
            LowerLeft  = new PinStub(5),
            Bottom     = new PinStub(6),
            LowerRight = new PinStub(7),
            Decimal    = new PinStub(8)
        };
        var display = new SevenSegmentDisplay(segments);

        //act
        display.Show(character);

        //assert
        Assert.Equal(expected[1] == '*' ? PowerValue.On : PowerValue.Off, segments.Top.Power);
        Assert.Equal(expected[3] == '*' ? PowerValue.On : PowerValue.Off, segments.UpperLeft.Power);
        Assert.Equal(expected[5] == '*' ? PowerValue.On : PowerValue.Off, segments.UpperRight.Power);
        Assert.Equal(expected[7] == '*' ? PowerValue.On : PowerValue.Off, segments.Center.Power);
        Assert.Equal(expected[9] == '*' ? PowerValue.On : PowerValue.Off, segments.LowerLeft.Power);
        Assert.Equal(expected[11] == '*' ? PowerValue.On : PowerValue.Off, segments.LowerRight.Power);
        Assert.Equal(expected[13] == '*' ? PowerValue.On : PowerValue.Off, segments.Bottom.Power);

        if (expected.Length > 15)
        {
            Assert.Equal(expected[15] == '*' ? PowerValue.On : PowerValue.Off, segments.Decimal.Power);
        }
    }
Exemplo n.º 5
0
        static void Painter_Starting(object sender, EventArgs e)
        {
            paintBuffer       = ConsoleBuffer.CreateScreenBuffer();
            display           = new SevenSegmentDisplay(new Point(Console.BufferWidth - 1, 1), 6, 0);
            display.ForeBrush = new HorizontalStripeBufferBrush(1, BufferColor.Green, BufferColor.DarkGreen);
            display.BackBrush = SolidBufferBrush.Black;

            fpsThread = new Thread(FPSUpdateThread);
            fpsThread.Start();
        }
Exemplo n.º 6
0
        static async Task App()
        {
            var board = await ConnectionService.Instance.GetFirstDeviceAsync();

            await board.ConnectAsync();

            var controller = new Tm1650(board.I2c);
            var display    = new SevenSegmentDisplay(controller.Leds);

            display.Text = 2345;
        }
Exemplo n.º 7
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        SevenSegmentDisplay display = (SevenSegmentDisplay)target;

        if (GUILayout.Button("Increment"))
        {
            display.Increment();
        }
        if (GUILayout.Button("Decrement"))
        {
            display.Decrement();
        }
    }
Exemplo n.º 8
0
        public override string Part2(string input)
        {
            var lines = input.Lines();

            var total = 0;

            foreach (var line in lines)
            {
                var io = line.Split(" | ");

                var display = new SevenSegmentDisplay(io[0]);

                total += display.GetDisplay(io[1]);
            }

            return(total.ToString());
        }
Exemplo n.º 9
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();  // get the deferral handle

            int count = 0;

            MAX7219             driver = new MAX7219(2);
            SevenSegmentDisplay ssd    = new SevenSegmentDisplay(driver);
            BMP180 bmp = new BMP180(BMP180.Mode.HIGHRES);

            ssd.FrameClear();
            ssd.FrameDraw();
            ssd.SetBrightness(4);

            while (true)
            {
                temperature = bmp.Temperature.DegreesCelsius;

                data.Clear();

                // is temperature less than 3 digits and there is a decimal part too then right pad to 5 places as decimal point does not take up a digit space on the display
                if (temperature < 100 && temperature != (int)temperature)
                {
                    data.Append($"{Math.Round(temperature, 1)}C".PadRight(5));
                }
                else
                {
                    data.Append($"{Math.Round(temperature, 0)}C".PadRight(4));
                }

                data.Append(Math.Round(bmp.Pressure.Hectopascals, 0));

                if (blink = !blink)
                {
                    data.Append(".");
                }                                          // add a blinking dot on bottom right as an I'm alive indicator

                ssd.DrawString(data.ToString());

                ssd.DrawString(count++, 1);

                ssd.FrameDraw();

                Task.Delay(2000).Wait();
            }
        }
Exemplo n.º 10
0
    protected override void OnPaint(PaintEventArgs pea)
    {
        SevenSegmentDisplay ssd = new SevenSegmentDisplay(pea.Graphics);

        string strTime = dt.ToString("T",
                                     DateTimeFormatInfo.InvariantInfo);
        SizeF sizef  = ssd.MeasureString(strTime, Font);
        float fScale = Math.Min(ClientSize.Width / sizef.Width,
                                ClientSize.Height / sizef.Height);
        Font font = new Font(Font.FontFamily,
                             fScale * Font.SizeInPoints);

        sizef = ssd.MeasureString(strTime, font);

        ssd.DrawString(strTime, font, Brushes.Red,
                       (ClientSize.Width - sizef.Width) / 2,
                       (ClientSize.Height - sizef.Height) / 2);
    }
Exemplo n.º 11
0
        private async Task InitDisplay()
        {
            /* Initialize the display */
            try
            {
                var driver = new MAX7219(2);
                ssd = new SevenSegmentDisplay(driver);
                ssd.FrameClear();
                ssd.FrameDraw();
                ssd.SetBrightness(10);

                await SerialWriteAsync("Starting...");
            }
            catch (Exception ex)
            {
                throw new Exception("Display Initialization Failed", ex);
            }
        }
Exemplo n.º 12
0
        static async Task App()
        {
            var board = await ConnectionService.Instance.GetFirstDeviceAsync();

            await board.ConnectAsync();

            var controller = new Max7219(board.Spi, board.Pins[7]);
            var display    = new SevenSegmentDisplay(controller.Leds, true);

            int i = 0;

            while (!Console.KeyAvailable)
            {
                display.Text = i++;
                await Task.Delay(10);
            }

            board.Disconnect();
        }
        public async Task Test_DecodeRemainingDigits_Test(string file, int?expectedValue = null)
        {
            // Arrange
            var textLines = await File.ReadAllLinesAsync(file);

            var puzzleInput = textLines
                              .Where(line => !string.IsNullOrWhiteSpace(line))
                              .ToList();

            var sevenSegmentDisplay = new SevenSegmentDisplay(puzzleInput);

            // Act
            var calculation = sevenSegmentDisplay.DecodeRemainingDigits();

            // Assert
            if (expectedValue.HasValue)
            {
                Assert.AreEqual(expectedValue, calculation);
            }

            Debug.WriteLine(calculation);
        }