#include "led.h" #include "ledconfig.h" #include "string.h" //#include "text.h" #include "font.h" /// Return the number of frames that should be /// painted between updates char getFramesPerUpdate() { return 80; } //#define SET_PIXEL( p, x, y ) { p[(LINE_SIZE*y) + (x/8)] |= 0x01 << (x%8); } void setPixel(unsigned char* pFrame, uint8_t x, uint8_t y) { pFrame += LINE_SIZE*y; pFrame += x/8; *pFrame |= 1 << (x%8); } uint16_t getWidth(char* pText) { uint16_t width = 0; while (*pText) { if (*pText == ' ') { width += 3 + 1; } else { width += get_char_len(*pText) + 1; } pText++; } return width; } // returns width uint8_t writeChar(unsigned char* pFrame, uint8_t c, int16_t offset) { if (c == ' ') { return 3; } uint8_t i,j; uint8_t len = get_char_len(c); for ( i = 0; i < HEIGHT; i++ ) { for (j = 0; j < len; j++) { int16_t aoff = offset + j; if ((aoff < WIDTH) && (aoff >= 0) && get_char_bit(c,i,j)) { setPixel(pFrame,j+offset,i); } } } return len; } int8_t print( unsigned char* pFrame, char* pText, int16_t offset ) { while ( *pText && (offset < WIDTH) ) { uint8_t len = writeChar( pFrame, *pText, offset ); offset += len + 1; pText++; } return offset; } /// Load the next frame into the provided buffer. /// The frameSeq parameter contains the number of /// frames that have been displayed since startup. /// The lines appear sequentially in the buffer, so /// that the layout is: /// | line0 | line1 | line2 | ... | line6 | /// pFrame pFrame+8 pFrame+16 ... pFrame+56 void getNextFrame( unsigned char* pFrame, uint32_t frameSeq ) { unsigned char i; for ( i =0; i < BUF_SIZE; i++ ) { pFrame[i] = 0; } { char* msg = "MEGASCROLLER WANTS A COOKIE ;) "; int32_t width = getWidth(msg); int32_t off = -(frameSeq%width); print(pFrame,msg,off); print(pFrame,msg,off+width); //print(pFrame,msg,off+width); } }