Required-Software-and-Data

٤Ƴ٤Ĥ
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
-
!
-
!
 
 
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
 
 
 
-
|
|
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
!
 
-
!
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
-
|
|
|
|
!
-
|
|
!
 
 
 
 
-
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
 
-
!
-
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
-
|
!
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
# coding: utf-8
import smbus
import time
import traceback
import struct
import threading
import copy
class Binary_file_reader:
    binary_data=None
 
    def read_file(self,path):
        self.binary_data=None
        try:
            with open(path,'rb') as file:
                while True:
                    chunk = file.read(1024)
                    if not chunk:
                        break
                    if not self.binary_data:
                        self.binary_data=chunk
                    else:
                        self.binary_data=self.binary_data+chunk
                file.close()
        except Exception as e:
            print(traceback.format_exc())
 
    def get_binary(self):
        return self.binary_data
 
    def dump_binary(self,frm, length):
        if not self.binary_data:
            print("no binary.")
        adr=frm
        s=""
        c=""
        size=len(self.binary_data)
        cs=[' ']
        if size<length:
            length=size
        eadr=adr+length
        while adr<eadr:
            a=adr
            if a<size:
                s='{:08x}'.format(a)
            else:
                s='        '
            print(s,end='')
            sline=''
            cline=''
            for i in range(16):
                if a<size:
                    d=self.binary_data[a] & 0xff
                    sline=sline+'{:02x}'.format(d)+' '
                    if d<0x20 or d>0xde or (d>0x73 and d<0xa1):
                        d=0x2e
                    cs=chr(d);
                    cline=cline+cs+' '
                else:
                    s='  '
                    c=' '
                a=a+1
            print(' '+sline+' '+cline)
            adr=a
 
    def dump_binary_all(self):
        self.dump_binary(0,len(self.binary_data))
 
#b_reader=Binary_file_reader()
#b_reader.read_file('ShinonomeMin_16.pdb')
#b_reader.dump_binary(0,1024)
 
