/// <summary> /// This method takes a string with each char (byte) representing the locations of active /// on a CyCustomCharacterArray. /// </summary> /// <param name="customCharacter"> The instance of a character to be updated from CyDesigner data.</param> /// <param name="cyParameterString"> The string representing byte array from CyDesigner.</param> public void CyParameterToCustomCharacter(CyCustomCharacter customCharacter, string cyParameterString) { char[] chars = new char[customCharacter.Rows]; int index = 0; // Remove last comma and seperate into indivudual strings. string[] hexCharacterArray = cyParameterString.TrimEnd(',').Split(','); for (int i = 0; i < hexCharacterArray.Length; i++) { chars[index++] = (char)byte.Parse(hexCharacterArray[i], System.Globalization.NumberStyles.HexNumber); } CharLCDmp_v1_1.CyBox[,] boxes = customCharacter.GetBoxArray(); for (int row = 0; row < customCharacter.Rows; row++) { for (int column = 0; column < customCharacter.Columns; column++) { if ((((byte)chars[row]) & getExponent(customCharacter.Columns - 1 - column)) != 0) { boxes[row, column].IsActive = true; } } } }
/// <summary> /// This method takes a user defined custom character and converts the locations of active /// pixels to an array of bytes, cast into a string to be stored on the LCD component object in CyDesigner. /// </summary> /// <param name="customCharacter"> The string representing byte array from CyDesigner.</param> public string CharacterToCYString(CyCustomCharacter customCharacter) { // Comma Seperated String of Hex Values string cyCharacterString = ""; CharLCDmp_v1_1.CyBox[,] pixelArray = customCharacter.GetBoxArray(); // Indivudual row value to be calculated byte rowValue; for (int row = 0; row < customCharacter.Rows; row++) { rowValue = 0; for (int column = 0; column < customCharacter.Columns; column++) { if (pixelArray[row, column].IsActive) { // If active find out which pixel it is. The 0th is the furthest right // and has a value of 1. 'customCharacter.Columns - 1' is the furthest left // and has a value of 2^(customCharacter.Columns -1). Values in between are // Exponential powers of 2 based on position. rowValue += (byte)getExponent(customCharacter.Columns - 1 - column); } } cyCharacterString += rowValue.ToString("X") + ","; } // Convert Char arry to string and return it. return(cyCharacterString); }
// Given a CustomCharacter, convert it into the lines of code to build an LCD custom char Array. string CharacterToCCode(CyCustomCharacter customCharacter) { // "characterString" represents the character after conversion to C Code String characterString = ""; CharLCDmp_v1_1.CyBox[,] pixelArray = customCharacter.GetBoxArray(); // Indivudual row value to be calculated byte rowValue; for (int row = 0; row < customCharacter.Rows; row++) { rowValue = 0; for (int column = 0; column < customCharacter.Columns; column++) { if (pixelArray[row, column].IsActive) { // If active find out which pixel it is. The 0th is the furthest right // and has a value of 1. 'customCharacter.Columns - 1' is the furthest left // and has a value of 2^(customCharacter.Columns -1). Values in between are // Exponential powers of 2 based on position. rowValue += (byte)getExponent(customCharacter.Columns - 1 - column); } } // Convert to 2 digit hex. Build Code for this row of the character. string temp = rowValue.ToString("X"); if (temp.Length != 2) { characterString += String.Format(" 0x0{0}u", rowValue.ToString("X")); } else { characterString += String.Format(" 0x{0}u", rowValue.ToString("X")); } // No Comma after the last hex value if (row != customCharacter.Rows - 1) { characterString += ","; } } return(characterString); }