Page 1 of 1

Some minor additions for the DMD library

Posted: Sat Jan 18, 2014 10:42 am
by Brissieboy
I needed to be able to determine the current font. The following method can be added to DMD.cpp and returns the pointer to the current font.

Code: Select all

/*--------------------------------------------------------------------------------------
 Return pointer to the current font
--------------------------------------------------------------------------------------*/
const uint8_t* DMD::getFont()
{
  return Font;
}
which can be used like this

Code: Select all

      const uint8_t* fontptr;   // variable to hold the pointer
      fontptr = dmd.getFont();  // remember the current font
     // change font and do something in here
      dmd.selectFont(fontptr);  // restore the original font
with the following lines added to DMD.h (in the Class DMD public area)

Code: Select all

  //Get the address of the current font
  const uint8_t* getFont();
And I wanted to be able to control where I placed a string depending on its width (pixel width, not number of characters) regardless of the font or whether is was fixed width or proportionally spaced. The following method returns the width in pixels in the current font

Code: Select all

//******************************************************************************
//Returns the width in pixels of the target string
//******************************************************************************
byte DMD::stringWidth(const char *bChars)
{
  int strWidth = 0;
  for (byte i = 0; i < strlen(bChars); i++) {  // step through the length of the string
    strWidth += dmd.charWidth(bChars[i]) + 1;  // increment by the width of this character in pixels,
                                               // plus the 1 pixel character spacing
  }
  return strWidth - 1;                         // don't allow for a character space at the end
}
with the following lines added to DMD.h (in the Class DMD public area)

Code: Select all

 //Return the width in pixels of the target string
  int stringWidth();
In void DMD::drawString() a blank single pixel wide space is drawn BEFORE the specified location of the string. I don't think his should not be built into the library - it is up to the programmer to provide this if required. (I didn't want it there>)
In DMD.cpp in DMD::drawString() comment out the line:

Code: Select all

	this->drawLine(bX -1 , bY, bX -1 , bY + height, bgcolour);
The library contains the following methods:
void DMD::scrollVert(int direction, boolean wrap)
void DMD::scrollHorz(int direction, boolean wrap)
Neither of these functions use the parameter 'wrap'.

And the void DMD::dumpPixels() method does not work - it does not allow for the updated screen buffers option and expects only 1 DMD set up - is not required and is commented out, but is retained in the library for some reason (probably an old debug tool and should be deleted to avoid confusion).