Adafruit-RGB_matrix_Panel(32*16)
Dependencies: Adafruit-GFX
Revision 12:e632883f319f, committed 2014-05-25
- Comitter:
- lelect
- Date:
- Sun May 25 13:41:34 2014 +0000
- Parent:
- 11:c2e2eb66d353
- Child:
- 13:0ceb1b8893e9
- Commit message:
- add oxygen & method(convert HSV in float value)
Changed in this revision
--- a/Adafruit-GFX.lib Sun May 25 12:36:39 2014 +0000 +++ b/Adafruit-GFX.lib Sun May 25 13:41:34 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/EIC_mbed/code/Adafruit-GFX/#3e9c32359703 +http://mbed.org/teams/EIC_mbed/code/Adafruit-GFX/#c2715acb7466
--- a/RGBmatrixPanel.cpp Sun May 25 12:36:39 2014 +0000 +++ b/RGBmatrixPanel.cpp Sun May 25 13:41:34 2014 +0000 @@ -189,7 +189,48 @@ (g << 7) | ((g & 0xC) << 3) | (b << 1) | ( b >> 3); } - +uint16_t RGBmatrixPanel::ColorHSV(float hue, float sat, float val, bool gflag) +{ + int i = floor(hue * 6); + float f = hue*6-i; + float p = val*(1-sat); + float q = val*(1-f*sat); + float t = val*(1-(1-f)*sat); + float r = 0,g=0,b=0; + switch(i % 6) { + case 0: + r = val; + g = t; + b = p; + break; + case 1: + r = q; + g = val; + b = p; + break; + case 2: + r = p; + g = val; + b = t; + break; + case 3: + r = p; + g = q; + b = val; + break; + case 4: + r = t; + g = p; + b = val; + break; + case 5: + r = val; + g = p; + b = q; + break; + } + return Color888(r*255,g*255,b*255,gflag); +} void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t c) { uint8_t r, g, b, bit, limit, *ptr; @@ -215,10 +256,8 @@ g = (c >> 7) & 0xF; // rrrrrGGGGggbbbbb b = (c >> 1) & 0xF; // rrrrrggggggBBBBb // Loop counter stuff - //log_debug("(%X, %X, %X)@(%d,%d)%s",r,g,b,x,y,"\t"); bit = 2; limit = 1 << nPlanes; - if(y < nRows) { // Data for the upper half of the display is stored in the lower bits of each byte. ptr = &matrixbuff[backindex][y*_rawWidth*(nPlanes-1) + x]; // Base addr @@ -283,17 +322,13 @@ // draw over every pixel. (No effect if double-buffering is not enabled.) void RGBmatrixPanel::swapBuffers(bool copy) { - log_debug("\r\ncall swapBuffers %s","\r\n"); if(matrixbuff[0] != matrixbuff[1]) { // To avoid 'tearing' display, actual swap takes place in the interrupt // handler, at the end of a complete screen refresh cycle. swapflag = true; // Set flag here, then... while(swapflag == true) wait_ms(1); // wait for interrupt to clear it if(copy == true) { - log_debug("\tmemcpy %s","\r\n"); memcpy(matrixbuff[backindex], matrixbuff[1-backindex], 32 * nRows * 3); - } else { - log_debug("\tnot memcpy %s","\r\n"); } } } @@ -321,7 +356,6 @@ void RGBmatrixPanel::updateDisplay(void) { uint8_t *ptr; - log_debug("\r\ncall updateDisplay\r\n"); _oe=1; _latch=1; if(++plane >= nPlanes) { // Advance plane counter. Maxed out? @@ -330,55 +364,28 @@ row= 0; // Yes, reset row counter, then... if(swapflag == true) { // Swap front/back buffers if requested backindex = 1 - backindex; - log_debug("\t\treset swapflag%s","\r\n"); swapflag = false; } - log_debug("\tReset into front buffer[%d]%s",backindex,"\r\n"); buffptr = matrixbuff[1-backindex]; // Reset into front buffer } } else if(plane == 1) { - log_debug("\tupdate row%s","\r\n"); _rowBus.write(row); } _oe=0; _latch=0; ptr = (uint8_t *)buffptr; - - log_debug("\t(row@plane)=(%d,%d)\r\n",row,plane); if(plane > 0) { - //ptr[i]>>2 for(int i=0; i<32; i++) { _dataBus.write((*(ptr+i)>>2)); _sclk=1; _sclk=0; -#if 0 -#ifdef DEBUG - if(int(_dataBus)==color) { - log_debug(" %02x",int(_dataBus)); - } else { - _dataBus=color; - log_debug(" (%x->%x)%s",color,int(_dataBus),"\0"); - } -#endif -#endif } buffptr += _rawWidth; } else { - //((ptr[i]<<4)|((ptr[i+32]<<2)&0x0C)|((ptr[i+64])&0x03)); for(int i=0; i<32; i++) { _dataBus.write(((ptr[i]<<4)|((ptr[i+32]<<2)&0x0C)|((ptr[i+64])&0x03))); _sclk=1; _sclk=0; -#if 0 -#ifdef DEBUG - if(int(_dataBus)==color) { - log_debug(" %02x",int(_dataBus)); - } else { - _dataBus=color; - log_debug(" (%x->%x)%s",color,int(_dataBus),"\0"); - } -#endif -#endif } }
--- a/RGBmatrixPanel.h Sun May 25 12:36:39 2014 +0000 +++ b/RGBmatrixPanel.h Sun May 25 13:41:34 2014 +0000 @@ -11,32 +11,86 @@ #define log_debug(...) #endif +/** RGBmatrixPanel is class for full color LED matrix + * + */ class RGBmatrixPanel : public Adafruit_GFX { public: // Constructor for 16x32 panel: RGBmatrixPanel(PinName r1,PinName g1,PinName b1,PinName r2,PinName g2,PinName b2,PinName a,PinName b,PinName c,PinName sclk,PinName latch,PinName oe, bool dbuf); -// RGBmatrixPanel(PinName r1,PinName r2,PinName g1,PinName g2,PinName b1,PinName b2,PinName a,PinName b,PinName c,PinName sclk,PinName latch,PinName oe,bool dbuf); // Constructor for 32x32 panel (adds 'd' pin): - //RGBmatrixPanel(PinName r1,PinName r2,PinName g1,PinName g2,PinName b1,PinName b2,PinName a,PinName b,PinName c,PinName d,PinName sclk, PinName latch,PinName oe,bool dbuf); + RGBmatrixPanel(PinName r1,PinName r2,PinName g1,PinName g2,PinName b1,PinName b2,PinName a,PinName b,PinName c,PinName d,PinName sclk, PinName latch,PinName oe,bool dbuf); + /** Attach a updateDisplay() to be called by the Ticker(every 100us) + * + */ void begin(void); - virtual void drawPixel(int16_t x, int16_t y, uint16_t c); + /** @fn void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t c) + * @bref drawPixel + */ + virtual void drawPixel(int16_t x,int16_t y,uint16_t c); + /** @fn void RGBmatrixPanel::fillScreen(uint16_t c) + * @bref fillScreen + * @param c fill screen 16bit color 0x0000 ~ 0xFFFF + */ virtual void fillScreen(uint16_t c); + /** @fn void RGBmatrixPanel::updateDisplay(void) + * @param c updateDisplay\\ + * This method is called by the interrupt start at begin(). + */ void updateDisplay(void); - void swapBuffers(bool); + /** @fn void RGBmatrixPanel::swapBuffers(bool copy) + * @param copy swap buffer (if you use double-buffer) + */ + void swapBuffers(bool copy); + /** @fn void RGBmatrixPanel::dumpMatrix(void) + * @bref dump to default USB Serial\\ + * Declaration is required to use.(#define DEBUG) + */ void dumpMatrix(void); uint8_t *backBuffer(void); + /** @fn void RGBmatrixPanel::Color333(uint8_t r, uint8_t g, uint8_t b) + * @bref up convert to 16bit color from 9bit color. + * @return 16bit(uint16_t) color value + */ uint16_t Color333(uint8_t r, uint8_t g, uint8_t b); + /** @fn void RGBmatrixPanel::Color444(uint8_t r, uint8_t g, uint8_t b) + * @bref up convert to 16bit color from 12bit color. + * @return 16bit(uint16_t) color value + */ uint16_t Color444(uint8_t r, uint8_t g, uint8_t b); + /** @fn void RGBmatrixPanel::Color888(uint8_t r, uint8_t g, uint8_t b) + * @bref down convert to 16bit color from 24bit color. + * @return 16bit(uint16_t) color value + */ uint16_t Color888(uint8_t r, uint8_t g, uint8_t b); + /** @fn void RGBmatrixPanel::Color888(uint8_t r, uint8_t g, uint8_t b, bool gflag) + * @bref down convert to 16bit color from 24bit color using the gamma value table. + * @return 16bit(uint16_t) color value + */ uint16_t Color888(uint8_t r, uint8_t g, uint8_t b, bool gflag); - uint16_t ColorHSV(long hue, uint8_t sat, uint8_t val, bool gflag); - + /** @fn void RGBmatrixPanel::ColorHSV(long hue, uint8_t sat, uint8_t val, bool gflag) + * @bref convert to 16bit color from (unsigned integer)HSV color using the gamma value table. + * @param hue 0~1536(decimal value) + * @param sat 0~255(decimal value) Does not make sense that it is not a multiple of 32. + * @param val 0~255(decimal value) Does not make sense that it is not a multiple of 32. + * @return 16bit(uint16_t) color value + */ + uint16_t ColorHSV(long hue, uint8_t sat, uint8_t val, bool gflag) + ; + /** @fn void RGBmatrixPanel::ColorHSV(float hue, float sat, float val, bool gflag) + * @bref convert to 16bit color from (float)HSV color using the gamma value table. + * @param hue Normalized value from 0.0 to 1.0 + * @param sat Normalized value from 0.0 to 1.0 + * @param val Normalized value from 0.0 to 1.0 + * @return 16bit(uint16_t) color value + */ + uint16_t ColorHSV(float hue, float sat, float val, bool gflag); private: uint8_t *matrixbuff[2]; uint8_t nRows;