-
Notifications
You must be signed in to change notification settings - Fork 6
/
i2c2oled-system.ini
673 lines (614 loc) · 26.7 KB
/
i2c2oled-system.ini
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
#
# File: "/media/fat/i2c2oled/i2c2oled-system.ini" System INI file
#
# Default Values
CONTRAST=100 # Set Contrast Value 0..255
ROTATE="no" # Set to "yes" for 180 Degree Display Rotation
ANIMATION=-1 # Set to -1 for Random Animation, 0 for NO Animation, 1 for PressPlay, 2..5 for the "Loading" Variations
BLACKOUT="yes" # Set to "yes" (default) for the short "Display-Blackout" before a Picture change. "no" = No Display "blackout"
SSD1309="no" # Set to "yes" if you use a SS1309 Display (activates an one pixel line offset)
SSH1106="no" # Set to "yes" if you use a SSH1106 Display (activates different ram addressing)
ONECOLOR="no" # Set to "yes" if you want to use the new "OneColor" and "Original" Two-Color Pictures. Set to "no" uses only the "Original" Pictures with Header.
INVERTHEADER="no" # Set to "yes" if you want the Header of the "original" Two-Color Pictures to be inverted. Useful if you run an One-Color Display.
USE_RANDOM_ALT="no" # Set to "yes" if you want randomly chosen alternative pix as well
# Temperature Sensor (AD7414) Values
AD7414_I2CBUS=2
AD7414_DEVADDR=0x4f
AD7414_VAL=0x00
AD7414_CONF=0x01
AD7414_T_HIGH=0x02
AD7414_T_LOW=0x03
AD7414_DEF_CONF=0x40
# I2C Temperature Sensor
SHOW_TEMP="no" # Set to "yes" in order to display temperature (AD7414) on the OLED
SHOW_TEMP_ROW=0
SHOW_TEMP_COL=2
SHOW_TEMP_INTERVAL=1
# Screensaver
SCREENSAVER="no" # Set to "yes" to enable the ScreenSaver
SCREENSAVER_INTERVAL=10 # The Screensaver Interval in Seconds
SCREENSAVER_START=12 # The Screensaver starts after SCREENSAVER_START x SCREENSAVER_INTERVAL [Seconds]
SCREENSAVER_SCREENS=4 # How many different Screens to show. 1=Time, 2=1+Date, 3=2+"i2c2oled", 4=3+"MiSTer FPGA", 5=4+Corename
SCREENSAVER_COUNTER=0 # Screensaver Counter (do not change)
# Slideshow
SLIDETIME=3.0 # Slideshow Wait-Time until the next Picture is shown.
# Debugging
debug="false"
debugfile="/tmp/i2c2oled"
# System Variables
oledid=3c # OLED I2C Address without "0x"
oledaddr=0x${oledid} # OLED I2C Address with "0x"
i2cbus=2 # i2c-2 = Bus 2
oledfound="false" # Pre-Set Variable with false
initfile="/tmp/i2c2oledinitdone" # File is created once each MiSTer Start
# Core related
newcore=""
oldcore=""
corenamefile="/tmp/CORENAME"
# Picture related
pixpath="/media/fat/i2c2oled/Pix"
pixpathone="/media/fat/i2c2oled/Pix_Onecolor"
pripath="/media/fat/i2c2oled/PRI"
pripathone="/media/fat/i2c2oled/PRI_Onecolor"
pixextn="pix"
startpix="${pixpath}/starting.pix"
notavailpix="${pixpath}/nopixavail.pix"
misterheaderpix="${pixpath}/misterheader.pix"
misterheaderpixone="${pixpathone}/misterheader.pix"
pix=""
# Text Colors
freset="\e[0m\033[0m"
fblink="\e[5m"
fbold="\e[1m"
fdim="\e[2m"
finvers="\e[7m"
fhidden="\e[8m"
funderl="\e[4m"
fblue="\e[1;34m"
fgreen="\e[1;32m"
fcyan="\e[1;36m"
fred="\e[1;31m"
fmagenta="\e[1;35m"
fyellow="\e[1;33m"
fwhite="\e[1;37m"
fgrey="\e[1;30m"
chide="\e[?25l"
cshow="\e[?25h"
# Animation Icon's
itape1="0x3C 0x5A 0x81 0xC3 0xC3 0x81 0x5A 0x3C"
itape2="0x3C 0x66 0xE7 0x81 0x81 0xE7 0x66 0x3C"
iload1="0x78 0x3C 0x1E 0x0F 0x87 0xC3 0xE1 0xF0"
iload2="0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x00"
iload3="0x18 0x00 0x3C 0x00 0xFF 0x00 0x3C 0x00"
iload4="0xC3 0xC3 0x66 0x66 0x3C 0x3C 0x18 0x18"
iwarp1="0x3C 0x42 0x81 0x81 0x81 0x81 0x42 0x3C"
iwarp2="0x3C 0x7E 0xFF 0xFF 0xFF 0xFF 0x7E 0x3C"
# Font 8x8
# Font starts with ASCII "0x20/32 (Space)
font_height=8
font_width=8
font=(
"0x00" "0x00" "0x00" "0x00" "0x00" "0x00" "0x00" "0x00" # Space
"0x00" "0x00" "0x00" "0x00" "0x5F" "0x00" "0x00" "0x00" # !
"0x00" "0x00" "0x00" "0x03" "0x00" "0x03" "0x00" "0x00" # "
"0x00" "0x24" "0x7E" "0x24" "0x24" "0x7E" "0x24" "0x00" # #
"0x00" "0x2E" "0x2A" "0x7F" "0x2A" "0x3A" "0x00" "0x00" # $
"0x00" "0x46" "0x26" "0x10" "0x08" "0x64" "0x62" "0x00" # %
"0x00" "0x20" "0x54" "0x4A" "0x54" "0x20" "0x50" "0x00" # &
"0x00" "0x00" "0x00" "0x04" "0x02" "0x00" "0x00" "0x00" # '
"0x00" "0x00" "0x00" "0x3C" "0x42" "0x00" "0x00" "0x00" # (
"0x00" "0x00" "0x00" "0x42" "0x3C" "0x00" "0x00" "0x00" # )
"0x00" "0x10" "0x54" "0x38" "0x54" "0x10" "0x00" "0x00" # *
"0x00" "0x10" "0x10" "0x7C" "0x10" "0x10" "0x00" "0x00" # +
"0x00" "0x00" "0x00" "0x80" "0x60" "0x00" "0x00" "0x00" # "
"0x00" "0x10" "0x10" "0x10" "0x10" "0x10" "0x00" "0x00" # -
"0x00" "0x00" "0x00" "0x60" "0x60" "0x00" "0x00" "0x00" # .
"0x00" "0x40" "0x20" "0x10" "0x08" "0x04" "0x00" "0x00" # /
"0x3C" "0x62" "0x52" "0x4A" "0x46" "0x3C" "0x00" "0x00" # 0
"0x44" "0x42" "0x7E" "0x40" "0x40" "0x00" "0x00" "0x00" # 1
"0x64" "0x52" "0x52" "0x52" "0x52" "0x4C" "0x00" "0x00" # 2
"0x24" "0x42" "0x42" "0x4A" "0x4A" "0x34" "0x00" "0x00" # 3
"0x30" "0x28" "0x24" "0x7E" "0x20" "0x20" "0x00" "0x00" # 4
"0x2E" "0x4A" "0x4A" "0x4A" "0x4A" "0x32" "0x00" "0x00" # 5
"0x3C" "0x4A" "0x4A" "0x4A" "0x4A" "0x30" "0x00" "0x00" # 6
"0x02" "0x02" "0x62" "0x12" "0x0A" "0x06" "0x00" "0x00" # 7
"0x34" "0x4A" "0x4A" "0x4A" "0x4A" "0x34" "0x00" "0x00" # 8
"0x0C" "0x52" "0x52" "0x52" "0x52" "0x3C" "0x00" "0x00" # 9
"0x00" "0x00" "0x00" "0x48" "0x00" "0x00" "0x00" "0x00" # :
"0x00" "0x00" "0x80" "0x64" "0x00" "0x00" "0x00" "0x00" # ;
"0x00" "0x00" "0x10" "0x28" "0x44" "0x00" "0x00" "0x00" # <
"0x00" "0x28" "0x28" "0x28" "0x28" "0x28" "0x00" "0x00" # =
"0x00" "0x00" "0x44" "0x28" "0x10" "0x00" "0x00" "0x00" # >
"0x00" "0x04" "0x02" "0x02" "0x52" "0x0A" "0x04" "0x00" # ?
"0x00" "0x3C" "0x42" "0x5A" "0x56" "0x5A" "0x1C" "0x00" # @
"0x7C" "0x12" "0x12" "0x12" "0x12" "0x7C" "0x00" "0x00" # A
"0x7E" "0x4A" "0x4A" "0x4A" "0x4A" "0x34" "0x00" "0x00" # B
"0x3C" "0x42" "0x42" "0x42" "0x42" "0x24" "0x00" "0x00" # C
"0x7E" "0x42" "0x42" "0x42" "0x24" "0x18" "0x00" "0x00" # D
"0x7E" "0x4A" "0x4A" "0x4A" "0x4A" "0x42" "0x00" "0x00" # E
"0x7E" "0x0A" "0x0A" "0x0A" "0x0A" "0x02" "0x00" "0x00" # F
"0x3C" "0x42" "0x42" "0x52" "0x52" "0x34" "0x00" "0x00" # G
"0x7E" "0x08" "0x08" "0x08" "0x08" "0x7E" "0x00" "0x00" # H
"0x00" "0x42" "0x42" "0x7E" "0x42" "0x42" "0x00" "0x00" # I
"0x30" "0x40" "0x40" "0x40" "0x40" "0x3E" "0x00" "0x00" # J
"0x7E" "0x08" "0x08" "0x14" "0x22" "0x40" "0x00" "0x00" # K
"0x7E" "0x40" "0x40" "0x40" "0x40" "0x40" "0x00" "0x00" # L
"0x7E" "0x04" "0x08" "0x08" "0x04" "0x7E" "0x00" "0x00" # M
"0x7E" "0x04" "0x08" "0x10" "0x20" "0x7E" "0x00" "0x00" # N
"0x3C" "0x42" "0x42" "0x42" "0x42" "0x3C" "0x00" "0x00" # O
"0x7E" "0x12" "0x12" "0x12" "0x12" "0x0C" "0x00" "0x00" # P
"0x3C" "0x42" "0x52" "0x62" "0x42" "0x3C" "0x00" "0x00" # Q
"0x7E" "0x12" "0x12" "0x12" "0x32" "0x4C" "0x00" "0x00" # R
"0x24" "0x4A" "0x4A" "0x4A" "0x4A" "0x30" "0x00" "0x00" # S
"0x02" "0x02" "0x02" "0x7E" "0x02" "0x02" "0x02" "0x00" # T
"0x3E" "0x40" "0x40" "0x40" "0x40" "0x3E" "0x00" "0x00" # U
"0x1E" "0x20" "0x40" "0x40" "0x20" "0x1E" "0x00" "0x00" # V
"0x3E" "0x40" "0x20" "0x20" "0x40" "0x3E" "0x00" "0x00" # W
"0x42" "0x24" "0x18" "0x18" "0x24" "0x42" "0x00" "0x00" # X
"0x02" "0x04" "0x08" "0x70" "0x08" "0x04" "0x02" "0x00" # Y
"0x42" "0x62" "0x52" "0x4A" "0x46" "0x42" "0x00" "0x00" # Z
"0x00" "0x00" "0x7E" "0x42" "0x42" "0x00" "0x00" "0x00" # [
"0x00" "0x04" "0x08" "0x10" "0x20" "0x40" "0x00" "0x00" # <backslash>
"0x00" "0x00" "0x42" "0x42" "0x7E" "0x00" "0x00" "0x00" # ]
"0x00" "0x08" "0x04" "0x7E" "0x04" "0x08" "0x00" "0x00" # ^
"0x80" "0x80" "0x80" "0x80" "0x80" "0x80" "0x80" "0x00" # _
"0x3C" "0x42" "0x99" "0xA5" "0xA5" "0x81" "0x42" "0x3C" # `
"0x00" "0x20" "0x54" "0x54" "0x54" "0x78" "0x00" "0x00" # a
"0x00" "0x7E" "0x48" "0x48" "0x48" "0x30" "0x00" "0x00" # b
"0x00" "0x00" "0x38" "0x44" "0x44" "0x44" "0x00" "0x00" # c
"0x00" "0x30" "0x48" "0x48" "0x48" "0x7E" "0x00" "0x00" # d
"0x00" "0x38" "0x54" "0x54" "0x54" "0x48" "0x00" "0x00" # e
"0x00" "0x00" "0x00" "0x7C" "0x0A" "0x02" "0x00" "0x00" # f
"0x00" "0x18" "0xA4" "0xA4" "0xA4" "0xA4" "0x7C" "0x00" # g
"0x00" "0x7E" "0x08" "0x08" "0x08" "0x70" "0x00" "0x00" # h
"0x00" "0x00" "0x00" "0x48" "0x7A" "0x40" "0x00" "0x00" # i
"0x00" "0x00" "0x40" "0x80" "0x80" "0x7A" "0x00" "0x00" # j
"0x00" "0x7E" "0x18" "0x24" "0x40" "0x00" "0x00" "0x00" # k
"0x00" "0x00" "0x00" "0x3E" "0x40" "0x40" "0x00" "0x00" # l
"0x00" "0x7C" "0x04" "0x78" "0x04" "0x78" "0x00" "0x00" # m
"0x00" "0x7C" "0x04" "0x04" "0x04" "0x78" "0x00" "0x00" # n
"0x00" "0x38" "0x44" "0x44" "0x44" "0x38" "0x00" "0x00" # o
"0x00" "0xFC" "0x24" "0x24" "0x24" "0x18" "0x00" "0x00" # p
"0x00" "0x18" "0x24" "0x24" "0x24" "0xFC" "0x80" "0x00" # q
"0x00" "0x00" "0x78" "0x04" "0x04" "0x04" "0x00" "0x00" # r
"0x00" "0x48" "0x54" "0x54" "0x54" "0x20" "0x00" "0x00" # s
"0x00" "0x00" "0x04" "0x3E" "0x44" "0x40" "0x00" "0x00" # t
"0x00" "0x3C" "0x40" "0x40" "0x40" "0x3C" "0x00" "0x00" # u
"0x00" "0x0C" "0x30" "0x40" "0x30" "0x0C" "0x00" "0x00" # v
"0x00" "0x3C" "0x40" "0x38" "0x40" "0x3C" "0x00" "0x00" # w
"0x00" "0x44" "0x28" "0x10" "0x28" "0x44" "0x00" "0x00" # x
"0x00" "0x1C" "0xA0" "0xA0" "0xA0" "0x7C" "0x00" "0x00" # y
"0x00" "0x44" "0x64" "0x54" "0x4C" "0x44" "0x00" "0x00" # z
"0x00" "0x08" "0x08" "0x76" "0x42" "0x42" "0x00" "0x00" # {
"0x00" "0x00" "0x00" "0x7E" "0x00" "0x00" "0x00" "0x00" # |
"0x00" "0x42" "0x42" "0x76" "0x08" "0x08" "0x00" "0x00" # }
"0x00" "0x00" "0x04" "0x02" "0x04" "0x02" "0x00" "0x00" # ~
)
# ****************** functions *********************
# Debug function
function dbug() {
if [ "${debug}" = "true" ]; then
echo "${1}" # output debug text
if [ ! -e ${debugfile} ]; then # log file not (!) exists (-e) create it
echo "---------- i2c_oled Debuglog ----------" > ${debugfile}
fi
echo "${1}" >> ${debugfile} # output debug text
fi
}
#ASCII-Functions
#function chr() {
# Get Charcater from ASCII Value (untested)
#printf \\$(printf '%03o' $1)
#[ "$1" -lt 256 ] || return 1
#printf "\$(printf '%03o' "$1")"
#}
function ord() {
# Get ASCII Value from Character
local chardec=$(LC_CTYPE=C printf '%d' "'$1")
[ "${chardec}" -eq 0 ] && chardec=32 # Manual Mod for " " (Space)
echo ${chardec}
#printf '%d' "'$1"
#LC_CTYPE=C printf '%d' "'$1"
}
# Display functions
function display_off() {
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xAE # Display OFF (sleep mode)
sleep 0.01
}
function display_on() {
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xAF # Display ON (normal mode)
sleep 0.01
}
function init_display() {
#i2cset -y ${i2cbus} ${oledaddr} 0xA8 0x3F 0xD3 0x00 0x40 0xA1 0xC8
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xA8 # Set Multiplex Ratio
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x3F # value
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xD3 # Set Display Offset
if [ "${SSD1309}" = "yes" ]; then # SSD1309 Display
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x01 # Set Vertical Shift to 1 for SSD1309
else
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x00 # Set Vertical Shift to 0 for SSD1306/SSH1106
fi
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x40 # Set Display Start Line to 000000b
if [ "${ROTATE}" = "yes" ]; then # By MickGyver
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xA0 # Set Segment Re-map, column address 0 is mapped to SEG0 (horisontal flip)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xC0 # Set COM Output Scan Direction. Scan from COM0 to COM7 (vertical flip)
else
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xA1 # Set Segment Re-map, column address 127 is mapped to SEG0
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xC8 # Set COM Output Scan Direction, remapped mode. Scan from COM7 to COM0
fi
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xDA # Set COM Pins Hardware Configuration
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x12 # Alternative COM pin configuration, Disable COM Left/Right remap needed for 128x64
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x81 # Set Contrast Control
#i2cset -y ${i2cbus} ${oledaddr} 0x00 ${CONTRAST} # value, 0xFF max.
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x05 # value, 0xFF max.
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xA4 # display RAM content
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xA6 # non-inverting display mode - black dots on white background
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xD5 # Set Display Clock (Divide Ratio/Oscillator Frequency)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x80 # max fequency, no divide ratio
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xDB # SSD1306_COMMSELECT
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x20 # 0.77 * VCC (default)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x8D # Charge Pump Setting
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x14 # enable charge pump
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x20 # page addressing mode
#i2cset -y ${i2cbus} ${oledaddr} 0x00 0x00 # horizontal addressing mode
#i2cset -y ${i2cbus} ${oledaddr} 0x00 0x01 # vertical addressing mode
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x02 # page addressing mode (reset)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x2E # Deactivate Scrolling
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x26 # Scrolling Setup
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x00 # Dummy 00h
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x02 # Start Page 2
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x07 # Frame frequency 2 frames (fastest)
#i2cset -y ${i2cbus} ${oledaddr} 0x00 0x00 # Frame frequency 5 frames
#i2cset -y ${i2cbus} ${oledaddr} 0x00 0x06 # Frame frequency 25 frames (slower)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x07 # End Page 7
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x00 # Dummy 00h
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xFF # Dummy FFh
reset_cursor
}
# Set Cursor to top left (0,0)
function reset_cursor() {
if [ "${SSH1106}" = "yes" ]; then
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xB0 # set page address (0xB0...0xB7)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x02 # set column lower 4 Bit (0x02..0x0F) 2 Pixel Offset
i2cset -y ${i2cbus} ${oledaddr} 0x00 0X10 # set column upper 4 Bit (0x10..0x1F)
else
i2cset -y ${i2cbus} ${oledaddr} 0x00 0xB0 # set page address (0xB0...0xB7)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x21 # set column address
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x00 # set start address
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x7F # set end address (127 max)
fi
}
# Set Cursor to x(0..127),y(0..7)
function set_cursor() {
if [ "${SSH1106}" = "yes" ]; then
i2cset -y ${i2cbus} ${oledaddr} 0x00 $(( 0xB0 + ${2} )) # set page address (0xB0...0xB7)
i2cset -y ${i2cbus} ${oledaddr} 0x00 $(( ((${1}+2) & 0x0F) )) # set column lower 4 Bit (0x02..0x0F) 2 Pixel Offset
i2cset -y ${i2cbus} ${oledaddr} 0x00 $(( ((((${1}+2) & 0xF0) >>4) | 0x10) )) # set column upper 4 Bit (0x10..0x1F)
else
i2cset -y ${i2cbus} ${oledaddr} 0x00 $(( 0xB0 + ${2} )) # set page address (0xB0..0xB7)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x21 # set column address
i2cset -y ${i2cbus} ${oledaddr} 0x00 $1 # set column start address (0..127 Pixel)
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x7F # set column end address (..127 max)
fi
}
# Set Contrast
function set_contrast() {
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x81 # Set Contrast Control
i2cset -y ${i2cbus} ${oledaddr} 0x00 ${1} # value, 0xFF max.
}
# Send character data in i mode (#sendi2char "${val}")
function sendi2char() {
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${1} i
}
# fill screen with 0x00, sent each 32 bytes
function clearscreen() {
#reset_cursor # Set Cursor to Top-Left
#echo "clearscreen";
local j=0; local i=0; local val="";
for j in $(seq 0 7); do #Page Adressing Mode
i=0; val="";
set_cursor $i $j
for i in $(seq 0 127); do
val=("${val} 0x00")
if [[ ${i} -eq 31 || ${i} -eq 63 || ${i} -eq 95 || ${i} -eq 127 ]]; then # Send Value every 32 Bytes
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${val} i # Send with "i" Mode
val=""
#sleep 0.5
fi #
done
done
reset_cursor # Set Cursor to Top-Left
}
# fill screen with 0xff, sent each 32 bytes
function flushscreen() {
#reset_cursor # Set Cursor to Top-Left
#echo "flushscreen";
local j=0; local i=0; local val="";
for j in $(seq 0 7); do #Page Adressing Mode
i=0; val="";
set_cursor $i $j
for i in $(seq 0 127); do
val=("${val} 0xff")
if [[ ${i} -eq 31 || ${i} -eq 63 || ${i} -eq 95 || ${i} -eq 127 ]]; then # Send Value every 32 Bytes
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${val} i # Send with "i" Mode
val=""
#sleep 0.5
fi #
done
done
reset_cursor # Set Cursor to Top-Left
}
# Get for each 8-Bit Size Vertical Segment the Bits and send them to be drawn
# Read 8-line-wise the 128 characters long string out of the array and get one char from the given position
# See https://unix.stackexchange.com/questions/9468/how-to-get-the-char-at-a-given-position-of-a-string-in-shell-script
function sendpix() {
#display_off
#reset_cursor
local val=""; local byt=0;
local b0=0; local b1=0; local b2=0; local b3=0; local b4=0; local b5=0; local b6=0; local b7=0
local j=0; local i=0;
#for j in 0 8 16 24 32 40 48 56; do #Vertical Adressoinmg Mode
for j in $(seq 0 7); do #Page Adressing Mode
i=0;
set_cursor $i $j
for i in $(seq 0 127); do
b0=${logo[j*8+0]:${i}:1}
b1=${logo[j*8+1]:${i}:1}
b2=${logo[j*8+2]:${i}:1}
b3=${logo[j*8+3]:${i}:1}
b4=${logo[j*8+4]:${i}:1}
b5=${logo[j*8+5]:${i}:1}
b6=${logo[j*8+6]:${i}:1}
b7=${logo[j*8+7]:${i}:1}
# Invert Header Lines if One-Color Display
if [ "${invert16}" = "yes" ]; then
# Invert only the first 16 (2x8) Lines
if [[ ${j} -eq 0 || ${j} -eq 1 ]]; then
b0=$((1-b0))
b1=$((1-b1))
b2=$((1-b2))
b3=$((1-b3))
b4=$((1-b4))
b5=$((1-b5))
b6=$((1-b6))
b7=$((1-b7))
fi
fi
#echo "${b8} ${b7} ${b6} ${b5} ${b4} ${b3} ${b2} ${b1} = ${val}"
let byt=${b7}*128+${b6}*64+${b5}*32+${b4}*16+${b3}*8+${b2}*4+${b1}*2+${b0}*1 # Bits to Decimal
val=("${val} ${byt}") # The collected Bytes for the "i" Mode
#echo "Byte: ${byt}" # Debugging Byte
#echo "Value: ${val}" # Debugging Value
#sleep 0.1
if [[ ${i} -eq 31 || ${i} -eq 63 || ${i} -eq 95 || ${i} -eq 127 ]]; then # Send Value every 32 Bytes
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${val} i # Send with "i" Mode
val=""
fi #
done # for i
done # for j
#display_on
}
# i2c Show-Picture function
function showpix() {
local corenamepos=0; local corenamelen=0;
pix=""
invert16="no" # Variable for Inverting the first 16 Pixel-Lines
loadX=24; loadY=5; # Starting Position for Loading Icons, used if no picture was found
if [ "${ONECOLOR}" = "yes" ]; then # >>> One-Color Picture
if [ -f "${pripathone}/${1}.${pixextn}" ]; then # Check for an existing OneColor Pri-Picturefolder and proceed
pix=("${pripathone}/${1}.${pixextn}") # Build Pix + Path + Extension
loadX=24; loadY=4;
dbug "Pix: ${pix}" # Debug Pix-Path
elif [ -f "${pixpathone}/${1}.${pixextn}" ]; then # Check for an existing OneColor Picturefolder and proceed
pix=("${pixpathone}/${1}.${pixextn}") # Build Pix + Path + Extension
loadX=24; loadY=4;
dbug "Pix: ${pix}" # Debug Pix-Path
elif [ -f "${pripath}/${1}.${pixextn}" ]; then # Check for an existing Pri-Picturefolder and proceed
pix=("${pripath}/${1}.${pixextn}") # Build Pix + Path + Extension
loadX=24; loadY=5;
dbug "Pix: ${pix}" # Debug Pix-Path
elif [ -f "${pixpath}/${1}.${pixextn}" ]; then # Check for an existing Regular Picturefolder and proceed
pix=("${pixpath}/${1}.${pixextn}") # Build Pix + Path + Extension
loadX=24; loadY=5;
dbug "Pix: ${pix}" # Debug Pix-Path
fi
else # >>> Regular Two-Color Display (Yellow/Blue) <<<
if [ -f "${pripath}/${1}.${pixextn}" ]; then # Check for an existing Pri-Picturefolder and proceed
pix=("${pripath}/${1}.${pixextn}") # Build Pix + Path + Extension
loadX=24; loadY=5;
dbug "Pix: ${pix}" # Debug Pix-Path
elif [ -f "${pixpath}/${1}.${pixextn}" ]; then # Check for an existing Picturefolder and proceed
pix=("${pixpath}/${1}.${pixextn}") # Build Pix + Path + Extension
loadX=24; loadY=5;
dbug "Pix: ${pix}" # Debug Pix-Path
fi
fi
if [ "${INVERTHEADER}" = "yes" ]; then # Invert Header only if a "regular" pix is used
if [[ $(dirname $pix) = ${pixpath} || $(dirname $pix) = ${pripath} ]]; then
invert16="yes" # Activate Invert
fi
fi
if [ -f "${pix}" ]; then # Lookup for an existing PIX and proceed
dbug -e "\nPIX: ${pix}"
if [ "${USE_RANDOM_ALT}" = "yes" ]; then # Use _altX pix?
SAVEIFS="${IFS}"
IFS=$'\n'
ACTPIXFOLDER=$(dirname "${pix}")
dbug "ACTPIXFOLDER: ${ACTPIXFOLDER}"
ALTPIXNUM=$(find "${ACTPIXFOLDER}" -name $(basename "${pix%.*}_alt")* | wc -l)
dbug "ALTPIXNUM: ${ALTPIXNUM}"
IFS="${SAVEIFS}"
if [ "${ALTPIXNUM}" -gt "0" ]; then # If more than 0 _altX pix
ALTPIXRND=$(( ${RANDOM} % $((ALTPIXNUM+1)) )) # then dice between 0 and count of found _altX pix
dbug "ALTPIXRND: ${ALTPIXRND}"
[ "${ALTPIXRND}" -gt 0 ] && pix="${ACTPIXFOLDER}/${1}_alt"${ALTPIXRND}".${pixextn}"
fi # If 0 then original picture, otherwise _altX pix
dbug "PIX: ${pix}"
fi
source ${pix} # Load Picture Array
sendpix # ..and show it
else # ! No Picture available !
if [ "${ONECOLOR}" = "yes" ]; then # >>> One-Color Picture
if [ -f "${misterheaderpixone}" ]; then # Lookup for the Empty-Header-PIX and proceed
source ${misterheaderpixone} # Load Picture Array for "Empty Header" if available
sendpix # ..and show it
elif [ -f "${misterheaderpix}" ]; then # Lookup for the Empty-Header-PIX and proceed
source ${misterheaderpix} # Load Picture Array for "Empty Header" if available
sendpix # ..and show it
else
clearscreen # No Picture found = ClearScreen
fi
else # >>> Regular Two-Color Display (Yellow/Blue) <<<
if [ -f "${misterheaderpix}" ]; then # Lookup for the Empty-Header-PIX and proceed
source ${misterheaderpix} # Load Picture Array for "Empty Header" if available
sendpix # ..and show it
else
clearscreen # No Picture found = ClearScreen
fi
fi
corenamelen=${#1} # Get lenght of Corename
let corenamepos=(127-corenamelen*8)/2 # Calculate X Position
set_cursor ${corenamepos} 4 # Set Cursor Position at Page 4
showtext ${1} # Show the Corename
dbug -e "\nTEXT-PIX: ${1}"
fi
}
# Show Text using included 8x8 font
function showtext() {
local a=0; local b=0; local achar=0; local charp=0; local charout="";
local text=${1}
local textlen=${#text}
#echo "dbug text: ${text}"
#echo "dbug textlen: ${textlen}"
dbug "Textlen: ${textlen}"
for (( a=0; a<${textlen}; a++ )); do
achar="`ord ${text:${a}:1}`" # get the ASCII Code
let charp=(achar-32)*${font_width} # calculate first byte in font array
charout=""
for (( b=0; b<${font_width}; b++ )); do # character loop
charout="${charout} ${font[charp+b]}" # build character out of single values
done
dbug "${a}: ${text:${a}:1} -> ${achar} -> ${charp} -> ${charout}"
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${charout} i # send character bytes to display
done
}
# Show Pressplay PIX with little Animation
function pressplay () {
local t=0;
if [ "${BLACKOUT}" = "yes" ]; then
display_off
fi
showpix pressplay
display_on
# Testing Font-Based-Animation
for (( t=0; t<5; t++)); do
set_cursor 48 4
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${itape1} i
set_cursor 64 4
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${itape2} i
sleep 0.3
set_cursor 48 4
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${itape2} i
set_cursor 64 4
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${itape1} i
sleep 0.3
done
}
# Show Loading Screen
function loading () {
local t=0;
if [ "${BLACKOUT}" = "yes" ]; then
display_off
fi
showpix loading
display_on
set_cursor ${loadX} ${loadY} # Cursor Position for OneColor Display
sleep 0.75
for t in 0.5 0.45 0.4 0.35 0.3 0.25 0.2 0.15 1.0 0.1; do # going faster each step
if (( ${1} == 1 )); then
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${iload1} i # Loading Icon 1
elif (( ${1} == 2 )); then
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${iload2} i # Loading Icon 2
elif (( ${1} == 3 )); then
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${iload3} i # Loading Icon 3
elif (( ${1} == 4 )); then
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${iload4} i # Loading Icon 4
fi
sleep ${t} # going faster each step
done
sleep 0.5
}
# NCC1701 Warp 5
function warp5 () {
local t=0;
if [ "${BLACKOUT}" = "yes" ]; then
display_off
fi
showpix ncc1701
display_on
sleep 1
for (( t=0; t<2; t++ )); do
#for (( t=0; t<5; t++ )); do
set_cursor 56 4
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${iwarp2} i
sleep 0.5
set_cursor 56 4
i2cset -y ${i2cbus} ${oledaddr} 0x40 ${iwarp1} i
sleep 0.5
done
#set_cursor 40 7
#showtext "Warp 5"
#sleep 2
set_cursor 40 7
showtext "Energy"
sleep 1
set_cursor 40 7
showtext " "
sleep 0.1
# Activate Scrolling
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x2F
sleep 2.5
# Deactivate Scrolling
i2cset -y ${i2cbus} ${oledaddr} 0x00 0x2E
sleep 0.5
}
#set default configuration
function init_temperature_default_config(){
dbug "Debuginfo: Init Sensor"
i2cset -y $AD7414_I2CBUS $AD7414_DEVADDR $AD7414_CONF $AD7414_DEF_CONF
}
#read temperature value register
function show_temperature() {
local raw_val=$(($(i2cget -y $AD7414_I2CBUS $AD7414_DEVADDR $AD7414_VAL w)))
local lo_val=$(("$raw_val">>14))
local hi_val=$(("$raw_val"&0xff))
local code_val=$(("$lo_val"|$(("$hi_val"<<2))))
if [ $(( "$hi_val" & 0x80)) -ne 0 ]; then
code_val=$(($code_val - 512))
fi
set_cursor $SHOW_TEMP_ROW $SHOW_TEMP_COL # Set Cursor at Page Row and Column
showtext $(printf "%.2f" $(echo $code_val / 4 | bc -l) ) # Some Text for the Display
#showtext $(printf "%s" $(date "+%T") ) # Testing the function without the Sensor
#sleep 1
}
#About/Thanks to.. (THEEASTEREGG) :-)
function manythanksto() {
clearscreen
display_on
set_cursor 0 0
showtext " By venice (C)"
set_cursor 0 1
showtext "Many Thanks to.."
set_cursor 0 2
showtext "-Mick Gyver"
set_cursor 0 3
showtext "-Marcelosofth"
set_cursor 0 4
showtext "-Ingloriond"
set_cursor 0 5
showtext "-OJaksch"
set_cursor 0 6
showtext "-mr-fitzie"
}
# ************************** End Functions **********************************