public static int DrawProportionalText(this GraphicsLibrary graphicsLibrary, ProportionalFontBase fontBase, int x, int y, string text)
        {
            var totalWidth = fontBase.GetWidth(text);

            graphicsLibrary.DrawBitmap(x, y, totalWidth, fontBase.Height, fontBase.GetBitmapFromString(text), DisplayBase.BitmapMode.Copy);
            return(fontBase.GetWidth(text));
        }
Example #2
0
        public void ConfigurePorts()
        {
            Console.WriteLine("Creating Outputs...");
            this.redPwm = Device.CreatePwmPort(Device.Pins.OnboardLedRed, pwmFrequency, 0f);
            this.bluPwm = Device.CreatePwmPort(Device.Pins.OnboardLedBlue, pwmFrequency, 0f);
            this.grePwm = Device.CreatePwmPort(Device.Pins.OnboardLedGreen, pwmFrequency, 0f);

            var busForDisplay = Device.CreateI2cBus( ) as I2cBus;

            busForDisplay.Frequency = i2cFrequency;

            Console.WriteLine("I2C bus frequency: {0}", busForDisplay.Frequency);

            this.display = new Ssd1306(busForDisplay, 0x3C, Ssd1306.DisplayType.OLED128x32);
            this.display.SendUGdash2832HSWEG02Startup();
            this.display.InvertDisplay = true;
            this.display.Clear(true);

            this.chicagoFont = new ShikaakwaProportionalFont();
            this.cornerFont  = new CornerProportionalFont();

            var yPosition = 3;

            this.line1     = this.chicagoFont.GetBitmapFromString("Programmed in C#").ShiftLsbToMsb(yPosition);
            this.line1Page = 0;
            yPosition     += this.chicagoFont.Spacing;
            var shiftLineTwo = yPosition % 8;

            this.line2     = this.chicagoFont.GetBitmapFromString("by SupraBitKid").ShiftLsbToMsb(shiftLineTwo);
            this.line2Page = ( byte )(yPosition / 8);

            this.topLeftCorner     = this.cornerFont.GetCharacter('a');
            this.topRightCorner    = this.cornerFont.GetCharacter('b');
            this.bottomLeftCorner  = this.cornerFont.GetCharacter('c');
            this.bottomRightCorner = this.cornerFont.GetCharacter('d');

            this.redColorText   = this.chicagoFont.GetBitmapFromString("red").ShiftLsbToMsb(shiftLineTwo);
            this.greenColorText = this.chicagoFont.GetBitmapFromString("green").ShiftLsbToMsb(shiftLineTwo);
            this.blueColorText  = this.chicagoFont.GetBitmapFromString("blue").ShiftLsbToMsb(shiftLineTwo);

            this.display.Clear(false);
            this.display.DrawBitmap(0, 0, this.topLeftCorner, Ssd1306Extensions.BitmapOp.Or);
            this.display.DrawBitmap(( byte )(this.display.Width - this.topRightCorner.Width), 0, this.topRightCorner, Ssd1306Extensions.BitmapOp.Or);
            this.display.DrawBitmap(0, ( byte )(this.display.GetPageCount() - 1), this.bottomLeftCorner, Ssd1306Extensions.BitmapOp.Or);
            this.display.DrawBitmap(( byte )(this.display.Width - this.bottomRightCorner.Width),
                                    ( byte )(this.display.GetPageCount() - 1), this.bottomRightCorner, Ssd1306Extensions.BitmapOp.Or);
            this.display.DrawBitmap(6, this.line1Page, this.line1, Ssd1306Extensions.BitmapOp.Or);
            this.display.DrawBitmap(6, this.line2Page, this.line2, Ssd1306Extensions.BitmapOp.Or);
            this.display.Show();
        }