class Font_accessor:
    font_array=[]
    base=0
    one_font_size=16
    font_width_byte=2
 
    asciicode=[
               0x2121, 0x2121,0x2121,0x2121,  #//0x00, 0x01, 0x02, 0x03,
               0x2121, 0x2121,0x2121,0x2121,  #//0x04, 0x05, 0x06, 0x07,
               0x2121, 0x2121,0x2121,0x2121,  #//0x08, 0x09, 0x0A, 0x0B,
               0x2121, 0x2121,0x2121,0x2121,  #//0x0C, 0x0D, 0x0E, 0x0F,
               0x2121, 0x2121,0x2121,0x2121,  #//0x10, 0x11, 0x12, 0x13,
               0x2121, 0x2121,0x2121,0x2121,  #//0x14, 0x15, 0x16, 0x17,
               0x2121, 0x2121,0x2121,0x2121,  #//0x18, 0x19, 0x1A, 0x1B,
               0x2121, 0x2121,0x2121,0x2121,  #//0x1C, 0x1D, 0x1E, 0x1F,
               0x2121, 0x212A,0x2148,0x2174,  #//0x20, 0x21, 0x22, 0x23, ' ', '!', '"', '#',
               0x2170, 0x2173,0x2175,0x212D,  #//0x24, 0x25, 0x26, 0x27, '$', '%', '&', ''',
               0x214A, 0x214B,0x2176,0x215C,  #//0x28, 0x29, 0x2A, 0x2B, '(', ')', '*', '+',
               0x2124, 0x215D,0x2125,0x213F,  #//0x2C, 0x2D, 0x2E, 0x2F, ',', '-', '.', '/',
               0x2330, 0x2331,0x2332,0x2333,  #//0x30, 0x31, 0x32, 0x33, '0', '1', '2', '3',
               0x2334, 0x2335,0x2336,0x2337,  #//0x34, 0x35, 0x36, 0x37, '4', '5', '6', '7',
               0x2338, 0x2339,0x2127,0x2128,  #//0x38, 0x39, 0x3A, 0x3B, '8', '9', ':', ';',
               0x2163, 0x2161,0x2164,0x2129,  #//0x3C, 0x3D, 0x3E, 0x3F, '<', '=', '>', '?',
               0x2177, 0x2341,0x2342,0x2343,  #//0x40, 0x41, 0x42, 0x43, '@', 'A', 'B', 'C',
               0x2344, 0x2345,0x2346,0x2347,  #//0x44, 0x45, 0x46, 0x47, 'D', 'E', 'F', 'G',
               0x2348, 0x2349,0x234A,0x234B,  #//0x48, 0x49, 0x4A, 0x4B, 'H', 'I', 'J', 'K',
               0x234C, 0x234D,0x234E,0x234F,  #//0x4C, 0x4D, 0x4E, 0x4F, 'L', 'M', 'N', 'O',
               0x2350, 0x2351,0x2352,0x2353,  #//0x50, 0x51, 0x52, 0x53, 'P', 'Q', 'R', 'S',
               0x2354, 0x2355,0x2356,0x2357,  #//0x54, 0x55, 0x56, 0x57, 'T', 'U', 'V', 'W',
               0x2358, 0x2359,0x235A,0x214E,  #//0x58, 0x59, 0x5A, 0x5B, 'X', 'Y', 'Z', '[',
               0x2140, 0x214F,0x2130,0x2132,  #//0x5C, 0x5D, 0x5E, 0x5F, '\', ']', '^', '_',
               0x212D, 0x2361,0x2362,0x2363,  #//0x60, 0x61, 0x62, 0x63, '`', 'a', 'b', 'c',
               0x2364, 0x2365,0x2366,0x2367,  #//0x64, 0x65, 0x66, 0x67, 'd', 'e', 'f', 'g',
               0x2368, 0x2369,0x236A,0x236B,  #//0x68, 0x69, 0x6A, 0x6B, 'h', 'i', 'j', 'k',
               0x236C, 0x236D,0x236E,0x236F,  #//0x6C, 0x6D, 0x6E, 0x6F, 'l', 'm', 'n', 'o',
               0x2370, 0x2371,0x2372,0x2373,  #//0x70, 0x71, 0x72, 0x73, 'p', 'q', 'r', 's',
               0x2374, 0x2375,0x2376,0x2377,  #//0x74, 0x65, 0x76, 0x77, 't', 'u', 'v', 'w',
               0x2378, 0x2379,0x237A,0x2150,  #//0x78, 0x69, 0x7A, 0x7B, 'x', 'y', 'z', '{',
               0x2143, 0x2151,0x2141,0x2121 # //0x7C, 0x6D, 0x7E, 0x7F, '|', '}', '~', ' ',
   ]
    ascii_font=[0 for x in range(256*8)]
    ascii_font_data=[
                   #//
                   #// use https://github.com/alexmac/alcextra/blob/master/aalib-1.4.0/src/font8.c
                   #//
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #//0x00 null
                    0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e,
                    0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e,
                    0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00,
                    0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00,
                    0x38, 0x7c, 0x38, 0xfe, 0xfe, 0x92, 0x10, 0x7c,
                    0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x7c,
                    0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00,
                    0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff,
                    0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00,
                    0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff,
                    0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78,
                    0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18,
                    0x3f, 0x33, 0x3f, 0x30, 0x30, 0x70, 0xf0, 0xe0,
                    0x7f, 0x63, 0x7f, 0x63, 0x63, 0x67, 0xe6, 0xc0,
                    0x99, 0x5a, 0x3c, 0xe7, 0xe7, 0x3c, 0x5a, 0x99,
                    0x80, 0xe0, 0xf8, 0xfe, 0xf8, 0xe0, 0x80, 0x00, #//0x10
                    0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00,
                    0x18, 0x3c, 0x7e, 0x18, 0x18, 0x7e, 0x3c, 0x18,
                    0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00,
                    0x7f, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x00,
                    0x3e, 0x63, 0x38, 0x6c, 0x6c, 0x38, 0x86, 0xfc,
                    0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00,
                    0x18, 0x3c, 0x7e, 0x18, 0x7e, 0x3c, 0x18, 0xff,
                    0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00,
                    0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00,
                    0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00,
                    0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00,
                    0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00,
                    0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00,
                    0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00,
                    0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #//0x20 space
                    0x18, 0x3c, 0x3c, 0x18, 0x18, 0x00, 0x18, 0x00,
                    0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00,
                    0x18, 0x7e, 0xc0, 0x7c, 0x06, 0xfc, 0x18, 0x00,
                    0x00, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xc6, 0x00,
                    0x38, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0x76, 0x00,
                    0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00,
                    0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00,
                    0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00,
                    0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30,
                    0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
                    0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00,
                    0x7c, 0xce, 0xde, 0xf6, 0xe6, 0xc6, 0x7c, 0x00, #//0x30 0
                    0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x00, #// 1
                    0x78, 0xcc, 0x0c, 0x38, 0x60, 0xcc, 0xfc, 0x00, #// 2
                    0x78, 0xcc, 0x0c, 0x38, 0x0c, 0xcc, 0x78, 0x00, #// 3
                    0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x1e, 0x00, #// 4
                    0xfc, 0xc0, 0xf8, 0x0c, 0x0c, 0xcc, 0x78, 0x00, #// 5
                    0x38, 0x60, 0xc0, 0xf8, 0xcc, 0xcc, 0x78, 0x00, #// 6
                    0xfc, 0xcc, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x00, #// 7
                    0x78, 0xcc, 0xcc, 0x78, 0xcc, 0xcc, 0x78, 0x00, #// 8
                    0x78, 0xcc, 0xcc, 0x7c, 0x0c, 0x18, 0x70, 0x00, #// 9
                    0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00,
                    0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30,
                    0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00,
                    0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00,
                    0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00,
                    0x3c, 0x66, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x00,
                    0x7c, 0xc6, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, #//0x40 @
                    0x30, 0x78, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0x00, #// A
                    0xfc, 0x66, 0x66, 0x7c, 0x66, 0x66, 0xfc, 0x00, #// B
                    0x3c, 0x66, 0xc0, 0xc0, 0xc0, 0x66, 0x3c, 0x00, #// C
                    0xf8, 0x6c, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, #// D
                    0xfe, 0x62, 0x68, 0x78, 0x68, 0x62, 0xfe, 0x00, #// E
                    0xfe, 0x62, 0x68, 0x78, 0x68, 0x60, 0xf0, 0x00, #// F
                    0x3c, 0x66, 0xc0, 0xc0, 0xce, 0x66, 0x3a, 0x00, #// G
                    0xcc, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0xcc, 0x00, #// H
                    0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// I
                    0x1e, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00, #// J
                    0xe6, 0x66, 0x6c, 0x78, 0x6c, 0x66, 0xe6, 0x00, #// K
                    0xf0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, #// L
                    0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0x00, #// M
                    0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x00, #// N
                    0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, #// O
                    0xfc, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, #// 0x50 P
                    0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0x7c, 0x0e, 0x00, #// Q
                    0xfc, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0xe6, 0x00, #// R
                    0x7c, 0xc6, 0xe0, 0x78, 0x0e, 0xc6, 0x7c, 0x00, #// S
                    0xfc, 0xb4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// T
                    0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xfc, 0x00, #// U
                    0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00, #// V
                    0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00, #// W
                    0xc6, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0xc6, 0x00, #// X
                    0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x78, 0x00, #// Y
                    0xfe, 0xc6, 0x8c, 0x18, 0x32, 0x66, 0xfe, 0x00, #// Z
                    0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00,
                    0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x02, 0x00,
                    0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00,
                    0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
                    0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, #// 0x60
                    0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, #// 0x61 a
                    0xe0, 0x60, 0x60, 0x7c, 0x66, 0x66, 0xdc, 0x00, #// b
                    0x00, 0x00, 0x78, 0xcc, 0xc0, 0xcc, 0x78, 0x00, #// c
                    0x1c, 0x0c, 0x0c, 0x7c, 0xcc, 0xcc, 0x76, 0x00, #// d
                    0x00, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, #// e
                    0x38, 0x6c, 0x64, 0xf0, 0x60, 0x60, 0xf0, 0x00, #// f
                    0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, #// g
                    0xe0, 0x60, 0x6c, 0x76, 0x66, 0x66, 0xe6, 0x00, #// h
                    0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, #// i
                    0x0c, 0x00, 0x1c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, #// j
                    0xe0, 0x60, 0x66, 0x6c, 0x78, 0x6c, 0xe6, 0x00, #// k
                    0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// l
                    0x00, 0x00, 0xcc, 0xfe, 0xfe, 0xd6, 0xd6, 0x00, #// m
                    0x00, 0x00, 0xb8, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, #// n
                    0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x00, #// o
                    0x00, 0x00, 0xdc, 0x66, 0x66, 0x7c, 0x60, 0xf0, #// 0x70 p
                    0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0x1e, #// q
                    0x00, 0x00, 0xdc, 0x76, 0x62, 0x60, 0xf0, 0x00, #// r
                    0x00, 0x00, 0x7c, 0xc0, 0x70, 0x1c, 0xf8, 0x00, #// s
                    0x10, 0x30, 0xfc, 0x30, 0x30, 0x34, 0x18, 0x00, #// t
                    0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, #// u
                    0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00, #// v
                    0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00, #// w
                    0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00, #// z
                    0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8,
                    0x00, 0x00, 0xfc, 0x98, 0x30, 0x64, 0xfc, 0x00,
                    0x1c, 0x30, 0x30, 0xe0, 0x30, 0x30, 0x1c, 0x00,
                    0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00,
                    0xe0, 0x30, 0x30, 0x1c, 0x30, 0x30, 0xe0, 0x00,
                    0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0x00,
                    0x7c, 0xc6, 0xc0, 0xc6, 0x7c, 0x0c, 0x06, 0x7c,
                    0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
                    0x1c, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, #//0x80
                    0x7e, 0x81, 0x3c, 0x06, 0x3e, 0x66, 0x3b, 0x00,
                    0xcc, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
                    0xe0, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
                    0x30, 0x30, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
                    0x00, 0x00, 0x7c, 0xc6, 0xc0, 0x78, 0x0c, 0x38,
                    0x7e, 0x81, 0x3c, 0x66, 0x7e, 0x60, 0x3c, 0x00,
                    0xcc, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00,
                    0xe0, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00,
                    0xcc, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,
                    0x7c, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
                    0xe0, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,
                    0xc6, 0x10, 0x7c, 0xc6, 0xfe, 0xc6, 0xc6, 0x00,
                    0x30, 0x30, 0x00, 0x78, 0xcc, 0xfc, 0xcc, 0x00,
                    0x1c, 0x00, 0xfc, 0x60, 0x78, 0x60, 0xfc, 0x00,
                    0x00, 0x00, 0x7f, 0x0c, 0x7f, 0xcc, 0x7f, 0x00,
                    0x3e, 0x6c, 0xcc, 0xfe, 0xcc, 0xcc, 0xce, 0x00, #//0x90
                    0x78, 0x84, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00,
                    0x00, 0xcc, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00,
                    0x00, 0xe0, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00,
                    0x78, 0x84, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
                    0x00, 0xe0, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
                    0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8,
                    0xc3, 0x18, 0x3c, 0x66, 0x66, 0x3c, 0x18, 0x00,
                    0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00,
                    0x18, 0x18, 0x7e, 0xc0, 0xc0, 0x7e, 0x18, 0x18,
                    0x38, 0x6c, 0x64, 0xf0, 0x60, 0xe6, 0xfc, 0x00,
                    0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x30, 0xfc, 0x30,
                    0xf8, 0xcc, 0xcc, 0xfa, 0xc6, 0xcf, 0xc6, 0xc3,
                    0x0e, 0x1b, 0x18, 0x3c, 0x18, 0x18, 0xd8, 0x70,
                    0x1c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
                    0x38, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,
                    0x00, 0x1c, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, #//0xA0
                    0x00, 0x1c, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
                    0x00, 0xf8, 0x00, 0xb8, 0xcc, 0xcc, 0xcc, 0x00,
                    0xfc, 0x00, 0xcc, 0xec, 0xfc, 0xdc, 0xcc, 0x00,
                    0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00,
                    0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00,
                    0x18, 0x00, 0x18, 0x18, 0x30, 0x66, 0x3c, 0x00,
                    0x00, 0x00, 0x00, 0xfc, 0xc0, 0xc0, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0c, 0x00, 0x00,
                    0xc6, 0xcc, 0xd8, 0x36, 0x6b, 0xc2, 0x84, 0x0f,
                    0xc3, 0xc6, 0xcc, 0xdb, 0x37, 0x6d, 0xcf, 0x03,
                    0x18, 0x00, 0x18, 0x18, 0x3c, 0x3c, 0x18, 0x00,
                    0x00, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x00, 0x00,
                    0x00, 0xcc, 0x66, 0x33, 0x66, 0xcc, 0x00, 0x00,
                    0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88,
                    0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
                    0xdb, 0xf6, 0xdb, 0x6f, 0xdb, 0x7e, 0xd7, 0xed, #//0xB0
                    0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
                    0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18,
                    0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18,
                    0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36,
                    0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36,
                    0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18,
                    0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36,
                    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
                    0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36,
                    0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00,
                    0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00,
                    0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18,
                    0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00,
                    0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, #//0xC0
                    0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18,
                    0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
                    0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18,
                    0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18,
                    0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36,
                    0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36,
                    0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36,
                    0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36,
                    0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
                    0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36,
                    0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
                    0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18,
                    0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, #//0xD0
                    0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00,
                    0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18,
                    0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36,
                    0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36,
                    0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18,
                    0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18,
                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                    0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
                    0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
                    0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
                    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x76, 0xdc, 0xc8, 0xdc, 0x76, 0x00,
                    0x00, 0x78, 0xcc, 0xf8, 0xcc, 0xf8, 0xc0, 0xc0,
                    0x00, 0xfc, 0xcc, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, #// 0xE0
                    0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x00,
                    0xfc, 0xcc, 0x60, 0x30, 0x60, 0xcc, 0xfc, 0x00,
                    0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0x70, 0x00,
                    0x00, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0xc0,
                    0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x00,
                    0xfc, 0x30, 0x78, 0xcc, 0xcc, 0x78, 0x30, 0xfc,
                    0x38, 0x6c, 0xc6, 0xfe, 0xc6, 0x6c, 0x38, 0x00,
                    0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x6c, 0xee, 0x00,
                    0x1c, 0x30, 0x18, 0x7c, 0xcc, 0xcc, 0x78, 0x00,
                    0x00, 0x00, 0x7e, 0xdb, 0xdb, 0x7e, 0x00, 0x00,
                    0x06, 0x0c, 0x7e, 0xdb, 0xdb, 0x7e, 0x60, 0xc0,
                    0x38, 0x60, 0xc0, 0xf8, 0xc0, 0x60, 0x38, 0x00,
                    0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00,
                    0x00, 0x7e, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00,
                    0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x7e, 0x00,
                    0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00, #// 0xF0
                    0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xfc, 0x00,
                    0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18,
                    0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70,
                    0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00,
                    0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00,
                    0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
                    0x0f, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x1c,
                    0x58, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00,
                    0x70, 0x98, 0x30, 0x60, 0xf8, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    ]
    def __init__(self,font_data, font_size, base):
       self.font_array=font_data
       self.one_font_size=font_size
       self.base=base
       self.font_width_byte=int((self.one_font_size+7)/8)
       for i in range(len(self.ascii_font)):
           self.ascii_font[i]=self.ascii_font_data[i]
 
    def utf_8_str_to_jis_barray(self,x):
        #print('utf_8_str_to_jis_barray x='+x)
        rtn=[]
        lx=len(x)
        for i in range(lx):
            c=x[i]
            #print('c='+c)
            j=self.utf_8_to_jis_char(c)
            #print('j={:x}'.format(j))
            rtn.append(j)
        return rtn
 
    def utf_8_to_jis_char(self,x):
        #print('utf_8_to_jis_char x='+x)
        w=x.encode('shift_jis')
        jw=self.sjis_to_jis(w)
        return jw
 
    def sjis_to_jis_string(self,x):
        xlen=len(x)
        rtn=''
        for i in range(xlen):
            w=self.sjis_to_jis(x[i])
            rtn=rtn+w
        return rtn
 
    def sjis_to_jis(self, x):
        #print('sjis_to_jis x=',end='')
        #print(x)
        if len(x)==2:
            wx=struct.unpack('BB',x)
            c1=wx[0]
            c2=wx[1]
        else:
            wx=struct.unpack('B',x)
            c1=0
            c2=wx[0]
        #print(wx)
        ##c1=(x >> 8) &0x00ff
        ##c2=x & 0x00ff
        #print('c1={:x}'.format(c1))
        #print('c2={:x}'.format(c2))
        if c1==0:
            c2=c2
        else:
            if c1 >=0xe0:
                c1=c1-0x40
            if c2 >=0x80:
                c2=c2-1
            if c2 >=0x9e:
                c1=(c1-0x70)*2
                c2=c2-0x7d
            else:
                c1=((c1-0x70)*2)-1
                c2=c2-0x1f
        rtn=(c1<<8)|c2
        #print('rtn=',end='')
        #print(rtn)
        return rtn
 
    def get_JIS_string(self,x):
        tmp=self.get_SJIS_string(x)
        if tmp==None:
            return None
        rtn=[' ' for i in range(len(tmp))]
        bl=len(tmp)
        for i in range(bl):
            #print('tmp[i]='+tmp[i])
            #print('tmp[i]={:0x}'.format(ord(tmp[i])))
            cx=ord(tmp[i]) & 0x0000ffff
            if cx>0x2100:
                rtn[i]=self.sjis_to_jis(tmp[i])
            else:
                rtn[i]=tmp[i]
        return rtn
 
    def get_font_jis(self,code):
        hb=(0xff00 & code)>>8
        lb=0x00ff & code
        if code <0x2100:
            return self.get_ascii_font(code)
        fn=((hb-0x21)*(0x7f-0x21))+lb-0x21
        pos=self.base+(fn*self.one_font_size*self.font_width_byte)
        return self.get_font_raw(pos)
 
    def get_ascii_font(self,c):
        # Standard ASCII 5x7 font
        # Draw a character
        rtn=[0 for i in range(16)]
        offset=6
        #print('get_ascii_font c={:x}'.format(c))
        for i in range(8):
            rtn[offset+i]=self.ascii_font[8*c+i]
        #print(rtn)
        return rtn
 
    def get_font_raw(self,pos):
        if self.font_array==None:
            return None
        rtn=[0 for i in range(self.one_font_size*self.font_width_byte)]
        if pos+self.one_font_size*self.font_width_byte > len(self.font_array):
            print("exceeded the max font range.")
            return None
        for i in range(self.one_font_size*self.font_width_byte):
            rtn[i]=self.font_array[pos+i]
        return rtn
 
    def print_font(self,f):
        if f==None:
            return
        w=int(self.one_font_size/8)
        fsize=len(f)
        if fsize<=16:
            w=1
        for i in range(self.one_font_size):
            for j in range(w):
                l=f[i*w+j]
                mask=0x0080
                for k in range(8):
                    if (mask & l)!=0:
                        print('*',end='')
                    else:
                        print(' ',end='')
                    mask=mask>>1
            print('')
        print('')
 
 
