Example #1
0
        public override void ConvertImage(MagickImage image, double scale, PixelInterpolateMethod pixelInterpolate, DitherMode dither, BitMode bitMode)
        {
            Reset();

            Mode = bitMode;

            int[] size = Utils.LCDSizeToNum((LCDSize)Converter.Instance.LCDSizeSelection.SelectedItem);

            image.InterpolativeResize(size[1] * Y, size[0] * X, pixelInterpolate);

            image.Depth = bitMode == BitMode.Bit3 ? 3 : 5;
            image.Settings.Compression = CompressionMethod.NoCompression;

            if (dither == DitherMode.Riemersma || dither == DitherMode.FloydSteinberg || dither == DitherMode.None)
            {
                image.Quantize(new QuantizeSettings()
                {
                    Colors = bitMode == BitMode.Bit3 ? 8 : 32, DitherMethod = (DitherMethod)dither, ColorSpace = ColorSpace.sRGB, TreeDepth = 100
                });
            }
            else
            {
                image.Quantize(new QuantizeSettings()
                {
                    Colors = bitMode == BitMode.Bit3 ? 8 : 32, DitherMethod = DitherMethod.No, ColorSpace = ColorSpace.sRGB, TreeDepth = 100
                });
                image.OrderedDither(dither.ToString());
            }
        }
Example #2
0
 public static char ColorToChar(BitMode mode, byte r, byte g, byte b)
 {
     return(mode switch
     {
         BitMode.Bit3 => ColorToChar3Bit(r, g, b),
         BitMode.Bit5 => ColorToChar5Bit(r, g, b),
         _ => '0',
     });
Example #3
0
        /// <summary>
        ///     Construct a new HD44780-compatible display
        /// </summary>
        /// <param name="iface">The writable parallel interface to use</param>
        /// <param name="Columns">The number of columns in the display</param>
        /// <param name="Rows">The number of rows of the display</param>
        /// <param name="Backlight">The active-high pin to use for the backlight</param>
        /// <param name="font">The font mode to use</param>
        public Hd44780(WriteOnlyParallelInterface iface, int Columns, int Rows, DigitalOut Backlight = null,
                       FontMode font = FontMode.Font_5x8) : base(Columns, Rows)
        {
            if (iface.Width == 8)
            {
                bits = BitMode.EightBit;
            }
            else if (iface.Width == 4)
            {
                bits = BitMode.FourBit;
            }
            else
            {
                throw new ArgumentException("The IParallelInterface bus must be either 4 or 8 bits wide.", "iface");
            }

            if (Rows == 1)
            {
                lines = LinesMode.OneLine;
            }
            else
            {
                lines = LinesMode.TwoOrMoreLines;
            }

            this.font  = font;
            this.iface = iface;
            iface.DelayMicroseconds = 50;
            iface.Enabled           = true;
            byte cmd;

            if (bits == BitMode.FourBit)
            {
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x03 })).Wait();
                Task.Run(() => Task.Delay(10)).Wait();
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x03 })).Wait();
                Task.Run(() => Task.Delay(10)).Wait();
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x03 })).Wait();
                Task.Run(() => Task.Delay(10)).Wait();
                Task.Run(() => iface.WriteCommandAsync(new uint[] { 0x02 })).Wait();
            }


            cmd = (byte)((byte)Command.FunctionSet | (byte)bits | (byte)lines | (byte)font);
            Task.Run(() => writeCommand(cmd)).Wait();

            Display = true;
            Task.Run(Clear).Wait();

            if (Backlight != null)
            {
                backlight = Backlight;
                Task.Run(backlight.MakeDigitalPushPullOutAsync).Wait();
            }


            this.Backlight = true;
        }
        public void ConvertImage(MagickImage image)
        {
            double scale = ImageScaleSlider.Value;

            PixelInterpolateMethod method = (PixelInterpolateMethod)InterpolationSelection.SelectedItem;
            DitherMode             dither = (DitherMode)DitherModeSelection.SelectedItem;
            BitMode mode = (BitMode)BitModeSelection.SelectedItem;

            currentWindow?.ConvertImage(image, scale, method, dither, mode);
        }
Example #5
0
        private void m_comboBoxModebit_SelectedIndexChanged(object sender, EventArgs e)
        {
            int mode = m_comboBoxModebit.SelectedIndex;

            if (mode == 0)
            {
                ShowLog("Mode Change to Read");
                m_textBoxBitVal.ReadOnly = true;
                m_bitmode = BitMode.Read;
            }
            else if (mode == 1)
            {
                ShowLog("Mode Change to Write");
                m_textBoxBitVal.ReadOnly = false;
                m_bitmode = BitMode.Write;
            }
        }
