xeye_ atsu / Mbed 2 deprecated SPIOLEDaitendo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // ALO-095BWNN-J9 test program
00002 // See also "http://www.aitendo.co.jp/product/2099"
00003 
00004 
00005 #include "mbed.h"
00006 #include "spioled.h"
00007 #define countof(x) ( sizeof(x) / sizeof(x[0]) )
00008 
00009 SPIOLED oled(p21, p22, p23, p5, p6, p7);    //cs res dc mosi miso sck
00010 
00011 bool kstate = false;
00012 unsigned int kbuf;
00013 unsigned char x_locale = 0;
00014 unsigned char y_locale = 0;
00015 
00016 
00017 unsigned int findface(unsigned short c){
00018     unsigned int p = 0;
00019     int i, sum;
00020     for(sum = i = 0; i < countof(font8table); i++){
00021         if(font8table[i].start <= c && c <= font8table[i].end){
00022             p = (sum + c - font8table[i].start);
00023             break;
00024         }
00025         sum += font8table[i].end - font8table[i].start + 1;
00026     }
00027     return p;
00028 }
00029 
00030 void drawc(unsigned char c){
00031     if(kstate){ // 2nd byte of shift-jis
00032         kstate = false;
00033         unsigned int p = findface(kbuf << 8 | c);
00034         oled.PutChar( x_locale , y_locale ,p);
00035         //   printf("%x %x\r\n",( kbuf << 8 | c),p); //for debug
00036         x_locale += X_Witch;
00037         if(x_locale + (X_Witch - 1) >= Dis_X_MAX){
00038             x_locale = 0;
00039             y_locale += Y_Witch;
00040             if(y_locale >= Dis_Y_MAX)y_locale=0;
00041         }
00042             
00043     } else if((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)){ // 1st byte of shift-jis
00044         kstate = true;
00045         kbuf = c;
00046     } else {        
00047         oled.PutChar_ABC( x_locale , y_locale ,c);
00048         x_locale += 6;
00049         if(x_locale + (X_Witch - 1) >= Dis_X_MAX){
00050             x_locale = 0;
00051             y_locale += Y_Witch;
00052             if(y_locale >= Dis_Y_MAX)y_locale=0;
00053         }
00054     }
00055        
00056 }
00057 
00058 void draws(unsigned char x, unsigned char y, char *s){
00059     unsigned char c;
00060     x_locale = x;
00061     y_locale = y;
00062     while((c = *s++) != '\0')drawc(c);
00063 }
00064     
00065     
00066     
00067 int main() {
00068     LocalFileSystem local( "local" );
00069     char            s[ 256 ];
00070     FILE            *fp;
00071 
00072     printf( "\r\nreading a message file.\r\n" );
00073 
00074     if ( NULL == (fp = fopen( "/local/test.txt", "r" )) ) {
00075         printf( "\r\nError: The message file cannot be accessed\r\n" );
00076         return -1;
00077     }
00078 
00079     fgets( s, 256, fp );
00080     fclose( fp );
00081     
00082       
00083 
00084    
00085 while(1){
00086   //  OLED_Init();
00087 
00088     oled.Full_Screen(0x0018);    //full red color in OLED
00089  //   wait_ms(500);
00090     oled.Full_Screen(0x07e0);    //full green color in OLED
00091  //   wait_ms(500);
00092     oled.Full_Screen(0xf800);    //full blue color in OLED
00093  //   wait_ms(500);
00094     oled.Full_Screen(0xffff);    //full white color in OLED
00095     wait_ms(500);
00096 
00097     
00098     
00099 
00100     oled.ChangeFontColor(0);
00101     draws(1,0,s);    
00102     wait_ms(5000);
00103     oled.Full_Screen(0);
00104     oled.ChangeFontColor(0xffff);
00105     draws(1,0,s);    
00106     wait_ms(5000);
00107     }
00108 }