takahiro maeda / CLED

Dependents:   Nucleo_IHS11a

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CLED.cpp Source File

CLED.cpp

00001 #include "mbed.h"
00002 #include "CLED.h"
00003 // *************************** CLED ********************************
00004 const byte CLED::c10[7] = {0, 4, 5, 1, 3, 2, 6};//IHS10:none, red, yellow, green, lightBlue, bule, purple
00005 const byte CLED::c11[7] = {0, 1, 3, 2, 6, 4, 5};//IHS11:none, red, yellow, green, lightBlue, bule, purple
00006 const byte CLED::INDI_COLOR = 12;
00007 // *************************** SPI ********************************
00008 extern SPI spi;
00009 extern DigitalOut ss;
00010 extern Serial uart;
00011 // *************************** GPIO ********************************
00012 extern DigitalOut sel_sen;
00013 extern DigitalOut fix_cled;
00014 extern DigitalOut oe_cled;
00015 // ************************* object ********************************
00016 Ticker indiTic;
00017 
00018 CLED::CLED(int ver) : inOn(false) {
00019     if (ver == 10) color = c10;
00020     if (ver == 11) color = c11;
00021     indiTic.attach(callback(this, &CLED::indiBlink), 400e-3);
00022     
00023 }
00024 
00025 void CLED::set(byte* ary12, bool indiRow) {        // 1-12[8]:{7, 3,..}
00026     int val24 = 0;
00027     for (int col = 0; col < COL_LEN; col++) {   // LED number is opposit direction
00028         bool isIndi = inOn && indiRow && (col == COL_LEN - 1) && (ary12[col] == 0);
00029         byte cVal = (isIndi ? INDI_COLOR : ary12[col]) >> 1;    
00030         val24 += color[cVal] << col * 3;
00031     }
00032     sel_sen = 0;                                //digitalWrite(sel_sen, LOW);
00033     oe_cled = 0;                                //digitalWrite(oe_cled, LOW);        
00034     ss = 0;                                     //digitalWrite(ss, LOW);
00035     for (int b = 2; b>=0; b--) {
00036         spi.write((val24 >> b * COL_LEN) & 0xff);
00037     }
00038     fix_cled = 1;       //digitalWrite(FIX_LED, HIGH);
00039     fix_cled = 0;       //digitalWrite(FIX_LED, LOW);      
00040     ss = 1;             //digitalWrite(ss, HIGH);
00041     oe_cled = 1;        //digitalWrite(oe_cled, HIGH);
00042 }
00043 
00044 void CLED::set(byte val12) {
00045     byte ary[COL_LEN];
00046     for (int i=0; i<COL_LEN; i++)
00047         ary[i] = val12;
00048     set(ary);
00049 }
00050 
00051 // *************** PWM callback function ****************
00052 void CLED::indiBlink() {          // indicator blink
00053     inOn = !inOn;
00054 }