Skip to content

Commit

Permalink
Reduce some type sizes, use DISPLAY_ROWS/DISPLAY_COLS more uniformly.
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 30, 2013
1 parent e088707 commit e4f49ab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 51 deletions.
24 changes: 12 additions & 12 deletions lib/Charliplexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ void LedSign::Flip(bool blocking)
/** Clear the screen completely
* @param set if 1 : make all led ON, if not set or 0 : make all led OFF
*/
void LedSign::Clear(int set) {
for(int x=0;x<14;x++)
for(int y=0;y<9;y++)
Set(x,y,set);
void LedSign::Clear(uint8_t c) {
for (uint8_t x=0; x<DISPLAY_COLS; x++)
for (uint8_t y=0; y<DISPLAY_ROWS; y++)
Set(x, y, c);
}


Expand All @@ -366,9 +366,9 @@ void LedSign::Clear(int set) {
* @param y is the y coordinate of the line to clear/light [0-8]
* @param set if 1 : make all led ON, if not set or 0 : make all led OFF
*/
void LedSign::Horizontal(int y, int set) {
for(int x=0;x<14;x++)
Set(x,y,set);
void LedSign::Horizontal(uint8_t y, uint8_t c) {
for (uint8_t x=0; x<DISPLAY_COLS; x++)
Set(x, y, c);
}


Expand All @@ -377,9 +377,9 @@ void LedSign::Horizontal(int y, int set) {
* @param x is the x coordinate of the line to clear/light [0-13]
* @param set if 1 : make all led ON, if not set or 0 : make all led OFF
*/
void LedSign::Vertical(int x, int set) {
for(int y=0;y<9;y++)
Set(x,y,set);
void LedSign::Vertical(uint8_t x, uint8_t c) {
for (uint8_t y=0; y<DISPLAY_ROWS; y++)
Set(x, y, c);
}


Expand All @@ -399,8 +399,8 @@ void LedSign::Set(uint8_t x, uint8_t y, uint8_t c)
c = SHADES-1;
#endif

uint16_t mask = 1 << pgm_read_byte_near(&ledMap[x+y*14].high);
uint8_t cycle = pgm_read_byte_near(&ledMap[x+y*14].cycle);
uint16_t mask = 1 << pgm_read_byte_near(&ledMap[x+y*DISPLAY_COLS].high);
uint8_t cycle = pgm_read_byte_near(&ledMap[x+y*DISPLAY_COLS].cycle);

uint16_t *p = &workBuffer->pixels[cycle*(SHADES-1)];
int i;
Expand Down
7 changes: 3 additions & 4 deletions lib/Charliplexing.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ namespace LedSign
extern void Init(uint8_t mode = SINGLE_BUFFER);
extern void Set(uint8_t x, uint8_t y, uint8_t c = 1);
extern void SetBrightness(uint8_t brightness);
extern volatile unsigned int tcnt2;
extern void Flip(bool blocking = false);
extern void Clear(int set=0);
extern void Horizontal(int y, int set=0);
extern void Vertical(int x, int set=0);
extern void Clear(uint8_t c = 0);
extern void Horizontal(uint8_t y, uint8_t c = 0);
extern void Vertical(uint8_t x, uint8_t c = 0);
};

#endif
51 changes: 22 additions & 29 deletions lib/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ const uint8_t* font2[] = { 0, 0, 0, 0, 0, 0, letters_97 /*a*/, letters_98
#endif

/* ----------------------------------------------------------------- */
/** Draws a figure (0-9). You should call it with set=1,
* wait a little them call it again with set=0
/** Draws a figure (0-9). You should call it with c=1,
* wait a little them call it again with c=0
* @param figure is the figure [0-9]
* @param x,y coordinates,
* @param set is 1 or 0 to draw or clear it
* @param c is 1 or 0 to draw or clear it
*/
uint8_t Font::Draw(unsigned char letter,int x,int y,int set) {
uint16_t maxx=0;
uint8_t Font::Draw(unsigned char letter, uint8_t x, uint8_t y, uint8_t c) {
uint8_t maxx=0;

uint8_t charCol;
uint8_t charRow;
Expand All @@ -141,25 +141,22 @@ uint8_t Font::Draw(unsigned char letter,int x,int y,int set) {
character = font[letter-fontMin];
// }

int i=0;

charCol = pgm_read_byte_near(character);
charRow = pgm_read_byte_near(character + 1);
charCol = pgm_read_byte_near(character++);
charRow = pgm_read_byte_near(character++);

while (charRow!=9) {
if (charCol>maxx) maxx=charCol;
if (
charCol + x <14 &&
charCol + x <DISPLAY_COLS &&
charCol + x >=0 &&
charRow + y <9 &&
charRow + y <DISPLAY_ROWS &&
charRow + y >=0
) {
LedSign::Set(charCol + x, charRow+y, set);
LedSign::Set(charCol + x, charRow+y, c);
}
i+=2;

charCol = pgm_read_byte_near(character + i);
charRow = pgm_read_byte_near(character + 1 + i);
charCol = pgm_read_byte_near(character++);
charRow = pgm_read_byte_near(character++);
}
return maxx+2;
}
Expand All @@ -169,10 +166,10 @@ uint8_t Font::Draw(unsigned char letter,int x,int y,int set) {
/** Draw a figure in the other direction (rotated 90°)
* @param figure is the figure [0-9]
* @param x,y coordinates,
* @param set is 1 or 0 to draw or clear it
* @param c is 1 or 0 to draw or clear it
*/
uint8_t Font::Draw90(unsigned char letter,int x,int y,int set) {
uint16_t maxx=0;
uint8_t Font::Draw90(unsigned char letter, uint8_t x, uint8_t y, uint8_t c) {
uint8_t maxx=0;

uint8_t charCol;
uint8_t charRow;
Expand All @@ -189,28 +186,24 @@ uint8_t Font::Draw90(unsigned char letter,int x,int y,int set) {
character = font[letter-fontMin];
// }

int i=0;

charCol = pgm_read_byte_near(character);
charRow = pgm_read_byte_near(character + 1);
charCol = pgm_read_byte_near(character++);
charRow = pgm_read_byte_near(character++);

while (charRow!=9) {
if (charCol>maxx) maxx=charCol;
if (
charRow + x <14 &&
charRow + x <DISPLAY_COLS &&
charRow + x >=0 &&
charCol + y <9 &&
charCol + y <DISPLAY_ROWS &&
charCol + y >=0
) {
LedSign::Set(7 - charRow + x, charCol + y, set);
LedSign::Set(7 - charRow + x, charCol + y, c);
}
i+=2;

charCol = pgm_read_byte_near(character + i);
charRow = pgm_read_byte_near(character + 1 + i);
charCol = pgm_read_byte_near(character++);
charRow = pgm_read_byte_near(character++);
}
return maxx+2;

}


Expand Down
8 changes: 2 additions & 6 deletions lib/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@

namespace Font
{

extern uint8_t Draw(unsigned char letter,int x,int y,int set=1);

extern uint8_t Draw90(unsigned char letter,int x,int y,int set=1);

extern uint8_t Draw(unsigned char letter, uint8_t x, uint8_t y, uint8_t c=1);
extern uint8_t Draw90(unsigned char letter, uint8_t x, uint8_t y, uint8_t c=1);
}

#endif

0 comments on commit e4f49ab

Please sign in to comment.