class Bitmap_to_Display:
 
  #
  # command:
  #   clear... 0x00
  #   show ... 0x01
  #   set1 ix,iy,r,g,b
  #         ... 0x02  *,*,  *,*,*
  #   setn ix,iy,n, r0,g0,b0, ..r(n-1),g(n-1),b(n-1)   n<=8
  #         ... 0x03 *,*, *, *,*,*, ..., *,*,*
  #
  pixels_ex01= [ \
          [ ' ',' ',' ',' ',' ',' ',' ',' '],\
                    [ ' ','r','r',' ',' ','r','r',' '],\
                    [ 'r',' ',' ','r','r',' ',' ','r'],\
                    [ 'r',' ',' ',' ',' ',' ',' ','r'],\
                    [ 'r',' ',' ',' ',' ',' ',' ','r'],\
                    [ 'r',' ',' ',' ',' ',' ',' ','r'],\
                    [ ' ','r',' ',' ',' ',' ','r',' '],\
                    [ ' ','r',' ',' ',' ',' ','r',' '],\
                    [ ' ',' ','r',' ',' ','r',' ',' '],\
                    [ ' ',' ',' ','r','r',' ',' ',' '],\
                    [ ' ',' ',' ',' ',' ',' ',' ',' '],\
                    [ ' ','g','g','g','g','g','g','g'],\
                    [ ' ',' ','g','y','y','y','g',' '],\
                    [ ' ',' ',' ','g','y','g',' ',' '],\
                    [ ' ',' ',' ','g','y','g',' ',' '],\
                    [ ' ',' ',' ',' ','g',' ',' ',' '] ]
 
  r_comp={' ':0x00, 'r':0xff, 'g':0x00, 'b':0x00, 'y':0xff, 'w':0xff}
  g_comp={' ':0x00, 'r':0x00, 'g':0xff, 'b':0x00, 'y':0xff, 'w':0xff}
  b_comp={' ':0x00, 'r':0x00, 'g':0x00, 'b':0xff, 'y':0x00, 'w':0xff}
 
  def __init__(self,fa):
    self.i2c = smbus.SMBus(1)
    self.addrs = 0x3f
    self.fourpix=[0x00, 0x00, 0x04, 0,0,0, 0,0,0, 0,0,0, 0,0,0]
    self.v_bitmap=[[] for i in range(16)]
    self.v_lp=0
    self.v_rp=0
    self.d_bitmap=[[[0]*3 for i in range(32)] for j in range(16)]
    self.current_r=0xff
    self.current_g=0x00
    self.current_b=0x00
    self.font_accessor=fa
 
  def start_display_thread(self):
      self.thread=threading.Thread(target=self.display_thread)
      self.thread.start()
 
  def display_thread(self):
      while True:
          if self.v_rp>=(len(self.v_bitmap[0])):
              self.v_rp=0
          if self.v_lp>=(len(self.v_bitmap[0])):
              self.v_lp=0
          #print('len(v_bitmap[0]={:d})'.format(len(self.v_bitmap[0])))
          #print('v_lp='+str(self.v_lp)+' v_rp='+str(self.v_rp))
          if self.v_lp==self.v_rp:
              self.clear_bitmap(self.d_bitmap)
          elif self.v_lp<self.v_rp:
              self.set_bitmap(self.v_bitmap,0,self.v_lp,16,32, self.d_bitmap,0,0)
          else:
              self.set_bitmap(self.v_bitmap,0,self.v_lp,16,
                        len(self.v_bitmap[0])-self.v_lp,
                        self.d_bitmap,0,0)
              self.set_bitmap(self.v_bitmap,0,0,16,self.v_rp,
                        self.d_bitmap,0,len(self.v_bitmap[0])-self.v_lp+1)
          self.v_lp=self.v_lp+1
          self.v_rp=self.v_rp+1
          self.show_bitmap(self.d_bitmap,0,0,16,32)
          time.sleep(0.01)
 
  def put_font(self,font):
      #print(font)
      if(len(font)>16):
          w=16
      else:
          w=8
      f_bitmap=[[[0,0,0] for i in range(w)] for j in range(16)]
      self.set_font(self.font_accessor,font,f_bitmap,0,0)
      self.append_font(f_bitmap)
 
  def append_font(self,font):
      #print('append_font w={:d}'.format(len(font[0])))
      #self.print_bitmap(font)
      if len(font)!=len(self.v_bitmap):
          print('font size unpatch')
          return
      for i in range(len(self.d_bitmap)):
          l=copy.copy(font[i])
          #print('l=',end='')
          #print(l)
          #print('l len={:d}'.format(len(l)))
          #print('b v_bitmap[{:d}'.format(i)+']=',end='')
          #print(self.v_bitmap[i])
          (self.v_bitmap[i]).extend(l)
          #print('a v_bitmap[{:d}'.format(i)+']=',end='')
          #print(self.v_bitmap[i])
          #print('len={:d}'.format(len(self.v_bitmap[i])))
      self.v_lp=0
      if len(self.v_bitmap[0])<31:
          self.v_rp=len(self.v_bitmap[0])
      else:
          self.v_rp=31
      #print('-print_bitmap v_lp={:d}'.format(self.v_lp)+' v_rp={:d}'.format(self.v_rp))
      #for i in range(16):
        #print('v_bitmap[{:d}'.format(i)+']  w={:d}'.format(len(self.v_bitmap[i])))
 
  def set_color(self,r,g,b):
    self.current_r=r
    self.current_g=g
    self.current_b=b
 
  def clear_bitmap(self,bitmap):
    h_max=len(bitmap)
    w_max=len(bitmap[0])
    for i in range(h_max):
      for j in range(w_max):
        for k in range(3):
          bitmap[i][j][k]=0
 
  def set_example_01(self,pixels_ex01,i,j,h,w,destination):
    for ip in range(h):
      for jp in range(w):
        p=pixels_ex01[i+ip][j+jp]
        for color in ['r','g','b']:
          if color == 'r':
            destination[ip][jp][0]=self.r_comp[p]
          elif color == 'g':
            destination[ip][jp][1]=self.g_comp[p]
          elif color == 'b':
            destination[ip][jp][2]=self.b_comp[p]
 
  def set_bitmap(self,source,i,j,h,w, destination,k,l):
    #print('set_bitmap i={:d}'.format(i)+' j={:d}'.format(j)+
    #      ' h={:d}'.format(h)+' w={:d}'.format(w)+
    #      ' k={:d}'.format(k)+' l={:d}'.format(k))
    #self.print_bitmap(source)
    for ip in range(h):
      for jp in range(w):
        for cp in range(3):
          #print(' i+ip={:d}'.format(i+ip)+' j+jp={:d}'.format(j+jp))
          cx=source[i+ip][j+jp][cp]
          destination[k+ip][l+jp][cp]=cx
 
  def set_font(self,fa,f, destination,d_i,d_j):
        if f==None:
            return
        w=int(fa.one_font_size/8)
        fsize=len(f)
        if fsize<=16:
            w=1
        for i in range(fa.one_font_size):
            for j in range(w):
                l=f[i*w+j]
                mask=0x0080
                for k in range(8):
                    if (mask & l)!=0:
                      #print('*',end='')
                      destination[d_i+i][d_j+j*8+k][0]=self.current_r
                      destination[d_i+i][d_j+j*8+k][1]=self.current_g
                      destination[d_i+i][d_j+j*8+k][2]=self.current_b
                    else:
                      destination[d_i+i][d_j+j*8+k][0]=0
                      destination[d_i+i][d_j+j*8+k][1]=0
                      destination[d_i+i][d_j+j*8+k][2]=0
                      #print(' ',end='')
                    mask=mask>>1
            #print('')
        #print('')
 
  def show_bitmap(self, pixels, #bitmap data
                        i,j, #i,j: left, top position from the bitmap
                        h,w  #h:hight, w:width of the showing
                 ):
    self.i2c.write_byte(self.addrs,0x00)
    four_bitmap=[[0]*3 for i in range(4)]
    for ip in range(h):
      for jp in range(int(w/4)):
        for kp in range(4):
          for cp in range(3):
            four_bitmap[kp][cp]=pixels[i+ip][j+jp*4+kp][cp]
        self.send_4_pixel(i+ip,j+jp*4,four_bitmap)
    self.i2c.write_byte(self.addrs,0x01)
 
  def send_4_pixel(self, i,j,four_bitmap):
    #self.i2c.write_byte(self.addrs,0x00)
    self.fourpix[0]=i
    self.fourpix[1]=j
    for k in range(4):
      for l in range(3):
        p=four_bitmap[k][l]
        self.fourpix[3+3*k+l]=p
    #print('self.fourpix=',end='')
    #print(self.fourpix)
    self.i2c.write_i2c_block_data(self.addrs,0x03,self.fourpix)
    #i2c.write_byte(addrs,0x01)
 
  def print_bitmap(self,bitmap):
    h_max=len(bitmap)
    w_max=len(bitmap[0])
    for ip in range(h_max):
      for jp in range(w_max):
        cc=0
        for cp in range(3):
          cx=bitmap[ip][jp][cp]
          cc=cc<<8|cx
        print('{:6x}'.format(cc),end='')
      print()
 
  def test_01(self):
    self.clear_bitmap(self.d_bitmap)
    self.print_bitmap(self.d_bitmap)
    self.set_example_01(self.pixels_ex01,0,0,16,8,self.d_bitmap)
    self.print_bitmap(self.d_bitmap)
    self.show_bitmap(self.d_bitmap,0,0,16,8)
    self.print_bitmap(self.d_bitmap)
 
