Skip to content

Commit

Permalink
Lib v1.5. Fixed tick-bug. Support for yPos in DrawText()
Browse files Browse the repository at this point in the history
  • Loading branch information
Small Room Labs committed Oct 16, 2010
1 parent f66fff5 commit a5b7516
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions library/QuarterK.cpp
Expand Up @@ -7,6 +7,7 @@
* The class is also autoinstantiated. * The class is also autoinstantiated.
* v1.3 Mats Engstrom - Added IsSet(). * v1.3 Mats Engstrom - Added IsSet().
* v1.4 Mats Engstrom - Support for Arduino Mega 1280 (bitbang SPI) * v1.4 Mats Engstrom - Support for Arduino Mega 1280 (bitbang SPI)
* v1.5 Mats Engstrom - Fixed bug in tick handling. Support for yPos in DrawText()
* *
* This software is licensed under the Creative Commons Attribution- * This software is licensed under the Creative Commons Attribution-
* ShareAlike 3.0 Unported License. * ShareAlike 3.0 Unported License.
Expand All @@ -25,6 +26,10 @@ byte _framebuffer[32]; // Private framebuffer for screen refresh only


volatile unsigned int tick; volatile unsigned int tick;


unsigned int QuarterK::GetTick() {
return tick;
}



// //
// Bit-banged SPI function used by Mega Arduinos // Bit-banged SPI function used by Mega Arduinos
Expand Down Expand Up @@ -52,8 +57,8 @@ volatile unsigned int tick;
ISR(TIMER1_COMPA_vect) { ISR(TIMER1_COMPA_vect) {
static byte nr=0; static byte nr=0;
byte offset; byte offset;

tick++; tick++;
offset=((nr+1)&0x07)*2; offset=((nr+1)&0x07)*2;


#if defined(__AVR_ATmega1280__) #if defined(__AVR_ATmega1280__)
Expand Down Expand Up @@ -755,6 +760,7 @@ boolean QuarterK::DrawText(char *msg, uint8_t *pFont, int shift, byte xPos, byte
bitmap=pgm_read_byte_near(p++); bitmap=pgm_read_byte_near(p++);
if ((x>=0) && (x<16)) { if ((x>=0) && (x<16)) {
y=min(7, charHeight-1); y=min(7, charHeight-1);
y+=yPos;
if (bitmap&0x80) qk.Plot(x,y); if (bitmap&0x80) qk.Plot(x,y);
y--; y--;
if (charHeight==1) continue; if (charHeight==1) continue;
Expand Down Expand Up @@ -785,6 +791,7 @@ boolean QuarterK::DrawText(char *msg, uint8_t *pFont, int shift, byte xPos, byte
for (column=0; column<charWidth; column++) { for (column=0; column<charWidth; column++) {
x=column+offset-shift; x=column+offset-shift;
y=charHeight-1; y=charHeight-1;
y+=yPos;
bitmap=pgm_read_byte_near(p++); bitmap=pgm_read_byte_near(p++);
if ((x>=0) && (x<16)) { if ((x>=0) && (x<16)) {
if (bitmap&0x80) qk.Plot(x,y); if (bitmap&0x80) qk.Plot(x,y);
Expand Down Expand Up @@ -825,8 +832,9 @@ boolean QuarterK::DrawText(char *msg, uint8_t *pFont, int shift, byte xPos, byte
// //
// //
void QuarterK::Delay(unsigned int ms) { void QuarterK::Delay(unsigned int ms) {
unsigned int oldtick;
while (ms-->0) { while (ms-->0) {
unsigned int oldtick=tick; oldtick=tick;
while(tick==oldtick); while(tick==oldtick);
}; };
} }
Expand Down
7 changes: 6 additions & 1 deletion library/QuarterK.h
Expand Up @@ -7,6 +7,7 @@
* The class is also autoinstantiated. * The class is also autoinstantiated.
* v1.3 Mats Engstrom - Added IsSet(). * v1.3 Mats Engstrom - Added IsSet().
* v1.4 Mats Engstrom - Support for Arduino Mega 1280 (bitbang SPI) * v1.4 Mats Engstrom - Support for Arduino Mega 1280 (bitbang SPI)
* v1.5 Mats Engstrom - Fixed bug in tick handling. Support for yPos in DrawText()
* *
* This software is licensed under the Creative Commons Attribution- * This software is licensed under the Creative Commons Attribution-
* ShareAlike 3.0 Unported License. * ShareAlike 3.0 Unported License.
Expand Down Expand Up @@ -124,12 +125,16 @@ extern byte framebuffer[32];
// //




extern volatile unsigned int tick;


class QuarterK { class QuarterK {


public: public:
QuarterK(void); QuarterK(void);



unsigned int GetTick();

void RefreshRow(); void RefreshRow();


// Turn off (Clear) or on (Fill) all pixels on the display // Turn off (Clear) or on (Fill) all pixels on the display
Expand Down Expand Up @@ -170,7 +175,7 @@ class QuarterK {


// Draws a string of characters. The *pFont a pointer to a font generated by // Draws a string of characters. The *pFont a pointer to a font generated by
// F. Maximilian Thiele's FontGenerator. The text is offsetted by the number of pixels // F. Maximilian Thiele's FontGenerator. The text is offsetted by the number of pixels
// defined by shift. Currently the xPos and yPos is not implemented in the code. // defined by shift. Currently xPos is not implemented in the code.
boolean DrawText(char *msg, uint8_t *pFont, int shift, byte xPos=0, byte yPos=0); boolean DrawText(char *msg, uint8_t *pFont, int shift, byte xPos=0, byte yPos=0);


// Get the state of the fire-button on the game controller. Returns // Get the state of the fire-button on the game controller. Returns
Expand Down

0 comments on commit a5b7516

Please sign in to comment.