.
Dependencies: BurstSPI EaEpaper mbed
Fork of epaper_mbed_130411_KL25Z by
main.cpp@4:05cb9a1b60ca, 2015-09-22 (annotated)
- Committer:
- Jamestom999
- Date:
- Tue Sep 22 11:04:06 2015 +0000
- Revision:
- 4:05cb9a1b60ca
- Parent:
- 3:6ab30c065d39
Stick It Demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:057244fcbbb6 | 1 | #include "mbed.h" |
dreschpe | 0:057244fcbbb6 | 2 | #include "EaEpaper.h" |
Jamestom999 | 4:05cb9a1b60ca | 3 | #include "Arial37x36.h" |
dreschpe | 0:057244fcbbb6 | 4 | #include "graphics.h" |
dreschpe | 0:057244fcbbb6 | 5 | |
Jamestom999 | 4:05cb9a1b60ca | 6 | #define epaper_width 264 |
Jamestom999 | 4:05cb9a1b60ca | 7 | #define epaper_hight 176 |
Jamestom999 | 4:05cb9a1b60ca | 8 | #define line_hight 40 |
Jamestom999 | 4:05cb9a1b60ca | 9 | #define text_field 240 |
Jamestom999 | 4:05cb9a1b60ca | 10 | #define ASCII_offset 32 |
Jamestom999 | 4:05cb9a1b60ca | 11 | |
Jamestom999 | 4:05cb9a1b60ca | 12 | int LineWrap(char* buff); |
Jamestom999 | 4:05cb9a1b60ca | 13 | char* BluetoothRecive(void); |
Jamestom999 | 4:05cb9a1b60ca | 14 | |
Jamestom999 | 4:05cb9a1b60ca | 15 | char line[4][40]; |
Jamestom999 | 4:05cb9a1b60ca | 16 | int indent[4]; |
Jamestom999 | 4:05cb9a1b60ca | 17 | |
Jamestom999 | 4:05cb9a1b60ca | 18 | EaEpaper epaper(p19, // PWR_CTRL |
Jamestom999 | 4:05cb9a1b60ca | 19 | p20, // BORDER |
Jamestom999 | 4:05cb9a1b60ca | 20 | p11, // DISCHARGE |
Jamestom999 | 4:05cb9a1b60ca | 21 | p12, // RESET_DISP |
Jamestom999 | 4:05cb9a1b60ca | 22 | p13, // BUSY |
Jamestom999 | 4:05cb9a1b60ca | 23 | p8 , // SSEL |
Jamestom999 | 4:05cb9a1b60ca | 24 | p26, // PWM |
Jamestom999 | 4:05cb9a1b60ca | 25 | p5,p6,p7, // MOSI,MISO,SCLK |
Jamestom999 | 4:05cb9a1b60ca | 26 | p28,p27); // SDA,SCL |
Jamestom999 | 4:05cb9a1b60ca | 27 | |
Jamestom999 | 4:05cb9a1b60ca | 28 | DigitalOut Flash_CS(p25); //Flash Select |
Jamestom999 | 4:05cb9a1b60ca | 29 | DigitalOut Screen_CS(p8 ); //Screen Select |
Jamestom999 | 4:05cb9a1b60ca | 30 | DigitalOut led (p23); //On board LED |
Jamestom999 | 4:05cb9a1b60ca | 31 | |
Jamestom999 | 4:05cb9a1b60ca | 32 | Serial Bluetooth(p9, p10); // tx, rx |
Jamestom999 | 4:05cb9a1b60ca | 33 | Serial Terminal (USBTX, USBRX);// tx, rx |
Jamestom999 | 4:05cb9a1b60ca | 34 | |
dreschpe | 0:057244fcbbb6 | 35 | int main() { |
Jamestom999 | 4:05cb9a1b60ca | 36 | int n, lineNumber; |
Jamestom999 | 4:05cb9a1b60ca | 37 | Flash_CS =1; |
Jamestom999 | 4:05cb9a1b60ca | 38 | Screen_CS=0; |
Jamestom999 | 4:05cb9a1b60ca | 39 | led =1; |
Jamestom999 | 4:05cb9a1b60ca | 40 | Bluetooth.baud(115200); |
Jamestom999 | 4:05cb9a1b60ca | 41 | Terminal .baud(115200); |
Jamestom999 | 4:05cb9a1b60ca | 42 | |
Jamestom999 | 4:05cb9a1b60ca | 43 | epaper.cls(); //Display the logo |
Jamestom999 | 4:05cb9a1b60ca | 44 | epaper.print_bm(bitmLogo,5,30); |
Jamestom999 | 4:05cb9a1b60ca | 45 | epaper.write_disp(); |
Jamestom999 | 4:05cb9a1b60ca | 46 | |
Jamestom999 | 4:05cb9a1b60ca | 47 | while(1){ |
Jamestom999 | 4:05cb9a1b60ca | 48 | lineNumber=LineWrap(BluetoothRecive()); //Wait and recive a string. Word wrap the string so that it fits to the screen |
Jamestom999 | 4:05cb9a1b60ca | 49 | epaper.cls(); //Clear screen buffer |
Jamestom999 | 4:05cb9a1b60ca | 50 | epaper.set_font((unsigned char*) Arial37x36);//Set font |
Jamestom999 | 4:05cb9a1b60ca | 51 | for(n=0;n<lineNumber;n++){ |
Jamestom999 | 4:05cb9a1b60ca | 52 | epaper.locate(indent[n], (epaper_hight-line_hight*(lineNumber-n*2))/2); |
Jamestom999 | 4:05cb9a1b60ca | 53 | epaper.printf(line[n]); //Write to screen buffer |
Jamestom999 | 4:05cb9a1b60ca | 54 | } |
Jamestom999 | 4:05cb9a1b60ca | 55 | epaper.write_disp(); //Display screen buffer |
Jamestom999 | 4:05cb9a1b60ca | 56 | } |
Jamestom999 | 4:05cb9a1b60ca | 57 | } |
dreschpe | 0:057244fcbbb6 | 58 | |
Jamestom999 | 4:05cb9a1b60ca | 59 | char* BluetoothRecive(void){ |
Jamestom999 | 4:05cb9a1b60ca | 60 | int n=0; |
Jamestom999 | 4:05cb9a1b60ca | 61 | char buff[200]; |
Jamestom999 | 4:05cb9a1b60ca | 62 | while(1){ |
Jamestom999 | 4:05cb9a1b60ca | 63 | while(!Bluetooth.readable()){} //Waits for char |
Jamestom999 | 4:05cb9a1b60ca | 64 | buff[n]=Bluetooth.getc(); //Saves char to array |
Jamestom999 | 4:05cb9a1b60ca | 65 | if(buff[n]==0){ //Detects end of string |
Jamestom999 | 4:05cb9a1b60ca | 66 | break; |
Jamestom999 | 4:05cb9a1b60ca | 67 | } |
Jamestom999 | 4:05cb9a1b60ca | 68 | n++; |
Jamestom999 | 4:05cb9a1b60ca | 69 | } |
Jamestom999 | 4:05cb9a1b60ca | 70 | return buff; |
Jamestom999 | 4:05cb9a1b60ca | 71 | } |
Jamestom999 | 4:05cb9a1b60ca | 72 | |
Jamestom999 | 4:05cb9a1b60ca | 73 | int LineWrap(char* buff){ |
Jamestom999 | 4:05cb9a1b60ca | 74 | int Old_Pix_Length, Pix_Length, Old_Char_Length, Char_Length, end_flag, lineNumber, words, wordCount, Offset; |
Jamestom999 | 4:05cb9a1b60ca | 75 | end_flag=0; //used for an end of string case. |
Jamestom999 | 4:05cb9a1b60ca | 76 | lineNumber=0; |
Jamestom999 | 4:05cb9a1b60ca | 77 | Offset=0; |
Jamestom999 | 4:05cb9a1b60ca | 78 | |
Jamestom999 | 4:05cb9a1b60ca | 79 | while(!end_flag && lineNumber<4){ //Loop for 4 lines or untill the end of string |
dreschpe | 0:057244fcbbb6 | 80 | |
Jamestom999 | 4:05cb9a1b60ca | 81 | //===================================================Find the number of words that can fit on a line================================================== |
Jamestom999 | 4:05cb9a1b60ca | 82 | words =0; |
Jamestom999 | 4:05cb9a1b60ca | 83 | Pix_Length=0; |
Jamestom999 | 4:05cb9a1b60ca | 84 | while(Pix_Length<text_field && !end_flag){ //check the size of strings with increasing word lengths. When the size is larger than the screen then stop |
Jamestom999 | 4:05cb9a1b60ca | 85 | words++; |
Jamestom999 | 4:05cb9a1b60ca | 86 | Old_Pix_Length=Pix_Length; //Save privious values of Pix and Char |
Jamestom999 | 4:05cb9a1b60ca | 87 | Old_Char_Length=Char_Length; |
Jamestom999 | 4:05cb9a1b60ca | 88 | Pix_Length =0; |
Jamestom999 | 4:05cb9a1b60ca | 89 | wordCount =0; |
Jamestom999 | 4:05cb9a1b60ca | 90 | Char_Length=0; |
Jamestom999 | 4:05cb9a1b60ca | 91 | //----------------Find the length of a string with a number of words---------------- |
Jamestom999 | 4:05cb9a1b60ca | 92 | while(wordCount<words && !end_flag){ |
Jamestom999 | 4:05cb9a1b60ca | 93 | if(buff[Offset+Char_Length]==0){ //Handle with an end of string case |
Jamestom999 | 4:05cb9a1b60ca | 94 | if(Pix_Length<text_field){ //Ignore the end of string case if the string is too big to fit on the screen. |
Jamestom999 | 4:05cb9a1b60ca | 95 | Old_Pix_Length=Pix_Length; //Update the Pix and Char lengths |
Jamestom999 | 4:05cb9a1b60ca | 96 | Old_Char_Length=Char_Length+1; |
Jamestom999 | 4:05cb9a1b60ca | 97 | end_flag=1; //Set flag |
Jamestom999 | 4:05cb9a1b60ca | 98 | } |
Jamestom999 | 4:05cb9a1b60ca | 99 | }else{ //If its not the end of the string, add on the size of the current char and copy it to the "line" array |
Jamestom999 | 4:05cb9a1b60ca | 100 | Pix_Length+=Arial37x36Size[buff[Offset+Char_Length]-ASCII_offset]; |
Jamestom999 | 4:05cb9a1b60ca | 101 | line[lineNumber][Char_Length]=buff[Offset+Char_Length]; |
Jamestom999 | 4:05cb9a1b60ca | 102 | } |
Jamestom999 | 4:05cb9a1b60ca | 103 | |
Jamestom999 | 4:05cb9a1b60ca | 104 | if(buff[Offset+Char_Length]==' '){ //A SPACE indicates the end of a word |
Jamestom999 | 4:05cb9a1b60ca | 105 | wordCount++; |
Jamestom999 | 4:05cb9a1b60ca | 106 | } |
Jamestom999 | 4:05cb9a1b60ca | 107 | Char_Length++; |
Jamestom999 | 4:05cb9a1b60ca | 108 | } |
Jamestom999 | 4:05cb9a1b60ca | 109 | Pix_Length-=Arial37x36Size[' '-ASCII_offset];//Remove the last SPACE from the string length |
Jamestom999 | 4:05cb9a1b60ca | 110 | //---------------------------------------------------------------------------------- |
Jamestom999 | 4:05cb9a1b60ca | 111 | } |
Jamestom999 | 4:05cb9a1b60ca | 112 | //==================================================================================================================================================== |
Jamestom999 | 4:05cb9a1b60ca | 113 | |
Jamestom999 | 4:05cb9a1b60ca | 114 | line[lineNumber][Old_Char_Length-1]='\0'; //Add a NULL char to the end of string |
Jamestom999 | 4:05cb9a1b60ca | 115 | indent[lineNumber]=(epaper_width-Old_Pix_Length)/2; //Indent so that the string is in the middle of the screen |
Jamestom999 | 4:05cb9a1b60ca | 116 | |
Jamestom999 | 4:05cb9a1b60ca | 117 | Offset+=Old_Char_Length; //Increment the offset so that the next line continues from the previous line |
Jamestom999 | 4:05cb9a1b60ca | 118 | lineNumber++; |
Jamestom999 | 4:05cb9a1b60ca | 119 | } |
dreschpe | 0:057244fcbbb6 | 120 | |
Jamestom999 | 4:05cb9a1b60ca | 121 | return lineNumber; |
Jamestom999 | 4:05cb9a1b60ca | 122 | } |