Example #6
0
 private void SetBitMode(BitMode mode)
 {
     if (mode == BitMode.Bits5)
     {
         sentinel    = 0x0b;
         asciiOffset = 0x30;
         bits        = 5;
     }
     else
     {
         sentinel    = 0x45;
         asciiOffset = 0x20;
         bits        = 7;
     }
     symbolMask = (1 << bits) - 1;
     byteMask   = (1 << (bits - 1)) - 1;
     bitMode    = mode;
 }
Example #7
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        protected override async Task InitializeInternal(IDictionary <string, string> driverConfigurationValues)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            if (null == this.gpio)
            {
                throw new NullReferenceException();
            }

            try
            {
                int[] dataPinNumbers = null;

                if (driverConfigurationValues.ContainsKey("RsPin") &&
                    driverConfigurationValues.ContainsKey("EnablePin") &&
                    driverConfigurationValues.ContainsKey("D4Pin") &&
                    driverConfigurationValues.ContainsKey("D5Pin") &&
                    driverConfigurationValues.ContainsKey("D6Pin") &&
                    driverConfigurationValues.ContainsKey("D7Pin"))
                {
                    int rsPin     = Convert.ToInt32(driverConfigurationValues["RsPin"]);
                    int enablePin = Convert.ToInt32(driverConfigurationValues["EnablePin"]);
                    int d4Pin     = Convert.ToInt32(driverConfigurationValues["D4Pin"]);
                    int d5Pin     = Convert.ToInt32(driverConfigurationValues["D5Pin"]);
                    int d6Pin     = Convert.ToInt32(driverConfigurationValues["D6Pin"]);
                    int d7Pin     = Convert.ToInt32(driverConfigurationValues["D7Pin"]);

                    if (driverConfigurationValues.ContainsKey("D0Pin") &&
                        driverConfigurationValues.ContainsKey("D1Pin") &&
                        driverConfigurationValues.ContainsKey("D2Pin") &&
                        driverConfigurationValues.ContainsKey("D3Pin"))
                    {
                        dataPinNumbers = new int[8];

                        int d0Pin = Convert.ToInt32(driverConfigurationValues["D0Pin"]);
                        int d1Pin = Convert.ToInt32(driverConfigurationValues["D1Pin"]);
                        int d2Pin = Convert.ToInt32(driverConfigurationValues["D2Pin"]);
                        int d3Pin = Convert.ToInt32(driverConfigurationValues["D3Pin"]);

                        dataPinNumbers[0] = d0Pin;
                        dataPinNumbers[1] = d1Pin;
                        dataPinNumbers[2] = d2Pin;
                        dataPinNumbers[3] = d3Pin;
                        dataPinNumbers[4] = d4Pin;
                        dataPinNumbers[5] = d5Pin;
                        dataPinNumbers[6] = d6Pin;
                        dataPinNumbers[7] = d7Pin;

                        this.bitMode = BitMode.Eight;
                    }
                    else
                    {
                        dataPinNumbers = new int[4];

                        dataPinNumbers[0] = d4Pin;
                        dataPinNumbers[1] = d5Pin;
                        dataPinNumbers[2] = d6Pin;
                        dataPinNumbers[3] = d7Pin;

                        this.bitMode = BitMode.Four;
                    }

                    this.initializePins(enablePin, rsPin, dataPinNumbers);
                    await this.initializeChip();
                }
            }
            catch (FormatException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (OverflowException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (FileLoadException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin is already open");
            }
        }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        protected override async Task InitializeInternal(XElement configFragment)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            this.gpio = GpioController.GetDefault();

            if (null == this.gpio)
                throw new NullReferenceException();

            var rsPinElement = configFragment.Descendants("RsPin").FirstOrDefault();
            var enablePinElement = configFragment.Descendants("EnablePin").FirstOrDefault();
            var d0PinElement = configFragment.Descendants("D0Pin").FirstOrDefault();
            var d1PinElement = configFragment.Descendants("D1Pin").FirstOrDefault();
            var d2PinElement = configFragment.Descendants("D2Pin").FirstOrDefault();
            var d3PinElement = configFragment.Descendants("D3Pin").FirstOrDefault();
            var d4PinElement = configFragment.Descendants("D4Pin").FirstOrDefault();
            var d5PinElement = configFragment.Descendants("D5Pin").FirstOrDefault();
            var d6PinElement = configFragment.Descendants("D6Pin").FirstOrDefault();
            var d7PinElement = configFragment.Descendants("D7Pin").FirstOrDefault();

            try
            {
                int[] dataPinNumbers = null;

                if (null != rsPinElement &&
                null != enablePinElement &&
                null != d4PinElement &&
                null != d5PinElement &&
                null != d6PinElement &&
                null != d7PinElement)
                {
                    int rsPin = Convert.ToInt32(rsPinElement.Value);
                    int enablePin = Convert.ToInt32(enablePinElement.Value);
                    int d4Pin = Convert.ToInt32(d4PinElement.Value);
                    int d5Pin = Convert.ToInt32(d5PinElement.Value);
                    int d6Pin = Convert.ToInt32(d6PinElement.Value);
                    int d7Pin = Convert.ToInt32(d7PinElement.Value);

                    if (null != d0PinElement &&
                    null != d1PinElement &&
                    null != d2PinElement &&
                    null != d3PinElement)
                    {
                        dataPinNumbers = new int[8];

                        int d0Pin = Convert.ToInt32(d0PinElement.Value);
                        int d1Pin = Convert.ToInt32(d1PinElement.Value);
                        int d2Pin = Convert.ToInt32(d2PinElement.Value);
                        int d3Pin = Convert.ToInt32(d3PinElement.Value);

                        dataPinNumbers[0] = d0Pin;
                        dataPinNumbers[1] = d1Pin;
                        dataPinNumbers[2] = d2Pin;
                        dataPinNumbers[3] = d3Pin;
                        dataPinNumbers[4] = d4Pin;
                        dataPinNumbers[5] = d5Pin;
                        dataPinNumbers[6] = d6Pin;
                        dataPinNumbers[7] = d7Pin;

                        this.bitMode = BitMode.Eight;
                    }
                    else
                    {
                        dataPinNumbers = new int[4];

                        dataPinNumbers[0] = d4Pin;
                        dataPinNumbers[1] = d5Pin;
                        dataPinNumbers[2] = d6Pin;
                        dataPinNumbers[3] = d7Pin;

                        this.bitMode = BitMode.Four;
                    }

                    this.initializePins(enablePin, rsPin, dataPinNumbers);
                    await this.initializeChip();
                }
            }
            catch (FormatException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (OverflowException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (FileLoadException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin is already open");
            }
        }
Example #9
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        protected override async Task InitializeInternal(IDictionary<string, string> driverConfigurationValues)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            if (null == this.gpio)
                throw new NullReferenceException();

            try
            {
                int[] dataPinNumbers = null;

                if (driverConfigurationValues.ContainsKey("RsPin") &&
                driverConfigurationValues.ContainsKey("EnablePin") &&
                driverConfigurationValues.ContainsKey("D4Pin") &&
                driverConfigurationValues.ContainsKey("D5Pin") &&
                driverConfigurationValues.ContainsKey("D6Pin") &&
                driverConfigurationValues.ContainsKey("D7Pin"))
                {
                    int rsPin = Convert.ToInt32(driverConfigurationValues["RsPin"]);
                    int enablePin = Convert.ToInt32(driverConfigurationValues["EnablePin"]);
                    int d4Pin = Convert.ToInt32(driverConfigurationValues["D4Pin"]);
                    int d5Pin = Convert.ToInt32(driverConfigurationValues["D5Pin"]);
                    int d6Pin = Convert.ToInt32(driverConfigurationValues["D6Pin"]);
                    int d7Pin = Convert.ToInt32(driverConfigurationValues["D7Pin"]);

                    if (driverConfigurationValues.ContainsKey("D0Pin") &&
                    driverConfigurationValues.ContainsKey("D1Pin") &&
                    driverConfigurationValues.ContainsKey("D2Pin") &&
                    driverConfigurationValues.ContainsKey("D3Pin"))
                    {
                        dataPinNumbers = new int[8];

                        int d0Pin = Convert.ToInt32(driverConfigurationValues["D0Pin"]);
                        int d1Pin = Convert.ToInt32(driverConfigurationValues["D1Pin"]);
                        int d2Pin = Convert.ToInt32(driverConfigurationValues["D2Pin"]);
                        int d3Pin = Convert.ToInt32(driverConfigurationValues["D3Pin"]);

                        dataPinNumbers[0] = d0Pin;
                        dataPinNumbers[1] = d1Pin;
                        dataPinNumbers[2] = d2Pin;
                        dataPinNumbers[3] = d3Pin;
                        dataPinNumbers[4] = d4Pin;
                        dataPinNumbers[5] = d5Pin;
                        dataPinNumbers[6] = d6Pin;
                        dataPinNumbers[7] = d7Pin;

                        this.bitMode = BitMode.Eight;
                    }
                    else
                    {
                        dataPinNumbers = new int[4];

                        dataPinNumbers[0] = d4Pin;
                        dataPinNumbers[1] = d5Pin;
                        dataPinNumbers[2] = d6Pin;
                        dataPinNumbers[3] = d7Pin;

                        this.bitMode = BitMode.Four;
                    }

                    this.initializePins(enablePin, rsPin, dataPinNumbers);
                    await this.initializeChip();
                }
            }
            catch (FormatException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (OverflowException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (FileLoadException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin is already open");
            }
        }
Example #10
0
 protected CharacterDisplayDriver(BitMode bitMode)
 {
     _bitMode = bitMode;
 }
Example #11
0
        public virtual void ConvertImage(MagickImage image, double scale, PixelInterpolateMethod pixelInterpolate, DitherMode dither, BitMode bitMode)
        {
            image.InterpolativeResize(Math.Max(1, (int)(image.Width * scale)), Math.Max(1, (int)(image.Height * scale)), pixelInterpolate);

            if (dither == DitherMode.Riemersma || dither == DitherMode.FloydSteinberg || dither == DitherMode.None)
            {
                image.Quantize(new QuantizeSettings()
                {
                    DitherMethod = (DitherMethod)dither,
                    Colors       = 256,
                    ColorSpace   = ColorSpace.sRGB,
                    TreeDepth    = 100
                });
            }
            else
            {
                image.OrderedDither(dither.ToString());
            }
        }
Example #12
0
        private static byte[] KeySchedule(byte[] key, BitMode mode)
        {
            int n = mode == BitMode.Bit128 ? 16 : mode == BitMode.Bit192 ? 24 : 32;
            int b = mode == BitMode.Bit128 ? 176 : mode == BitMode.Bit192 ? 208 : 240;

            byte[] output = new byte[b];
            Array.Copy(key, output, n);

            int rcon_iter = 1;

            int accruedBytes = n;

            while (accruedBytes < b)
            {
                // Generate 4 new bytes of extended key
                byte[] t = Support.WriteToArray(new byte[4], KSchedCore((uint)Support.ReadInt(output, accruedBytes - 4), rcon_iter), 0);
                ++rcon_iter;
                for (int i = 0; i < 4; ++i)
                {
                    t[i] ^= output[accruedBytes - n + i];
                }
                Array.Copy(t, 0, output, accruedBytes, 4);
                accruedBytes += 4;

                // Generate 12 new bytes of extended key
                for (int i = 0; i < 3; ++i)
                {
                    Array.Copy(output, accruedBytes - 4, t, 0, 4);
                    for (int j = 0; j < 4; ++j)
                    {
                        t[j] ^= output[accruedBytes - n + j];
                    }
                    Array.Copy(t, 0, output, accruedBytes, 4);
                    accruedBytes += 4;
                }

                // Special processing for 256-bit key schedule
                if (mode == BitMode.Bit256)
                {
                    Array.Copy(output, accruedBytes - 4, t, 0, 4);
                    for (int j = 0; j < 4; ++j)
                    {
                        t[j] = (byte)(SBox(t[j]) ^ output[accruedBytes - n + j]);
                    }
                    Array.Copy(t, 0, output, accruedBytes, 4);
                    accruedBytes += 4;
                }
                // Special processing for 192-bit key schedule
                if (mode != BitMode.Bit128)
                {
                    for (int i = mode == BitMode.Bit192 ? 1 : 2; i >= 0; --i)
                    {
                        Array.Copy(output, accruedBytes - 4, t, 0, 4);
                        for (int j = 0; j < 4; ++j)
                        {
                            t[j] ^= output[accruedBytes - n + j];
                        }
                        Array.Copy(t, 0, output, accruedBytes, 4);
                        accruedBytes += 4;
                    }
                }
            }

            return(output);
        }
 public static string MagickImageToText(BitMode b)
 {
     return(null);
 }
Example #14
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        protected override async Task InitializeInternal(XElement configFragment)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            this.gpio = GpioController.GetDefault();

            if (null == this.gpio)
            {
                throw new NullReferenceException();
            }

            var rsPinElement     = configFragment.Descendants("RsPin").FirstOrDefault();
            var enablePinElement = configFragment.Descendants("EnablePin").FirstOrDefault();
            var d0PinElement     = configFragment.Descendants("D0Pin").FirstOrDefault();
            var d1PinElement     = configFragment.Descendants("D1Pin").FirstOrDefault();
            var d2PinElement     = configFragment.Descendants("D2Pin").FirstOrDefault();
            var d3PinElement     = configFragment.Descendants("D3Pin").FirstOrDefault();
            var d4PinElement     = configFragment.Descendants("D4Pin").FirstOrDefault();
            var d5PinElement     = configFragment.Descendants("D5Pin").FirstOrDefault();
            var d6PinElement     = configFragment.Descendants("D6Pin").FirstOrDefault();
            var d7PinElement     = configFragment.Descendants("D7Pin").FirstOrDefault();

            try
            {
                int[] dataPinNumbers = null;

                if (null != rsPinElement &&
                    null != enablePinElement &&
                    null != d4PinElement &&
                    null != d5PinElement &&
                    null != d6PinElement &&
                    null != d7PinElement)
                {
                    int rsPin     = Convert.ToInt32(rsPinElement.Value);
                    int enablePin = Convert.ToInt32(enablePinElement.Value);
                    int d4Pin     = Convert.ToInt32(d4PinElement.Value);
                    int d5Pin     = Convert.ToInt32(d5PinElement.Value);
                    int d6Pin     = Convert.ToInt32(d6PinElement.Value);
                    int d7Pin     = Convert.ToInt32(d7PinElement.Value);

                    if (null != d0PinElement &&
                        null != d1PinElement &&
                        null != d2PinElement &&
                        null != d3PinElement)
                    {
                        dataPinNumbers = new int[8];

                        int d0Pin = Convert.ToInt32(d0PinElement.Value);
                        int d1Pin = Convert.ToInt32(d1PinElement.Value);
                        int d2Pin = Convert.ToInt32(d2PinElement.Value);
                        int d3Pin = Convert.ToInt32(d3PinElement.Value);

                        dataPinNumbers[0] = d0Pin;
                        dataPinNumbers[1] = d1Pin;
                        dataPinNumbers[2] = d2Pin;
                        dataPinNumbers[3] = d3Pin;
                        dataPinNumbers[4] = d4Pin;
                        dataPinNumbers[5] = d5Pin;
                        dataPinNumbers[6] = d6Pin;
                        dataPinNumbers[7] = d7Pin;

                        this.bitMode = BitMode.Eight;
                    }
                    else
                    {
                        dataPinNumbers = new int[4];

                        dataPinNumbers[0] = d4Pin;
                        dataPinNumbers[1] = d5Pin;
                        dataPinNumbers[2] = d6Pin;
                        dataPinNumbers[3] = d7Pin;

                        this.bitMode = BitMode.Four;
                    }

                    this.initializePins(enablePin, rsPin, dataPinNumbers);
                    await this.initializeChip();
                }
            }
            catch (FormatException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (OverflowException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin config is invalid");
            }
            catch (FileLoadException)
            {
                Debug.WriteLine("HD44780GpioDriver: Pin is already open");
            }
        }
        /// <summary>
        /// Construct a new HD44780-compatible display
        /// </summary>
        /// <param name="iface">The writable parallel interface to use</param>
        /// <param name="Columns">The number of columns in the display</param>
        /// <param name="Rows">The number of rows of the display</param>
        /// <param name="Backlight">The active-high pin to use for the backlight</param>
        /// <param name="font">The font mode to use</param>
        public Hd44780(WriteOnlyParallelInterface iface, int Columns, int Rows, DigitalOutPin Backlight = null, FontMode font = FontMode.Font_5x8) : base(Columns, Rows)
        {
            if (iface.Width == 8)
                this.bits = BitMode.EightBit;
            else if (iface.Width == 4)
                this.bits = BitMode.FourBit;
            else
                throw new ArgumentException("The IParallelInterface bus must be either 4 or 8 bits wide.", "iface");

            if (Rows == 1)
                this.lines = LinesMode.OneLine;
            else
                this.lines = LinesMode.TwoOrMoreLines;

            this.font = font;
            this.iface = iface;
            iface.DelayMicroseconds = 50;
            iface.Enabled = true;
            byte cmd;

            if (bits == BitMode.FourBit)
            {
                iface.WriteCommand(new uint[] { 0x03 }).Wait();
                Task.Delay(10).Wait();
                iface.WriteCommand(new uint[] { 0x03 }).Wait();
                Task.Delay(10).Wait();
                iface.WriteCommand(new uint[] { 0x03 }).Wait();
                Task.Delay(10).Wait();
                iface.WriteCommand(new uint[] { 0x02 }).Wait();
            }


            cmd = (byte)((byte)Command.FunctionSet | (byte)bits | (byte)lines | (byte)font);
            writeCommand(cmd).Wait();

            Display = true;
            Clear().Wait();

            if (Backlight != null)
            {
                this.backlight = Backlight;
                backlight.MakeDigitalPushPullOut();
            }


            this.Backlight = true;
        }