Johan Kritzinger
/
FRDMKL25Z-ShiftBrite
A few classes to interface one or more ShiftBrite module to the FRDM KL25Z.
Diff: sbDriver.cpp
- Revision:
- 3:9376bf1f1bbd
- Parent:
- 0:f76850de7b57
- Child:
- 4:d2f8ddb423e2
--- a/sbDriver.cpp Wed Aug 20 05:24:38 2014 +0000 +++ b/sbDriver.cpp Wed Aug 20 08:11:28 2014 +0000 @@ -3,11 +3,7 @@ #include "mbed.h" #include "sbDriver.h" -//#define DEBUGPRINT //Uncoment to see various debug output - -//#define SENDPRINT //Uncomment to see what is being sent to the SB's - -#define ERRORPRINT //Comment to not see any error message on STD:: +#define ERRORPRINT //Comment out to not see any error message on STD:: //NOTES ON THE SHIFTBRITE MODULES @@ -120,9 +116,6 @@ // OK, so the sb control/data lines have been setup via references //Allocate memory for moduleCount* sb modules serial_p = port; -#ifdef DEBUGPRINT - serial_p->printf("Construct shiftBriteDisplay\r\n"); -#endif spi.format(8,0);//8 bit, mode 0 spi.frequency(100000);//100kHz clk @@ -159,9 +152,6 @@ bCorr= blue & 0x7F; if(f_update == 0){ -#ifdef DEBUGPRINT - serial_p->printf("Current adj\r\n"); -#endif f_update=1; //prevent the ISR from messing this up //Backup the colours @@ -202,9 +192,6 @@ void shiftBriteDisplay::setLed(unsigned int moduleNum, unsigned long int rgbValue){ //Set the colour of a specific LED in the array -#ifdef DEBUGPRINT - serial_p->printf("SetLed %u:%lx\r\n",moduleNum,rgbValue); -#endif moduleCount >= moduleNum ? module_p[moduleNum].setRgbLed(rgbValue): /*TO DO - set some sort of error? For now, mess up the LAST moodule setting*/ module_p[moduleCount-1].setRgbLed(rgbValue); } //-------------------- @@ -220,39 +207,17 @@ //Now, massage the hardware to send the data bits for this particular led module //Remember, spi writes 8 bits at a time so I need to access the packet a byte at a time //but I also need to start at the MSB -#ifdef DEBUGPRINT - serial_p->printf("send 0x%0x\r\n",temp); - serial_p->printf("Red: 0x%x | Grn: 0x%x | Blue: 0x%x\r\n",M.getRed(),M.getGreen(),M.getBlue()); -#endif byt = (unsigned char)( 0X000000FF & (temp >> 24));//msb if(commandStatus == 1){//i.e. adjust current control registers byt |= 0x40;//Add in the control flag to tell the shift Brite LED module that we are talking to the control registers -#ifdef SENDPRINT - serial_p->printf("C"); - } //i.e. going to write current control registers - else { - serial_p->printf("N"); -#endif } spi.write(byt); -#ifdef SENDPRINT - serial_p->printf("*0x%02x",byt); -#endif byt = (unsigned char)( 0X000000FF & (temp >> 16)); spi.write(byt); -#ifdef SENDPRINT - serial_p->printf("%02x",byt); -#endif byt = (unsigned char)( 0X000000FF & (temp >> 8)); spi.write(byt); -#ifdef SENDPRINT - serial_p->printf("%02x",byt); -#endif byt = (unsigned char)( 0X000000FF & temp); spi.write(byt); -#ifdef SENDPRINT - serial_p->printf("%02x\r\n",byt); -#endif } //-------------------- @@ -290,7 +255,63 @@ } } -//-------------------- +void shiftBriteDisplay::rotateLeft(){ + rgbLed temp; //temporary object to hold data + unsigned int i; + temp.setRgbLed(module_p[0].getRed(),module_p[0].getGreen(),module_p[0].getBlue()); + for(i=0; i != moduleCount-1; i++){ + setLed(i,module_p[i+1].getRed(),module_p[i+1].getGreen(),module_p[i+1].getBlue()); + } + setLed(moduleCount-1,temp.getRed(),temp.getGreen(),temp.getBlue()); +} + +void shiftBriteDisplay::shiftLeft(){;//info shifted out is lost, + unsigned int i; + for(i=0; i != moduleCount-1; i++){ + setLed(i,module_p[i+1].getRed(),module_p[i+1].getGreen(),module_p[i+1].getBlue()); + } + setLed(moduleCount-1,0,0,0); +} +void shiftBriteDisplay::rotateRight(){; + rgbLed temp; //temporary object to hold data + unsigned int i; + temp.setRgbLed(module_p[moduleCount-1].getRed(),module_p[moduleCount-1].getGreen(),module_p[moduleCount-1].getBlue()); + for(i=moduleCount; i != 0; i--){ + setLed(i-1,module_p[i-2].getRed(),module_p[i-2].getGreen(),module_p[i-2].getBlue()); + } + setLed(0,temp.getRed(),temp.getGreen(),temp.getBlue()); +} +void shiftBriteDisplay::shiftRight(){;//info shifted out is lost + unsigned int i; + for(i=moduleCount; i != 0; i--){ + setLed(i-1,module_p[i-2].getRed(),module_p[i-2].getGreen(),module_p[i-2].getBlue()); + } + setLed(0,0,0,0); +} +void shiftBriteDisplay::turnOn(){; + priv_SBEnable(); +} +void shiftBriteDisplay::turnOff(){; + priv_SBDisable(); +} + +void shiftBriteDisplay::flip(){; //swop positions + rgbLed temp; //temporary object to hold data + unsigned int i; + for(i=0; i != moduleCount/2; i++){ + temp.setRgbLed(module_p[i].getRed(),module_p[i].getGreen(),module_p[i].getBlue()); + setLed(i,module_p[moduleCount-1-i].getRed(),module_p[moduleCount-1-i].getGreen(),module_p[moduleCount-1-i].getBlue()); + setLed(moduleCount-i-1,temp.getRed(),temp.getGreen(),temp.getBlue()); + } +} + +void shiftBriteDisplay::invert(){; //invert colours + unsigned int i; + for(i=0; i != moduleCount; i++){ + //module_p[i].getRed(); + setLed(i,1023-module_p[i].getRed(),1023-module_p[i].getGreen(),1023-module_p[i].getBlue()); + } +} //=============================================================================================