[388] | 1 | /*
|
---|
| 2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2018 Cores Co., Ltd. Japan
|
---|
| 5 | *
|
---|
| 6 | * ä¸è¨èä½æ¨©è
|
---|
| 7 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 8 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 9 | * å¤ã»åé
|
---|
| 10 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 11 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 12 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 13 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 14 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 15 | * ç¨ã§ããå½¢ã§åé
|
---|
| 16 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 17 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 18 | * è
|
---|
| 19 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 20 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 21 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 22 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 23 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 24 | * ã¨ï¼
|
---|
| 25 | * (a) åé
|
---|
| 26 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 27 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 28 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 29 | * (b) åé
|
---|
| 30 | å¸ã®å½¢æ
|
---|
| 31 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 32 | * å ±åãããã¨ï¼
|
---|
| 33 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 34 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 35 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 36 | 責ãããã¨ï¼
|
---|
| 37 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 38 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 39 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 40 | * å
|
---|
| 41 | 責ãããã¨ï¼
|
---|
| 42 | *
|
---|
| 43 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 44 | ã
|
---|
| 45 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 46 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 47 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 48 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: draw_font.c 388 2019-05-22 11:25:18Z coas-nagasima $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | #include <kernel.h>
|
---|
| 54 | #include <t_syslog.h>
|
---|
| 55 | #include <t_stdlib.h>
|
---|
| 56 | #include <string.h>
|
---|
| 57 | #include <target_syssvc.h>
|
---|
| 58 | #include <time.h>
|
---|
| 59 | #include "adafruit_ssd1306.h"
|
---|
| 60 | #include "draw_font.h"
|
---|
| 61 |
|
---|
| 62 | void get_bitmap_font(const uint8_t *string, uint8_t *bitmap_data, uint32_t *use_chars)
|
---|
| 63 | {
|
---|
| 64 | uint32_t len, code;
|
---|
| 65 | uint8_t i, j, k;
|
---|
| 66 | uint32_t totalj, totalk;
|
---|
| 67 |
|
---|
| 68 | *use_chars = 0;
|
---|
| 69 | len = 0;
|
---|
| 70 | if ((string[0] & 0x80) == 0) { len = 1; }
|
---|
| 71 | else if ((string[0] & 0xE0) == 0xC0) { len = 2; }
|
---|
| 72 | else if ((string[0] & 0xF0) == 0xE0) { len = 3; }
|
---|
| 73 | else if ((string[0] & 0xF8) == 0xF0) { len = 4; }
|
---|
| 74 | else { return; }
|
---|
| 75 |
|
---|
| 76 | j = k = totalj = totalk = 0;
|
---|
| 77 |
|
---|
| 78 | if (len == 1) {
|
---|
| 79 | code = string[0];
|
---|
| 80 | memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 81 | *use_chars = 1;
|
---|
| 82 | return;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | if (len == 2) {
|
---|
| 86 | code = string[0];
|
---|
| 87 | // 1ãã¤ãç®ãµã¼ã
|
---|
| 88 | for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) {
|
---|
| 89 | if (Utf8CodeTable_2B_1st[i][0] == code) {
|
---|
| 90 | code = string[1];
|
---|
| 91 | for (j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++) {
|
---|
| 92 | if (UTF8_2B_CODE_BITMAP[totalk].code == code) {
|
---|
| 93 | memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 94 | *use_chars = 2;
|
---|
| 95 | return;
|
---|
| 96 | }
|
---|
| 97 | totalk++;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | else {
|
---|
| 101 | totalk += Utf8CodeTable_2B_1st[i][1];
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | return;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | if (len == 3) {
|
---|
| 108 | code = string[0];
|
---|
| 109 | // 1ãã¤ãç®ãµã¼ã
|
---|
| 110 | for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) {
|
---|
| 111 | if (Utf8CodeTable_3B_1st[i][0] == code) {
|
---|
| 112 | code = string[1];
|
---|
| 113 | // 2ãã¤ãç®ãµã¼ã
|
---|
| 114 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
| 115 | if (Utf8CodeTable_3B_2nd[totalj][0] == code) {
|
---|
| 116 | code = string[2];
|
---|
| 117 | // 3ãã¤ãç®ãµã¼ã
|
---|
| 118 | for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
|
---|
| 119 | if (UTF8_3B_CODE_BITMAP[totalk].code == code) {
|
---|
| 120 | memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 121 | *use_chars = 3;
|
---|
| 122 | return;
|
---|
| 123 | }
|
---|
| 124 | totalk++;
|
---|
| 125 | }
|
---|
| 126 | return;
|
---|
| 127 | }
|
---|
| 128 | else {/*èªã¿é£ã°ãbitmapåæ°ãèç©*/
|
---|
| 129 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
| 130 | }
|
---|
| 131 | totalj++;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | else {/*èªã¿é£ã°ãbitmapåæ°ãèç©*/
|
---|
| 135 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
| 136 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
| 137 | totalj++;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | return;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | void lcd_drawFont(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
|
---|
| 146 | {
|
---|
| 147 | int i, j, b;
|
---|
| 148 | uint8_t *bitmap = bitmap_data;
|
---|
| 149 |
|
---|
| 150 | b = 0x80;
|
---|
| 151 | for (i = 0; i < FONT_HEIGHT; i++) {
|
---|
| 152 | for (j = 0; j < FONT_WIDTH; j++) {
|
---|
| 153 | if ((*bitmap & b) != 0) {
|
---|
| 154 | lcd_drawPixel(hlcd, x + j, y + i, color);
|
---|
| 155 | }
|
---|
| 156 | else {
|
---|
| 157 | lcd_drawPixel(hlcd, x + j, y + i, back_color);
|
---|
| 158 | }
|
---|
| 159 | b >>= 1;
|
---|
| 160 | if (b == 0) {
|
---|
| 161 | b = 0x80;
|
---|
| 162 | bitmap++;
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | void lcd_drawFontHalf(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
|
---|
| 169 | {
|
---|
| 170 | int i, j, b;
|
---|
| 171 | uint8_t *bitmap = bitmap_data;
|
---|
| 172 |
|
---|
| 173 | b = 0x80;
|
---|
| 174 | for (i = 0; i < FONT_HEIGHT; i++) {
|
---|
| 175 | for (j = 0; j < FONT_HALF_WIDTH; j++) {
|
---|
| 176 | if ((*bitmap & b) != 0) {
|
---|
| 177 | lcd_drawPixel(hlcd, x + j, y + i, color);
|
---|
| 178 | }
|
---|
| 179 | else {
|
---|
| 180 | lcd_drawPixel(hlcd, x + j, y + i, back_color);
|
---|
| 181 | }
|
---|
| 182 | b >>= 1;
|
---|
| 183 | if (b == 0) {
|
---|
| 184 | b = 0x80;
|
---|
| 185 | bitmap++;
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | void lcd_drawString(LCD_Handler_t *hlcd, const char *string, int x, int y, uint16_t color, uint16_t back_color)
|
---|
| 192 | {
|
---|
| 193 | uint32_t current_top, use_chars, for_3B_hankaku_code;
|
---|
| 194 | uint8_t bitmap_data[FONT_WIDTH * FONT_HEIGHT / 8], ctrl_code;
|
---|
| 195 | int local_x, local_y, len = strlen(string);
|
---|
| 196 | const uint8_t *code = (const uint8_t *)string;
|
---|
| 197 |
|
---|
| 198 | local_x = x;
|
---|
| 199 | local_y = y;
|
---|
| 200 |
|
---|
| 201 | current_top = 0;
|
---|
| 202 | while (current_top < len) {
|
---|
| 203 | memset(bitmap_data, 0x0, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 204 | ctrl_code = code[current_top];
|
---|
| 205 | get_bitmap_font(&code[current_top], bitmap_data, &use_chars);
|
---|
| 206 | if (use_chars == 0)
|
---|
| 207 | return;
|
---|
| 208 |
|
---|
| 209 | //3ãã¤ãã³ã¼ãåè§æåç¨
|
---|
| 210 | if (use_chars == 3) {
|
---|
| 211 | for_3B_hankaku_code = 0;
|
---|
| 212 | for_3B_hankaku_code = ((code[current_top] << 16) |
|
---|
| 213 | (code[current_top + 1] << 8) |
|
---|
| 214 | (code[current_top + 2]));
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | current_top += use_chars;
|
---|
| 218 |
|
---|
| 219 | //1ãã¤ãã³ã¼ãåè§æå
|
---|
| 220 | if (use_chars == 1) {
|
---|
| 221 | if (ctrl_code == 0x0D) { // CR
|
---|
| 222 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
| 223 | continue;
|
---|
| 224 | }
|
---|
| 225 | if (ctrl_code == 0x0A) { // LF
|
---|
| 226 | local_y = local_y + FONT_HEIGHT;
|
---|
| 227 | continue;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
| 231 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
| 232 | local_y = local_y + FONT_HEIGHT;
|
---|
| 233 | }
|
---|
| 234 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
| 235 | local_x += FONT_HALF_WIDTH;
|
---|
| 236 | continue;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | //3ãã¤ãã³ã¼ãåè§æå
|
---|
| 240 | if (use_chars == 3) {
|
---|
| 241 | if (((0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF)) ||
|
---|
| 242 | ((0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F))) {
|
---|
| 243 | //3ãã¤ãã³ã¼ãåè§æå
|
---|
| 244 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
| 245 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
| 246 | local_y = local_y + FONT_HEIGHT;
|
---|
| 247 | }
|
---|
| 248 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
| 249 | local_x += FONT_HALF_WIDTH;
|
---|
| 250 | continue;
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | //å
|
---|
| 255 | ¨è§æå
|
---|
| 256 | if (local_x + FONT_WIDTH > hlcd->_width) {
|
---|
| 257 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
| 258 | local_y = local_y + FONT_HEIGHT;
|
---|
| 259 | }
|
---|
| 260 | lcd_drawFont(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
| 261 | local_x += FONT_WIDTH;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 |
|
---|