class Show_String:
    def __init__(self):
        b_reader=Binary_file_reader()
        b_reader.read_file('ShinonomeMin_16.pdb')
        self.fa=Font_accessor(b_reader.get_binary(),16,0x00F0)
        self.b2d=Bitmap_to_Display(self.fa)
        self.b2d.start_display_thread()
 
    def set_string(self,s):
        sx=""
        while True:
            print('s='+s+' sx='+sx)
            if s.startswith('(red)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0xff
                self.b2d.current_g=0x00
                self.b2d.current_b=0x00
                s=s[len('(red)'):]
            if s.startswith('(green)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0x00
                self.b2d.current_g=0xff
                self.b2d.current_b=0x00
                s=s[len('(green)'):]
            if s.startswith('(blue)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0x00
                self.b2d.current_g=0x00
                self.b2d.current_b=0xff
                s=s[len('(blue)'):]
            if s.startswith('(yellow)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0xff
                self.b2d.current_g=0xff
                self.b2d.current_b=0x00
                s=s[len('(yellow)'):]
            if s.startswith('(magenta)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0xff
                self.b2d.current_g=0x00
                self.b2d.current_b=0xff
                s=s[len('(magenta)'):]
            if s.startswith('(cyan)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0x00
                self.b2d.current_g=0xff
                self.b2d.current_b=0xff
                s=s[len('(cyan)'):]
            if s.startswith('(white)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0xc0
                self.b2d.current_g=0xc0
                self.b2d.current_b=0xc0
                s=s[len('(white)'):]
            if s.startswith('(pink)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=0xc0
                self.b2d.current_g=0x30
                self.b2d.current_b=0x30
                s=s[len('(pink)'):]
            if s.startswith('(orange)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=233
                self.b2d.current_g=163
                self.b2d.current_b=0
                s=s[len('(orange)'):]
            if s.startswith('(brown)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=100
                self.b2d.current_g=77
                self.b2d.current_b=55
                s=s[len('(orange)'):]
            if s.startswith('(purple)'):
                self.put_string(sx)
                sx=""
                self.b2d.current_r=128
                self.b2d.current_g=0
                self.b2d.current_b=128
                s=s[len('(purple)'):]
            if len(s)>0:
                sx=sx+s[0]
                s=s[1:]
            if len(s)<=0:
                self.put_string(sx)
                return
 
    def put_string(self,s):
        if s=="":
            return
        print('r={:d}'.format(self.b2d.current_r)+
              ' g={:d}'.format(self.b2d.current_g)+
              ' b={:d}'.format(self.b2d.current_b))
        print('put_string '+s)
        s_jis=self.fa.utf_8_str_to_jis_barray(s)
        self.b2d.clear_bitmap(self.b2d.d_bitmap)
        for i in range(len(s_jis)):
            c=s_jis[i]
            fx=self.b2d.font_accessor.get_font_jis(c)
            self.b2d.font_accessor.print_font(fx)
            self.b2d.put_font(fx)
 
 
ss=Show_String()
brightness=[15]
ss.b2d.i2c.write_i2c_block_data(ss.b2d.addrs,0x06,brightness)
ss.set_string("(green)福山(red)薔薇(blue)祭(white)!")
 

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS