Wim Huiskamp / Mbed 2 deprecated mbed_PT6964

Dependencies:   PT6964 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed PT6964 Test program, for PT6964 LED controller
00002  * Copyright (c) 2015, v01: WH, Initial version
00003  *               2016, v03: WH, updated Icon handling, UDCs and _putc()
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  */
00023 #include "mbed.h"
00024 #include "PT6964.h"
00025 
00026 Serial pc(USBTX, USBRX);
00027 DigitalOut myled(LED1);
00028 
00029 // Select one of the testboards for Princeton PT6964 LED controller
00030 #define PT6964_TEST   0 
00031 #define DVD538A_TEST  1 
00032 
00033 #if (DVD538A_TEST == 1)
00034 //High level Control PT9664 for DVD538A
00035 
00036 PT6964_DVD538A::DisplayData_t all_str  = {0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F};  
00037 PT6964_DVD538A::DisplayData_t bye_str  = {LO(C7_B),HI(C7_B), LO(C7_Y),HI(C7_Y), LO(C7_E),HI(C7_E), 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};
00038 
00039 // KeyData_t size is 5 bytes  
00040 PT6964_DVD538A::KeyData_t keydata; 
00041 
00042 // PT6964 declaration, Default setting 7 Grids @ 10 Segments
00043 PT6964_DVD538A PT6964_dvd538a(p5,p6,p7, p8);
00044 
00045 char cmd;
00046 int main() {
00047     
00048     pc.printf("Hello World\r\n"); //    
00049     
00050     PT6964_dvd538a.cls(); 
00051     PT6964_dvd538a.writeData(all_str);
00052     wait(4);
00053     PT6964_dvd538a.setBrightness(PT6964_BRT3);    
00054     wait(1);
00055     PT6964_dvd538a.setBrightness(PT6964_BRT0);        
00056     wait(1);
00057     PT6964_dvd538a.setBrightness(PT6964_BRT3);            
00058     
00059     while (1) {
00060      
00061       // Check and read keydata
00062       if (PT6964_dvd538a.getKeys(&keydata)) {
00063         pc.printf("Keydata 0..4 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4]);
00064 
00065         if (keydata[0] == 0x01) { //sw1 L/R  
00066           float delay = 0.2;
00067 
00068           PT6964_dvd538a.cls(); 
00069           PT6964_dvd538a.setIcon(PT6964_DVD538A::LD1); wait(delay);
00070           PT6964_dvd538a.setIcon(PT6964_DVD538A::LD2); wait(delay);
00071           PT6964_dvd538a.setIcon(PT6964_DVD538A::CD);  wait(delay);
00072           PT6964_dvd538a.setIcon(PT6964_DVD538A::DVD); wait(delay);
00073           PT6964_dvd538a.setIcon(PT6964_DVD538A::PSE); wait(delay);
00074           PT6964_dvd538a.setIcon(PT6964_DVD538A::PLY); wait(delay);
00075           PT6964_dvd538a.setIcon(PT6964_DVD538A::COL2); wait(delay);
00076           PT6964_dvd538a.setIcon(PT6964_DVD538A::MP4); wait(delay);
00077           PT6964_dvd538a.setIcon(PT6964_DVD538A::MP3); wait(delay);
00078 
00079           PT6964_dvd538a.clrIcon(PT6964_DVD538A::LD1); wait(delay);
00080           PT6964_dvd538a.clrIcon(PT6964_DVD538A::LD2); wait(delay);
00081           PT6964_dvd538a.clrIcon(PT6964_DVD538A::CD);  wait(delay);
00082           PT6964_dvd538a.clrIcon(PT6964_DVD538A::DVD); wait(delay);
00083           PT6964_dvd538a.clrIcon(PT6964_DVD538A::PSE); wait(delay);
00084           PT6964_dvd538a.clrIcon(PT6964_DVD538A::PLY); wait(delay);
00085           PT6964_dvd538a.clrIcon(PT6964_DVD538A::COL2); wait(delay);
00086           PT6964_dvd538a.clrIcon(PT6964_DVD538A::MP4); wait(delay);
00087           PT6964_dvd538a.clrIcon(PT6964_DVD538A::MP3); wait(delay);
00088         }       
00089 
00090         if (keydata[0] == 0x02) { //sw2 Stop  
00091           PT6964_dvd538a.cls(); 
00092         }  
00093 
00094         if (keydata[0] == 0x08) { //sw4 Play   
00095           PT6964_dvd538a.cls(); 
00096 //          for (int i=0; i<16; i++) {
00097           for (int i=0x00; i<=0xFF; i++) {            
00098             PT6964_dvd538a.locate(0);            
00099             PT6964_dvd538a.printf("%04x", i);
00100 //            PT6964_dvd538a.printf("%04X", i);            
00101             wait(0.2);
00102           }  
00103         }       
00104 
00105         if (keydata[0] == 0x10) { //sw3 Open  
00106 #if(1)
00107 //test to show all digits (base is 0x10)
00108           pc.printf("Show all hex digits\r\n");
00109           wait(1);          
00110           PT6964_dvd538a.cls(); 
00111 
00112           PT6964_dvd538a.printf("%04x", 0x01AB);
00113           cmd = pc.getc(); // wait for key                                     
00114           
00115           int val = 1; 
00116           for (int i=0; i<DVD538A_NR_DIGITS; i++) {
00117 
00118             for (int cnt=0; cnt<0x10; cnt++) {
00119               PT6964_dvd538a.locate(0);
00120               PT6964_dvd538a.printf("%04x", (val * cnt));
00121 
00122 //              wait(0.5);
00123               cmd = pc.getc(); // wait for key
00124             }  
00125             val = val * 0x10;
00126           }
00127           pc.printf("\r\nShow all hex digits done\r\n");          
00128 #endif 
00129         }  
00130         
00131       } //if
00132 
00133       myled = !myled;
00134       wait(0.3);      
00135     } //while
00136 }
00137 #endif
00138 
00139 #if (PT6964_TEST == 1) 
00140 //Direct control of PT9664 for DVD538
00141 
00142 // DisplayData_t size is  8 bytes (4 digits @ 13 segments) OR 10 bytes (5 digits @ 12 segments) OR
00143 //                       12 bytes (6 digits @ 11 segments) OR 14 bytes (7 digits @ 10 segments) 
00144 PT6964::DisplayData_t mbed_str = {0xDA,0x00, 0x7C,0x00, 0x3C,0x01, 0xF6,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
00145 PT6964::DisplayData_t all_str  = {0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F};  
00146 PT6964::DisplayData_t bye_str = {0x7C,0x00, 0xEC,0x00, 0x3C,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
00147 PT6964::DisplayData_t hello_str = {0xDC,0x00, 0x3C,0x01, 0x38,0x00, 0x38,0x00, 0xF8,0x01, 0x00,0x00, 0x00,0x00};  
00148 PT6964::DisplayData_t tst_str;  
00149 PT6964::DisplayData_t hello1_str = {0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x30,0x00, 0x00,0x00, 0x00,0x00};  
00150 PT6964::DisplayData_t hello2_str = {0x00,0x00, 0x00,0x00, 0x00,0x00, 0xE8,0x02, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
00151 PT6964::DisplayData_t hello3_str = {0x00,0x00, 0x00,0x00, 0x78,0x02, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
00152 PT6964::DisplayData_t hello4_str = {0x00,0x00, 0x30,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
00153 
00154 
00155 // KeyData_t size is 5 bytes  
00156 PT6964::KeyData_t keydata; 
00157 
00158 // PT6964 declaration, Default setting 7 Grids @ 10 Segments
00159 PT6964 PT6964(p5,p6,p7, p8);
00160 
00161 int main() {
00162     
00163     pc.printf("Hello World\r\n"); //    
00164     
00165     PT6964.cls(); 
00166     PT6964.writeData(all_str);
00167     wait(4);
00168     PT6964.setBrightness(PT6964_BRT3);    
00169     PT6964.writeData(mbed_str);    
00170     wait(1);
00171     PT6964.setBrightness(PT6964_BRT0);        
00172     wait(1);
00173     PT6964.setBrightness(PT6964_BRT3);            
00174     
00175     while (1) {
00176      
00177       // Check and read keydata
00178       if (PT6964.getKeys(&keydata)) {
00179         pc.printf("Keydata 0..4 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4]);
00180 
00181         if (keydata[0] == 0x01) { //sw1 L/R  
00182           PT6964.cls(); 
00183           PT6964.writeData(hello1_str);
00184                    
00185         }       
00186 
00187         if (keydata[0] == 0x02) { //sw2 Stop  
00188           PT6964.cls(); 
00189           PT6964.writeData(hello2_str);          
00190 
00191         }  
00192 
00193         if (keydata[0] == 0x08) { //sw4 Play   
00194           PT6964.cls(); 
00195           PT6964.writeData(hello3_str);          
00196          
00197         }       
00198 
00199         if (keydata[0] == 0x10) { //sw3 Open  
00200           PT6964.cls(); 
00201           PT6964.writeData(hello4_str);          
00202 
00203         }       
00204         
00205       } //if
00206 
00207       myled = !myled;
00208       wait(0.3);      
00209     } //while
00210 }
00211 #endif