[364] | 1 | /*
|
---|
| 2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2018 Cores Co., Ltd. Japan
|
---|
| 5 | *
|
---|
| 6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 11 | * スコード中に含まれていること.
|
---|
| 12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 15 | * の無保証規定を掲載すること.
|
---|
| 16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 18 | * と.
|
---|
| 19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 22 | * 報告すること.
|
---|
| 23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 27 | * 免責すること.
|
---|
| 28 | *
|
---|
| 29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 33 | * の責任を負わない.
|
---|
| 34 | *
|
---|
| 35 | * @(#) $Id$
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <kernel.h>
|
---|
| 39 | #include <t_syslog.h>
|
---|
| 40 | #include <t_stdlib.h>
|
---|
| 41 | #include <string.h>
|
---|
| 42 | #include <target_syssvc.h>
|
---|
| 43 | #include <time.h>
|
---|
| 44 | #include "adafruit_ssd1306.h"
|
---|
| 45 | #include "draw_font.h"
|
---|
| 46 |
|
---|
| 47 | void get_bitmap_font(const uint8_t *string, uint8_t *bitmap_data, uint32_t *use_chars)
|
---|
| 48 | {
|
---|
| 49 | uint32_t len, code;
|
---|
| 50 | uint8_t i, j, k;
|
---|
| 51 | uint32_t totalj, totalk;
|
---|
| 52 |
|
---|
| 53 | *use_chars = 0;
|
---|
| 54 | len = 0;
|
---|
| 55 | if ((string[0] & 0x80) == 0) { len = 1; }
|
---|
| 56 | else if ((string[0] & 0xE0) == 0xC0) { len = 2; }
|
---|
| 57 | else if ((string[0] & 0xF0) == 0xE0) { len = 3; }
|
---|
| 58 | else if ((string[0] & 0xF8) == 0xF0) { len = 4; }
|
---|
| 59 | else { return; }
|
---|
| 60 |
|
---|
| 61 | j = k = totalj = totalk = 0;
|
---|
| 62 |
|
---|
| 63 | if (len == 1) {
|
---|
| 64 | code = string[0];
|
---|
| 65 | memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 66 | *use_chars = 1;
|
---|
| 67 | return;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | if (len == 2) {
|
---|
| 71 | code = string[0];
|
---|
| 72 | // 1バイト目サーチ
|
---|
| 73 | for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) {
|
---|
| 74 | if (Utf8CodeTable_2B_1st[i][0] == code) {
|
---|
| 75 | code = string[1];
|
---|
| 76 | for (j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++) {
|
---|
| 77 | if (UTF8_2B_CODE_BITMAP[totalk].code == code) {
|
---|
| 78 | memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 79 | *use_chars = 2;
|
---|
| 80 | return;
|
---|
| 81 | }
|
---|
| 82 | totalk++;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | else {
|
---|
| 86 | totalk += Utf8CodeTable_2B_1st[i][1];
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | return;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | if (len == 3) {
|
---|
| 93 | code = string[0];
|
---|
| 94 | // 1バイト目サーチ
|
---|
| 95 | for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) {
|
---|
| 96 | if (Utf8CodeTable_3B_1st[i][0] == code) {
|
---|
| 97 | code = string[1];
|
---|
| 98 | // 2バイト目サーチ
|
---|
| 99 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
| 100 | if (Utf8CodeTable_3B_2nd[totalj][0] == code) {
|
---|
| 101 | code = string[2];
|
---|
| 102 | // 3バイト目サーチ
|
---|
| 103 | for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
|
---|
| 104 | if (UTF8_3B_CODE_BITMAP[totalk].code == code) {
|
---|
| 105 | memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 106 | *use_chars = 3;
|
---|
| 107 | return;
|
---|
| 108 | }
|
---|
| 109 | totalk++;
|
---|
| 110 | }
|
---|
| 111 | return;
|
---|
| 112 | }
|
---|
| 113 | else {/*読み飛ばすbitmap個数を蓄積*/
|
---|
| 114 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
| 115 | }
|
---|
| 116 | totalj++;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | else {/*読み飛ばすbitmap個数を蓄積*/
|
---|
| 120 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
| 121 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
| 122 | totalj++;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | return;
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | void lcd_drawFont(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
|
---|
| 131 | {
|
---|
| 132 | int i, j, b;
|
---|
| 133 | uint8_t *bitmap = bitmap_data;
|
---|
| 134 |
|
---|
| 135 | b = 0x80;
|
---|
| 136 | for (i = 0; i < FONT_HEIGHT; i++) {
|
---|
| 137 | for (j = 0; j < FONT_WIDTH; j++) {
|
---|
| 138 | if ((*bitmap & b) != 0) {
|
---|
| 139 | lcd_drawPixel(hlcd, x + j, y + i, color);
|
---|
| 140 | }
|
---|
| 141 | else {
|
---|
| 142 | lcd_drawPixel(hlcd, x + j, y + i, back_color);
|
---|
| 143 | }
|
---|
| 144 | b >>= 1;
|
---|
| 145 | if (b == 0) {
|
---|
| 146 | b = 0x80;
|
---|
| 147 | bitmap++;
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | void lcd_drawFontHalf(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
|
---|
| 154 | {
|
---|
| 155 | int i, j, b;
|
---|
| 156 | uint8_t *bitmap = bitmap_data;
|
---|
| 157 |
|
---|
| 158 | b = 0x80;
|
---|
| 159 | for (i = 0; i < FONT_HEIGHT; i++) {
|
---|
| 160 | for (j = 0; j < FONT_HALF_WIDTH; j++) {
|
---|
| 161 | if ((*bitmap & b) != 0) {
|
---|
| 162 | lcd_drawPixel(hlcd, x + j, y + i, color);
|
---|
| 163 | }
|
---|
| 164 | else {
|
---|
| 165 | lcd_drawPixel(hlcd, x + j, y + i, back_color);
|
---|
| 166 | }
|
---|
| 167 | b >>= 1;
|
---|
| 168 | if (b == 0) {
|
---|
| 169 | b = 0x80;
|
---|
| 170 | bitmap++;
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | void lcd_drawString(LCD_Handler_t *hlcd, const char *string, int x, int y, uint16_t color, uint16_t back_color)
|
---|
| 177 | {
|
---|
| 178 | uint32_t current_top, use_chars, for_3B_hankaku_code;
|
---|
| 179 | uint8_t bitmap_data[FONT_WIDTH * FONT_HEIGHT / 8], ctrl_code;
|
---|
| 180 | int local_x, local_y, len = strlen(string);
|
---|
| 181 | const uint8_t *code = (const uint8_t *)string;
|
---|
| 182 |
|
---|
| 183 | local_x = x;
|
---|
| 184 | local_y = y;
|
---|
| 185 |
|
---|
| 186 | current_top = 0;
|
---|
| 187 | while (current_top < len) {
|
---|
| 188 | memset(bitmap_data, 0x0, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 189 | ctrl_code = code[current_top];
|
---|
| 190 | get_bitmap_font(&code[current_top], bitmap_data, &use_chars);
|
---|
| 191 | if (use_chars == 0)
|
---|
| 192 | return;
|
---|
| 193 |
|
---|
| 194 | //3バイトコード半角文字用
|
---|
| 195 | if (use_chars == 3) {
|
---|
| 196 | for_3B_hankaku_code = 0;
|
---|
| 197 | for_3B_hankaku_code = ((code[current_top] << 16) |
|
---|
| 198 | (code[current_top + 1] << 8) |
|
---|
| 199 | (code[current_top + 2]));
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | current_top += use_chars;
|
---|
| 203 |
|
---|
| 204 | //1バイトコード半角文字
|
---|
| 205 | if (use_chars == 1) {
|
---|
| 206 | if (ctrl_code == 0x0D) { // CR
|
---|
| 207 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
| 208 | continue;
|
---|
| 209 | }
|
---|
| 210 | if (ctrl_code == 0x0A) { // LF
|
---|
| 211 | local_y = local_y + FONT_HEIGHT;
|
---|
| 212 | continue;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
| 216 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
| 217 | local_y = local_y + FONT_HEIGHT;
|
---|
| 218 | }
|
---|
| 219 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
| 220 | local_x += FONT_HALF_WIDTH;
|
---|
| 221 | continue;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | //3バイトコード半角文字
|
---|
| 225 | if (use_chars == 3) {
|
---|
| 226 | if (((0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF)) ||
|
---|
| 227 | ((0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F))) {
|
---|
| 228 | //3バイトコード半角文字
|
---|
| 229 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
| 230 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
| 231 | local_y = local_y + FONT_HEIGHT;
|
---|
| 232 | }
|
---|
| 233 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
| 234 | local_x += FONT_HALF_WIDTH;
|
---|
| 235 | continue;
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | //全角文字
|
---|
| 240 | if (local_x + FONT_WIDTH > hlcd->_width) {
|
---|
| 241 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
| 242 | local_y = local_y + FONT_HEIGHT;
|
---|
| 243 | }
|
---|
| 244 | lcd_drawFont(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
| 245 | local_x += FONT_WIDTH;
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
| 248 |
|
---|