Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperdisplay Compatibility #32

Open
iangrahamchristensen opened this issue Jul 10, 2019 · 3 comments
Open

Hyperdisplay Compatibility #32

iangrahamchristensen opened this issue Jul 10, 2019 · 3 comments

Comments

@iangrahamchristensen
Copy link

I've attempted to add your 8x16 font size to the hyperdisplay library, but I would appreciate some help. I began by adding the microview 8x16font.h bitmap from your repository. I copied the getCharInfo() method in hyperdisplay.cpp, and I'm attempting to rework the algorithm for the 8x16font.h, however, I'm running into some issues. When I try writing out the bitmap on graphing paper I end up with gibberish, and when running the code the size is still 5x7 unless I swap indi and indj at line 973 --> if(values[indj] & (0x01 << indi)).

		void hyperdisplay::getCharInfo(uint8_t character, char_info_t * character_info) 
		{
			character_info->data = NULL;	// Use the window's current color

			// Link the default cordinate arrays
			character_info->xLoc = hyperdisplayAlternativeXloc;
			character_info->yLoc = hyperdisplayAlternativeYloc;

			// Set the maximum x and y dimensions
			character_info->xDim = 8;
			character_info->yDim = 17;

			// Figure out if the character should cause a newline
			if (character == '\r' || character == '\n')
			{
				character_info->causesNewline = true;
			}
			else
			{
				character_info->causesNewline = false;
			} 

			// Figure out if you need to actually show the chracter
			if((character >= ' ') && (character <= '~'))
			{
				character_info->show = true;
			}
			else
			{
				character_info->show = false;
				return;								// No point in continuing;
			}

			// This will store the hex values that represent each column of pixels
			int values[17];

			// The first value skips the first row of definitions
			// The second value is the character width
			// The third value is the ASCII start character
			int offset = 6 + 8 * (character - 32);

			// Counter for how many pixels need to be printed
			character_info->numPixels = 0;
			
			// The index value of the next X and Y locations
			int n = 0;
			
			// Read the 8 different hex values being saved in the array
			for(int indi = 0; indi < 16; indi++)
			{

				// Sets each value in the array to a hex value from the fontmap, 
				// which in binary should be a set of bits that are on or off
				// representing the pixels that are either black or white, etc.
				// (the sum of the offset and indi are the index of the byte being read)
				values[indi] = pgm_read_byte(font8x16 + offset + indi);

				// Now go through each row of the character's pixels and confirm whether to print a pixel or not
				for(int indj = 0; indj < 8; indj++)
				{
					// Not sure what this does or why it works, but I switched the
					// indi and indj values and the TFT displays the correct size
					// (obviously the the 0x01 is shifted to the left by indj, and 
					//  then the column value is ANDed together to see if the outcome
					//  is true...not sure what that means though without understanding
					//  the fontmap better)
					if(values[indi] & (0x01 << indj))
					{
						// A pixel is being added so we need to increase the numPixels counter
						character_info->numPixels++;

						// Add the x and y locations of the new pixel to the character_info struct
						*(character_info->xLoc + n) = (hd_font_extent_t)indi;
						*(character_info->yLoc + n) = (hd_font_extent_t)indj;

						// Increment the index value because we just filled the current index with pixel data
						n++;
					}
				}
			}
		}

Here is the link to the file I'm using: https://github.com/iangchristensen/SparkFun_HyperDisplay_Library/blob/master/SparkFun_HyperDisplay_Library/src/hyperdisplay.cpp

@MLXXXp
Copy link
Contributor

MLXXXp commented Jul 10, 2019

When I try writing out the bitmap on graphing paper I end up with gibberish

This document should help to explain how MicroView fonts are encoded:
https://learn.sparkfun.com/tutorials/microview-hookup-guide/creating-fonts-for-microview

@jpliew
Copy link
Contributor

jpliew commented Jul 10, 2019

Thanks @MLXXXp , long time since we last chat. I can't believe the document to create fonts for MicroView is still valid after that many years.

Hi @iangchristensen , from a quick look at HyperDisplay library, it's is an on going development. I am unable to see any code that will deal with font more than 8 pixel height yet.

From their blog, SparkFun has a big vision for this display library, it will be so much better if you can work together with their team to enhance their library.

The HyperDisplay library is using part of MicroView's library as reference hence using the same font format.

If you look at this function, it deals with font taller than 8pixel height.

void MicroView::drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode) {

But before you wasted time porting this over, just a reminder that MicroView library was improved by @MLXXXp to be optimized and serve one single purpose to be fast and efficient for the MicroView OLED. Because HyperDisplay is meant for "any" display, hence the code from MicroView may need to be relook and changed to work with other display sizes.

Good luck.

@oclyke
Copy link

oclyke commented Jul 15, 2019

@MLXXXp and @jpliew, thanks for pointing @iangchristensen at the HyperDisplay Project GitHub Repository, as well as for the great work on the MicroView!

@iangchristensen, the 5x7 MicroView font is included so that there is a default that allows text to get to the screen, and also as a reference for one way to add your own font. I'm happy to see that you're interested in HyperDisplay and would gladly help you get the 8x16 font working. Can you open an issue on the HyperDisplay repository (link above)?

At a very high level there are two things happening to display the 5x7 font with HyperDisplay:

  1. Reading the MicroView font format to get a list of coordinates that should be colored
  2. Converting that to work with the HyperDisplay interface so that the pixels can be displayed.

In step two each character that is drawn has a rectangular area of WxH pixels. Each pixel may have its own color and relative X/Y location within the character area. Setting that information into the character_info structure is the method by which any character is drawn, and is the responsibility of the get_char_info() function.

Like I said, I'm excited to hear more from your at the HyperDisplay repo. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants