Toyomasa Watarai / Mbed 2 deprecated LEDMatrix_Master

Dependencies:   mbed

Fork of LEDMatrix_Master by en 129

Revision:
6:bfd5c9d80f48
Parent:
4:70a1803901d1
--- a/15x16fontsLib.cpp	Thu Nov 14 07:39:19 2013 +0000
+++ b/15x16fontsLib.cpp	Sat Nov 16 05:16:19 2013 +0000
@@ -19,7 +19,7 @@
     MSB = seq / 94 + 1;
     LSB = seq % 94 + 1;
     Address = 0;
-        
+    
     if(     MSB >=  1 && MSB <= 15 && LSB >= 1 && LSB <= 94)
         Address =( (MSB -  1) * 94 + (LSB - 1))*32;
     else if(MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94)
@@ -31,6 +31,16 @@
     else if(MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94)
         Address = ((MSB - 88) * 94 + (LSB - 1))*32 + 0x3D060L;
     
+    // if ASCII code
+    int font_width;
+    if(code >= 0x20 && code <= 0x7F) {
+        Address = (code - 0x20)*16 + 255968;
+        font_width = 8;
+    }
+    else {
+        font_width = 16;
+    }
+
     // Deselect the device
     FontROM_CS = 1;
 
@@ -46,36 +56,35 @@
     FontROM.write(Address & 0xff);
     
     // Send a dummy byte to receive the contents of the WHOAMI register
-    for(int i=0; i<32; i++)
+    for(int i=0; i<(font_width*2); i++)
     {
-      matrixdata[i]=FontROM.write(0x00);
+        matrixdata[i]=FontROM.write(0x00);
     }
 
     // Deselect the device
     FontROM_CS = 1;
 }
 
-void draw_kanji_15x16(int pos_x,unsigned char color)
+void draw_kanji_15x16(int pos_x,unsigned char color, int font_width)
 {
-    int i = 0;
-    for(i=0;i<16;i++)
+    for(int i=0; i<font_width; i++)
     {
         if( ((signed int)(15-i+pos_x) >= 0) && ((15-i+pos_x) <= (DISPLAY_XSIZE-1)) )
         {
             if(color == COLOR_G || color == COLOR_C || color == COLOR_Y || color == COLOR_W)
             {
                 ImageBuf[0][15-i+pos_x] =  matrixdata[i];
-                ImageBuf[0][15-i+pos_x] |= matrixdata[i+16]<<8;
+                ImageBuf[0][15-i+pos_x] |= matrixdata[i+font_width]<<8;
             }
             if(color == COLOR_R || color == COLOR_Y || color == COLOR_M || color == COLOR_W)
             {
                 ImageBuf[1][15-i+pos_x] =  matrixdata[i];
-                ImageBuf[1][15-i+pos_x] |= matrixdata[i+16]<<8;
+                ImageBuf[1][15-i+pos_x] |= matrixdata[i+font_width]<<8;
             }
             if(color == COLOR_B || color == COLOR_C || color == COLOR_M || color == COLOR_W)
             {
                 ImageBuf[2][15-i+pos_x] =  matrixdata[i];
-                ImageBuf[2][15-i+pos_x] |= matrixdata[i+16]<<8;
+                ImageBuf[2][15-i+pos_x] |= matrixdata[i+font_width]<<8;
             }
         }
     }
@@ -102,18 +111,18 @@
             SJISChar = (SJISChar<<8) | c;
             f_SJISChar = 0;
             read_font(SJISChar);
-            draw_kanji_15x16(pos_x-CountChar*16,color);
-            CountChar++;
+            draw_kanji_15x16(pos_x-CountChar*8, color, 16);
+            CountChar+=2;
         }
         else  //ASCII文字
         {
             SJISChar = c;
             f_SJISChar = 0;
             read_font(SJISChar);
-            draw_kanji_15x16(pos_x-CountChar*16,color);
+            draw_kanji_15x16(pos_x-CountChar*8, color, 8);
             CountChar++;
         }
         str++;
         c = *str;
     }
-}
\ No newline at end of file
+}