Ejemplo n.º 1
0
        /// <summary>
        /// Loads the specified encoding.
        /// This behaves as <see cref="LoadEncoding(LcdCharacterEncoding)"/> when the argument is of the dynamic type <see cref="LcdCharacterEncoding"/>, otherwise like an encding
        /// with no special characters.
        /// </summary>
        /// <param name="encoding">The encoding to load.</param>
        /// <returns>See true if the encoding was correctly loaded.</returns>
        public bool LoadEncoding(Encoding encoding)
        {
            LcdCharacterEncoding lcdCharacterEncoding = encoding as LcdCharacterEncoding;

            if (lcdCharacterEncoding != null)
            {
                return(LoadEncoding(encoding));
            }

            lock (_lock)
            {
                _characterEncoding = encoding;
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the character mapping optimized for the given culture.
        /// Checks whether the characters required for a given culture are available in the installed character map and tries
        /// to add them as user-defined characters, if possible.
        /// </summary>
        /// <param name="culture">Culture for which support is required</param>
        /// <param name="romName">ROM type of attached chip. Supported values: "A00", "A02", "SplC780"</param>
        /// <param name="unknownLetter">Letter that is printed when an unknown character is encountered. This letter must be part of the
        /// default rom set</param>
        /// <param name="maxNumberOfCustomCharacters">Maximum number of custom characters supported on the hardware. Should be 8 for Hd44780-controlled displays.</param>
        /// <returns>The newly created encoding. Whether the encoding can be loaded to a certain display will be decided later.</returns>
        /// <exception cref="ArgumentException">The character specified as unknownLetter must be part of the mapping.</exception>
        public LcdCharacterEncoding Create(CultureInfo culture, string romName, char unknownLetter, int maxNumberOfCustomCharacters)
        {
            if (culture == null)
            {
                throw new ArgumentNullException(nameof(culture));
            }

            Dictionary <char, byte> newMap;

            // Need to copy the static map, we must not update that
            switch (romName)
            {
            case "A00":
                newMap = new Dictionary <char, byte>(DefaultA00Map);
                break;

            case "A02":
                newMap = new Dictionary <char, byte>(DefaultA02Map);
                break;

            case "SplC780":
                newMap = new Dictionary <char, byte>(DefaultSplC780Map);
                break;

            default:
                newMap = new Dictionary <char, byte>(DefaultCustomMap);
                break;
            }

            List <byte[]> extraCharacters = new List <byte[]>();
            bool          supported       = AssignLettersForCurrentCulture(newMap, culture, romName, extraCharacters, maxNumberOfCustomCharacters);

            if (!newMap.ContainsKey(unknownLetter))
            {
                throw new ArgumentException("The replacement letter is not part of the mapping", nameof(unknownLetter));
            }

            var encoding = new LcdCharacterEncoding(culture.Name, romName, newMap, unknownLetter, extraCharacters);

            encoding.AllCharactersSupported = !supported;
            return(encoding);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the specified character encoding. This loads any custom characters from the encoding to the display.
        /// </summary>
        /// <param name="encoding">The encoding to load.</param>
        /// <returns>True if the character encoding was successfully loaded, false if there are not enough custom slots for all the required custom characters.
        /// This may also return false if the encoding factory returned incomplete results, such as a missing custom character for a special diacritic.</returns>
        public bool LoadEncoding(LcdCharacterEncoding encoding)
        {
            bool allCharactersLoaded = encoding.AllCharactersSupported;

            lock (_lock)
            {
                int numberOfCharctersToLoad = Math.Min(encoding.ExtraCharacters.Count, _lcd.NumberOfCustomCharactersSupported);
                if (numberOfCharctersToLoad < encoding.ExtraCharacters.Count)
                {
                    // We can't completelly load that encoding, because there are not enough custom slots.
                    allCharactersLoaded = false;
                }

                for (byte i = 0; i < numberOfCharctersToLoad; i++)
                {
                    byte[] pixelMap = encoding.ExtraCharacters[i];
                    _lcd.CreateCustomCharacter(i, pixelMap);
                }

                _characterEncoding = encoding;
            }

            return(allCharactersLoaded);
        }