1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Update usage of PROGMEM to Arduino 1.0.1

This commit is contained in:
Rhys Weatherley
2013-09-29 09:15:24 +10:00
parent 6a5ec04068
commit 393eb6c2ba
14 changed files with 50 additions and 41 deletions

View File

@@ -47,6 +47,16 @@
* \sa Black, White
*/
/**
* \typedef Bitmap::ProgMem
* \brief Type that represents a bitmap within program memory.
*/
/**
* \typedef Bitmap::Font
* \brief Type that represents a font within program memory.
*/
/**
* \var Bitmap::Black
* \brief Color value corresponding to "black".
@@ -412,14 +422,14 @@ void Bitmap::drawBitmap(int x, int y, const Bitmap &bitmap, Color color)
*
* \sa drawInvertedBitmap(), fill()
*/
void Bitmap::drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color)
void Bitmap::drawBitmap(int x, int y, Bitmap::ProgMem bitmap, Color color)
{
uint8_t w = pgm_read_byte(bitmap);
uint8_t s = (w + 7) >> 3;
uint8_t h = pgm_read_byte(bitmap + 1);
Color invColor = !color;
for (uint8_t by = 0; by < h; ++by) {
const prog_uint8_t *line = bitmap + 2 + by * s;
const uint8_t *line = ((const uint8_t *)bitmap) + 2 + by * s;
uint8_t mask = 0x80;
uint8_t value = pgm_read_byte(line);
for (uint8_t bx = 0; bx < w; ++bx) {
@@ -448,7 +458,7 @@ void Bitmap::drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color)
*/
/**
* \fn void Bitmap::drawInvertedBitmap(int x, int y, const prog_uint8_t *bitmap)
* \fn void Bitmap::drawInvertedBitmap(int x, int y, Bitmap::ProgMem bitmap)
* \brief Draws \a bitmap at (\a x, \a y) in inverted colors.
*
* This is a convenience function that is equivalent to
@@ -458,14 +468,14 @@ void Bitmap::drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color)
*/
/**
* \fn const prog_uint8_t *Bitmap::font() const
* \fn Font Bitmap::font() const
* \brief Returns the currently selected font, or null if none selected.
*
* \sa setFont(), drawText(), drawChar(), charWidth()
*/
/**
* \fn void Bitmap::setFont(const prog_uint8_t *font)
* \fn void Bitmap::setFont(Font font)
* \brief Sets the \a font for use with drawText() and drawChar().
*
* \code
@@ -590,15 +600,15 @@ int Bitmap::drawChar(int x, int y, char ch)
index -= first;
uint8_t heightBytes = (height + 7) >> 3;;
uint8_t width;
const prog_uint8_t *image;
const uint8_t *image;
if (fontIsFixed(_font)) {
// Fixed-width font.
width = fontWidth(_font);
image = _font + 6 + index * heightBytes * width;
image = ((const uint8_t *)_font) + 6 + index * heightBytes * width;
} else {
// Variable-width font.
width = pgm_read_byte(_font + 6 + index);
image = _font + 6 + count;
image = ((const uint8_t *)_font) + 6 + count;
for (uint8_t temp = 0; temp < index; ++temp) {
// Scan through all previous characters to find the starting
// location for this one.
@@ -772,7 +782,7 @@ void Bitmap::fill(int x, int y, int width, int height, Color color)
*
* \sa drawBitmap(), clear(), invert()
*/
void Bitmap::fill(int x, int y, int width, int height, const prog_uint8_t *pattern, Color color)
void Bitmap::fill(int x, int y, int width, int height, Bitmap::ProgMem pattern, Color color)
{
uint8_t w = pgm_read_byte(pattern);
uint8_t s = (w + 7) >> 3;
@@ -781,8 +791,8 @@ void Bitmap::fill(int x, int y, int width, int height, const prog_uint8_t *patte
return;
Color invColor = !color;
for (int tempy = 0; tempy < height; ++tempy) {
const prog_uint8_t *startLine = pattern + 2 + (tempy % h) * s;
const prog_uint8_t *line = startLine;
const uint8_t *startLine = ((const uint8_t *)pattern) + 2 + (tempy % h) * s;
const uint8_t *line = startLine;
uint8_t mask = 0x80;
uint8_t value = pgm_read_byte(line++);
int bit = 0;

View File

@@ -38,6 +38,8 @@ public:
bool isValid() const { return fb != 0; }
typedef uint8_t Color;
typedef PGM_VOID_P ProgMem;
typedef PGM_VOID_P Font;
static const Color Black = 0;
static const Color White = 1;
@@ -63,12 +65,12 @@ public:
void drawFilledCircle(int centerX, int centerY, int radius, Color color = White);
void drawBitmap(int x, int y, const Bitmap &bitmap, Color color = White);
void drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color = White);
void drawBitmap(int x, int y, Bitmap::ProgMem bitmap, Color color = White);
void drawInvertedBitmap(int x, int y, const Bitmap &bitmap);
void drawInvertedBitmap(int x, int y, const prog_uint8_t *bitmap);
void drawInvertedBitmap(int x, int y, Bitmap::ProgMem bitmap);
const prog_uint8_t *font() const { return _font; }
void setFont(const prog_uint8_t *font) { _font = font; }
Font font() const { return _font; }
void setFont(Font font) { _font = font; }
Color textColor() const { return _textColor; }
void setTextColor(Color color) { _textColor = color; }
@@ -85,7 +87,7 @@ public:
void copy(int x, int y, int width, int height, Bitmap *dest, int destX, int destY);
void fill(int x, int y, int width, int height, Color color);
void fill(int x, int y, int width, int height, const prog_uint8_t *pattern, Color color = White);
void fill(int x, int y, int width, int height, Bitmap::ProgMem pattern, Color color = White);
void scroll(int dx, int dy, Color fillColor = Black);
void scroll(int x, int y, int width, int height, int dx, int dy, Color fillColor = Black);
@@ -101,7 +103,7 @@ private:
int _height;
int _stride;
uint8_t *fb;
const prog_uint8_t *_font;
Font _font;
Color _textColor;
friend class DMD;
@@ -125,7 +127,7 @@ inline void Bitmap::drawInvertedBitmap(int x, int y, const Bitmap &bitmap)
drawBitmap(x, y, bitmap, Black);
}
inline void Bitmap::drawInvertedBitmap(int x, int y, const prog_uint8_t *bitmap)
inline void Bitmap::drawInvertedBitmap(int x, int y, Bitmap::ProgMem bitmap)
{
drawBitmap(x, y, bitmap, Black);
}

View File

@@ -45,7 +45,7 @@
#define DEJAVUSANS9_WIDTH 10
#define DEJAVUSANS9_HEIGHT 10
static uint8_t DejaVuSans9[] PROGMEM = {
static uint8_t const DejaVuSans9[] PROGMEM = {
0x0F, 0x7A, // size
0x0A, // width
0x0A, // height

View File

@@ -45,7 +45,7 @@
#define DEJAVUSANSBOLD9_WIDTH 10
#define DEJAVUSANSBOLD9_HEIGHT 10
static uint8_t DejaVuSansBold9[] PROGMEM = {
static uint8_t const DejaVuSansBold9[] PROGMEM = {
0x12, 0x36, // size
0x0A, // width
0x0A, // height

View File

@@ -45,7 +45,7 @@
#define DEJAVUSANSITALIC9_WIDTH 10
#define DEJAVUSANSITALIC9_HEIGHT 10
static uint8_t DejaVuSansItalic9[] PROGMEM = {
static uint8_t const DejaVuSansItalic9[] PROGMEM = {
0x11, 0xDC, // size
0x0A, // width
0x0A, // height

View File

@@ -45,7 +45,7 @@
#define MONO5X7_WIDTH 5
#define MONO5X7_HEIGHT 7
static uint8_t Mono5x7[] PROGMEM = {
static uint8_t const Mono5x7[] PROGMEM = {
0x00, 0x00, // size
0x05, // width
0x07, // height

View File

@@ -227,7 +227,7 @@ byte const run10[] PROGMEM = {
B01000000, B00000000
};
const prog_uint8_t *frames[] = {
Bitmap::ProgMem frames[] = {
run1,
run2,
run3,

View File

@@ -227,7 +227,7 @@ byte const run10[] PROGMEM = {
B01000000, B00000000
};
const prog_uint8_t *frames[] = {
Bitmap::ProgMem frames[] = {
run1,
run2,
run3,