P10
Embed:
(wiki syntax)
Show/hide line numbers
LED_P10.cpp
00001 #include "mbed.h" 00002 #include "Aerial_black_16.h" 00003 #include "double_font2.h" 00004 #include "led_half_1.h" 00005 #include "LED_P10.h" 00006 #include <string.h> 00007 00008 char * LedP10 :: msg=NULL; 00009 char * LedP10 :: msg1=NULL; 00010 char * LedP10 :: msg2=NULL; 00011 const uint8_t * LedP10 :: font_lib; 00012 uint8_t * LedP10 :: dislay[2]={NULL}; 00013 int LedP10 :: speed=5; 00014 int LedP10 :: font; 00015 int LedP10 :: filled=0; 00016 int LedP10 :: index=0; 00017 int LedP10 :: filled1=0; 00018 int LedP10 :: filled2=0; 00019 int LedP10 :: index1=0; 00020 int LedP10 :: index2=0; 00021 int LedP10 :: numberofpanels=1; 00022 int LedP10 :: buffersize=49; 00023 int LedP10 :: storepin =8; 00024 int LedP10 :: outputenablepin=9 ; 00025 int LedP10 :: b =4; 00026 int LedP10 :: a =3; 00027 int LedP10 :: scroll=-1; 00028 int LedP10 :: scroll1=-1; 00029 int LedP10 :: scroll2=-1; 00030 int LedP10 :: scrollcount=0; 00031 int LedP10 :: scrollcount1=0; 00032 int LedP10 :: scrollcount2=0; 00033 int LedP10 :: x=0; 00034 int LedP10 :: y=0; 00035 int LedP10 :: speed1=5; 00036 int LedP10 :: speed2=5; 00037 int LedP10 :: speedcount=0; 00038 int LedP10 :: speedcount1=0; 00039 int LedP10 :: speedcount2=0; 00040 int LedP10 :: always=1; 00041 int LedP10 :: always1=0; 00042 int LedP10 :: always2=1; 00043 uint8_t LedP10 :: brightness=255; 00044 LedP10 :: LedP10() 00045 {} 00046 void LedP10 :: init_internal() 00047 { 00048 00049 /* 00050 pinMode(outputenablepin,OUTPUT); 00051 pinMode(a,OUTPUT); 00052 pinMode(b,OUTPUT); 00053 pinMode(10,OUTPUT); 00054 00055 pinMode(storepin,OUTPUT); 00056 digitalWrite(a, LOW); 00057 digitalWrite(b, LOW); 00058 SPI.beginTransaction(SPISettings(1152000, MSBFIRST, SPI_MODE0)); 00059 SPI.begin(); 00060 digitalWrite(outputenablepin,LOW); 00061 scroll=-1; 00062 scroll1=-1; 00063 scroll2=-1; 00064 00065 */ 00066 } 00067 00068 void LedP10 :: store() 00069 { 00070 /* 00071 digitalWrite(storepin, HIGH); 00072 digitalWrite(storepin, LOW); 00073 00074 */ 00075 } 00076 00077 void LedP10 :: init(int A, int B, int store_pin, int oe, int no_of_panels) 00078 { 00079 a=A; 00080 b=B; 00081 storepin=store_pin; 00082 outputenablepin=oe; 00083 numberofpanels=no_of_panels; 00084 buffersize=17+numberofpanels*32; 00085 dislay[0]=(uint8_t *)malloc(buffersize*sizeof(uint8_t)); 00086 dislay[1]=(uint8_t *)malloc(buffersize*sizeof(uint8_t)); 00087 for(int i=0;i<buffersize;i++) 00088 { 00089 dislay[0][i]=0x00; 00090 dislay[1][i]=0x00; 00091 } 00092 LedP10 ::init_internal(); 00093 } 00094 void LedP10 :: filldisplaysingle_static() 00095 { 00096 filled=0; 00097 index=0; 00098 char nextchar; 00099 int no_of_char = pgm_read_byte_near(font_lib+5); 00100 int first_char = pgm_read_byte_near(font_lib+4); 00101 uint16_t widthpos,width,datapos; 00102 while(index!=strlen(msg)&&filled<32*numberofpanels) 00103 { 00104 nextchar=msg[index++]; 00105 widthpos= 6+nextchar-first_char; 00106 uint16_t sum=0; 00107 for(int i=0;i<nextchar-first_char;i++) 00108 { 00109 sum+= 2*pgm_read_byte_near(font_lib+6+i); 00110 } 00111 datapos= 6+no_of_char+sum; 00112 width=pgm_read_byte_near(font_lib+widthpos); 00113 if(filled+width+1<=32*numberofpanels) 00114 { 00115 word count=0; 00116 for(count=0;count<width;count++) 00117 { 00118 dislay[0][filled]=pgm_read_byte_near(font_lib+datapos+count); 00119 dislay[1][filled]=pgm_read_byte_near(font_lib+datapos+count+width); 00120 (filled)++; 00121 } 00122 dislay[0][filled]=0x00; 00123 dislay[1][filled]=0x00; 00124 (filled)++; 00125 } 00126 00127 } 00128 while(filled<32*numberofpanels) 00129 { 00130 dislay[0][filled]=0x00; 00131 dislay[1][filled]=0x00; 00132 (filled)++; 00133 } 00134 } 00135 00136 void LedP10 :: filldisplaysingle() 00137 { 00138 char nextchar; 00139 uint16_t widthpos,width,datapos; 00140 int no_of_char=pgm_read_byte_near(font_lib+5); 00141 int first_char = pgm_read_byte_near(font_lib+4); 00142 while(filled<buffersize&&(scroll>0||always==1)) 00143 { 00144 if(index==strlen(msg)) 00145 { 00146 scroll--; 00147 index=0; 00148 nextchar=' '; 00149 } 00150 else 00151 { 00152 nextchar=msg[index++]; 00153 } 00154 widthpos= 6+nextchar-first_char; 00155 uint16_t sum=0; 00156 for(int i=0;i<nextchar-first_char;i++) 00157 { 00158 sum+= 2*pgm_read_byte_near(font_lib+6+i); 00159 } 00160 datapos= 6+no_of_char+sum; 00161 width=pgm_read_byte_near(font_lib+widthpos); 00162 if(filled+width+1<=buffersize) 00163 { 00164 word count=0; 00165 for(count=0;count<width;count++) 00166 { 00167 dislay[0][filled]=pgm_read_byte_near(font_lib+datapos+count); 00168 dislay[1][filled]=pgm_read_byte_near(font_lib+datapos+count+width); 00169 (filled)++; 00170 } 00171 dislay[0][filled]=0x00; 00172 dislay[1][filled]=0x00; 00173 (filled)++; 00174 } 00175 else 00176 { 00177 if(index>0) 00178 index--; 00179 else 00180 { 00181 index=strlen(msg); 00182 scroll++; 00183 } 00184 break; 00185 } 00186 } 00187 } 00188 00189 void LedP10 :: filldisplaydouble_static() 00190 { 00191 filled1=0;filled2=0;index1=0;index2=0; 00192 char nextchar1,nextchar2; 00193 int no_of_char=pgm_read_byte_near(font_lib+5); 00194 int first_char = pgm_read_byte_near(font_lib+4); 00195 uint16_t widthpos1,width1,datapos1,widthpos2,width2,datapos2; 00196 while(index1!=strlen(msg1)&&filled1<32*numberofpanels) 00197 { 00198 nextchar1=msg1[index1++]; 00199 widthpos1= 6+nextchar1-first_char; 00200 uint16_t sum1=0; 00201 for(int i=0;i<nextchar1-first_char;i++) 00202 { 00203 sum1+= pgm_read_byte_near(font_lib+6+i); 00204 } 00205 datapos1= 6+no_of_char+sum1; 00206 width1=pgm_read_byte_near(font_lib+widthpos1); 00207 if(filled1+width1+1<=32*numberofpanels) 00208 { 00209 word count1=0; 00210 for(count1=0;count1<width1;count1++) 00211 { 00212 dislay[0][filled1]=pgm_read_byte_near(font_lib+datapos1+count1); 00213 (filled1)++; 00214 } 00215 dislay[0][filled1]=0x00; 00216 } 00217 00218 } 00219 while(filled1<32*numberofpanels) 00220 { 00221 dislay[0][filled1++]=0x00; 00222 } 00223 while(index2!=strlen(msg2)&&filled2<32*numberofpanels) 00224 { 00225 nextchar2=msg2[index2++]; 00226 widthpos2= 6+nextchar2-first_char; 00227 uint16_t sum2=0; 00228 for(int i=0;i<nextchar2-first_char;i++) 00229 { 00230 sum2+= pgm_read_byte_near(font_lib+6+i); 00231 } 00232 datapos2= 6+no_of_char+sum2; 00233 width2=pgm_read_byte_near(font_lib+widthpos2); 00234 if(filled2+width2+1<=32*numberofpanels) 00235 { 00236 word count2=0; 00237 for(count2=0;count2<width2;count2++) 00238 { 00239 dislay[1][filled2]=pgm_read_byte_near(font_lib+datapos2+count2); 00240 (filled2)++; 00241 } 00242 dislay[1][filled2++]=0x00; 00243 } 00244 00245 } 00246 while(filled2<32*numberofpanels) 00247 { 00248 dislay[1][filled2++]=0x00; 00249 } 00250 00251 } 00252 00253 00254 void LedP10 :: filldisplaydouble() 00255 { 00256 char nextchar1,nextchar2; 00257 uint16_t widthpos1,width1,datapos1,widthpos2,width2,datapos2; 00258 int no_of_char=pgm_read_byte_near(font_lib+5); 00259 int first_char = pgm_read_byte_near(font_lib+4); 00260 while(filled1<buffersize&&(scroll1>0||always1==1)) 00261 { 00262 if(index1==strlen(msg1)) 00263 { 00264 scroll1--; 00265 index1=0; 00266 nextchar1=' '; 00267 } 00268 else 00269 { 00270 nextchar1=msg1[index1++]; 00271 } 00272 widthpos1= 6+nextchar1-first_char; 00273 uint16_t sum1=0; 00274 for(int i=0;i<nextchar1-first_char;i++) 00275 { 00276 sum1+= pgm_read_byte_near(font_lib+6+i); 00277 } 00278 datapos1= 6+no_of_char+sum1; 00279 width1=pgm_read_byte_near(font_lib+widthpos1); 00280 if(filled1+width1+1<=buffersize) 00281 { 00282 word count1=0; 00283 for(count1=0;count1<width1;count1++) 00284 { 00285 dislay[0][filled1]=pgm_read_byte_near(font_lib+datapos1+count1); 00286 (filled1)++; 00287 } 00288 dislay[0][filled1]=0x00; 00289 (filled1)++; 00290 } 00291 else 00292 { 00293 if(index1>0) 00294 index1--; 00295 else 00296 { 00297 scroll1++; 00298 index1=strlen(msg1); 00299 } 00300 break; 00301 } 00302 } 00303 while(filled2<buffersize&&(scroll2>0||always2==1)) 00304 { 00305 if(index2==strlen(msg2)) 00306 { 00307 scroll2--; 00308 index2=0; 00309 nextchar2=' '; 00310 } 00311 else 00312 { 00313 nextchar2=msg2[index2++]; 00314 } 00315 widthpos2= 6+nextchar2-first_char; 00316 uint16_t sum2=0; 00317 for(int i=0;i<nextchar2-first_char;i++) 00318 { 00319 sum2+= pgm_read_byte_near(font_lib+6+i); 00320 } 00321 datapos2= 6+no_of_char+sum2; 00322 width2=pgm_read_byte_near(font_lib+widthpos2); 00323 if(filled2+width2+1<=buffersize) 00324 { 00325 word count2=0; 00326 for(count2=0;count2<width2;count2++) 00327 { 00328 dislay[1][filled2]=pgm_read_byte_near(font_lib+datapos2+count2); 00329 (filled2)++; 00330 } 00331 dislay[1][filled2]=0x00; 00332 (filled2)++; 00333 } 00334 else 00335 { 00336 if(index2>0) 00337 index2--; 00338 else 00339 { 00340 index2=strlen(msg2); 00341 scroll2++; 00342 } 00343 break; 00344 } 00345 } 00346 } 00347 00348 void LedP10 :: slide() 00349 { 00350 int i; 00351 if(speed1!=0) 00352 { 00353 speedcount1++; 00354 if(speedcount1==30/speed1) 00355 { 00356 speedcount1=0; 00357 for(i=0;i<buffersize-1 ;i++) 00358 { 00359 dislay[0][i]= dislay[0][i+1]; 00360 } 00361 filled1--; 00362 } 00363 } 00364 if(speed2!=0) 00365 { 00366 speedcount2++; 00367 if(speedcount2==30/speed2) 00368 { 00369 speedcount2=0; 00370 for(i=0;i<buffersize-1 ;i++) 00371 { 00372 dislay[1][i]= dislay[1][i+1]; 00373 } 00374 filled2--; 00375 } 00376 } 00377 00378 //if(speed1==speed2&&speed1!=0) 00379 filled--; 00380 } 00381 00382 void LedP10 ::slidesingle() 00383 { 00384 int i; 00385 if(speed!=0) 00386 { 00387 speedcount++; 00388 if(speedcount==30/speed) 00389 { 00390 speedcount=0; 00391 for(i=0;i<buffersize-1 ;i++) 00392 { 00393 dislay[0][i]= dislay[0][i+1]; 00394 dislay[1][i]= dislay[1][i+1]; 00395 } 00396 filled--; 00397 } 00398 } 00399 else 00400 { 00401 speedcount++; 00402 if(speedcount==30/speed) 00403 { 00404 speedcount=0; 00405 for(i=0;i<buffersize-1 ;i++) 00406 { 00407 dislay[0][i]= dislay[0][i]; 00408 dislay[1][i]= dislay[1][i]; 00409 } 00410 filled--; 00411 } 00412 } 00413 } 00414 void LedP10 :: showgroup(int p,int q) 00415 { 00416 int i,j,k,row,col,byt; 00417 byte temp,data=0x00; 00418 for(col=0;col<4*numberofpanels;col++) 00419 { 00420 row=12+p+2*q; 00421 byt=row/8; 00422 for(i=0;i<4;i++) 00423 { 00424 data=0x00; 00425 for(k=0;k<8;k++) 00426 { 00427 data=data<<1; 00428 temp=0x01; 00429 temp&=(dislay[row/8][8*col+k]>>(row%8)); 00430 data|=temp; 00431 } 00432 row-=4; 00433 byt=row/8; 00434 SPI.transfer(~data); 00435 } 00436 } 00437 digitalWrite(outputenablepin,LOW); 00438 LedP10 ::store(); 00439 } 00440 00441 void LedP10 :: showmsg_single_scroll(char msg_[],int no_of_times, int speed_, int font_) 00442 { 00443 if(font_==0) 00444 font_lib=Arial_Black_16; 00445 else if(font_==1) 00446 font_lib=Arial_14; 00447 scroll= no_of_times; 00448 msg=msg_; 00449 speed=speed_; 00450 speed1=speed; 00451 speed2=speed; 00452 speedcount1=0; 00453 speedcount2=0; 00454 font=font_; 00455 if(no_of_times<0) 00456 always=1; 00457 else 00458 always=0; 00459 Timer1.initialize(100); 00460 Timer1.attachInterrupt(callback4); 00461 } 00462 00463 00464 00465 void LedP10 :: callback() 00466 { 00467 digitalWrite(outputenablepin,LOW); 00468 LedP10 ::filldisplaysingle_static(); 00469 LedP10 ::showone(); 00470 00471 } 00472 void LedP10 :: callback2() 00473 { 00474 digitalWrite(outputenablepin,LOW); 00475 LedP10 ::filldisplaydouble_static(); 00476 LedP10 ::showone(); 00477 00478 } 00479 void LedP10 :: showone() 00480 { 00481 if(x==0&&y==0) 00482 { 00483 LedP10 ::showgroup(0,0); 00484 digitalWrite(a,LOW); 00485 digitalWrite(b,LOW); 00486 analogWrite(outputenablepin, brightness); 00487 x=1;y=0; 00488 } 00489 else if(x==1&&y==0) 00490 { 00491 LedP10 ::showgroup(1,0); 00492 digitalWrite(a,HIGH); 00493 digitalWrite(b,LOW); 00494 analogWrite(outputenablepin,brightness); 00495 x=0;y=1; 00496 } 00497 else if(x==0&&y==1) 00498 { 00499 LedP10 ::showgroup(0,1); 00500 digitalWrite(a,LOW); 00501 digitalWrite(b,HIGH); 00502 analogWrite(outputenablepin,brightness); 00503 x=1;y=1; 00504 } 00505 else if(x==1&&y==1) 00506 { 00507 LedP10 ::showgroup(1,1); 00508 digitalWrite(a,HIGH); 00509 digitalWrite(b,HIGH); 00510 analogWrite(outputenablepin, brightness); 00511 x=0;y=0; 00512 } 00513 } 00514 void LedP10 :: showmsg_single_static(long int msg_,int font_) 00515 { 00516 String thisString1 = String(msg_); 00517 thisString1.toCharArray(sts_dis,thisString1.length()+1); 00518 //free(&thisString1); 00519 //showmsg_single_static(newmsg1,font_); 00520 digitalWrite(outputenablepin,LOW); 00521 Timer1.stop(); 00522 if(font_==0) 00523 font_lib=Arial_Black_16; 00524 else if(font_==1) 00525 font_lib=Arial_14; 00526 msg=sts_dis; 00527 font=font_; 00528 filled=0; 00529 Timer1.initialize(5500); 00530 Timer1.attachInterrupt(callback); 00531 LedP10 ::filldisplaysingle_static(); 00532 } 00533 00534 00535 00536 void LedP10 :: showmsg_single_static(char msg_[],int font_) 00537 { 00538 digitalWrite(outputenablepin,LOW); 00539 Timer1.stop(); 00540 if(font_==0) 00541 font_lib=Arial_Black_16; 00542 else if(font_==1) 00543 font_lib=Arial_14; 00544 msg=msg_; 00545 font=font_; 00546 filled=0; 00547 Timer1.initialize(5500); 00548 Timer1.attachInterrupt(callback); 00549 LedP10 ::filldisplaysingle_static(); 00550 } 00551 void LedP10 :: showmsg_double_static(long int msg1_,long int msg2_,int font_) 00552 { 00553 String thisString1 = String(msg1_); 00554 thisString1.toCharArray(sts_dis1,thisString1.length()+1); 00555 String thisString2 = String(msg2_); 00556 thisString2.toCharArray(sts_dis2,thisString2.length()+1); 00557 showmsg_double_static(sts_dis1,sts_dis2, font_); 00558 } 00559 00560 void LedP10 :: showmsg_double_static(long int msg1_,char msg2_[],int font_) 00561 { 00562 String thisString1 = String(msg1_); 00563 thisString1.toCharArray(sts_dis1,thisString1.length()+1); 00564 00565 showmsg_double_static(sts_dis1,msg2_, font_); 00566 } 00567 00568 void LedP10 :: showmsg_double_static(char msg1_[],long int msg2_,int font_) 00569 { 00570 String thisString2 = String(msg2_); 00571 thisString2.toCharArray(sts_dis2,thisString2.length()+1); 00572 showmsg_double_static(msg1_,sts_dis2, font_); 00573 } 00574 void LedP10 :: showmsg_double_static(char msg1_[],char msg2_[],int font_) 00575 { 00576 digitalWrite(outputenablepin,LOW); 00577 Timer1.stop(); 00578 if(font_==0) 00579 font_lib=font_lib=Led_half_1; 00580 else if(font_==1) 00581 {} 00582 msg1=msg1_; 00583 msg2=msg2_; 00584 font=font_; 00585 filled1=0; 00586 filled2=0; 00587 Timer1.initialize(6500); 00588 Timer1.attachInterrupt(callback2); 00589 LedP10 ::filldisplaydouble_static(); 00590 } 00591 void LedP10 :: callback3() 00592 { 00593 00594 LedP10 ::showone(); 00595 if(x==1&&y==1) 00596 LedP10 ::slide(); 00597 LedP10 ::filldisplaydouble(); 00598 00599 if(filled1==0&&filled2==0&&scroll1==0&&scroll2==0) 00600 { 00601 digitalWrite(outputenablepin,LOW); 00602 Timer1.stop(); 00603 } 00604 } 00605 void LedP10 :: callback4() 00606 { 00607 00608 LedP10 ::showone(); 00609 if(x==1&&y==1) 00610 { 00611 LedP10 ::slidesingle(); 00612 } 00613 00614 filldisplaysingle(); 00615 00616 if(filled==0&&scroll==0) 00617 { 00618 digitalWrite(outputenablepin,LOW); 00619 Timer1.stop(); 00620 } 00621 } 00622 void LedP10 :: showmsg_double_scroll(char msg1_[],char msg2_[],int no_of_times1,int no_of_times2, int speed1_,int speed2_, int font_) 00623 { 00624 if(font_==0) 00625 font_lib=font_lib=Led_half_1; 00626 else if(font_==1) 00627 {} 00628 msg1=msg1_; 00629 msg2=msg2_; 00630 speed1=speed1_; 00631 speed2=speed2_; 00632 font=font_; 00633 scroll1= no_of_times1; 00634 scroll2= no_of_times2; 00635 if(scroll1<0) 00636 always1=1; 00637 else 00638 always1=0; 00639 if(scroll2<0) 00640 always2=1; 00641 else 00642 always2=0; 00643 LedP10 ::filldisplaydouble(); 00644 Timer1.initialize(100); 00645 Timer1.attachInterrupt(callback3); 00646 } 00647 00648 void LedP10 :: setbrightness(uint8_t brightness_) 00649 { 00650 brightness=brightness_; 00651 }
Generated on Tue Jul 12 2022 22:15:01 by
1.7.2