-
Notifications
You must be signed in to change notification settings - Fork 4
/
fourteensegment.js
130 lines (122 loc) · 4.86 KB
/
fourteensegment.js
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
import { createMatrix } from './main';
function fixBitmap(bitmap) {
let newBitmap = bitmap
.filter(value => value !== undefined)
.map(num => num);
for (var i = newBitmap.length; i < 4; i++) {
newBitmap.unshift([0, 0]);
}
return newBitmap;
}
function charToFourteenSegment(char) {
const CHARS = {
" ": [0b00000000, 0b00000000],
"!": [0b00000110, 0b01000000],
"\"": [0b00100000, 0b00000010],
"#": [0b11001110, 0b00010010],
"$": [0b11101101, 0b00010010],
"%": [0b00100100, 0b00001100],
"&": [0b01011101, 0b00100011],
"'": [0b00000000, 0b00000100],
"(": [0b00000000, 0b00100100],
")": [0b00000000, 0b00001001],
"*": [0b11000000, 0b00111111],
"+": [0b11000000, 0b00010010],
",": [0b00000000, 0b00001000],
"-": [0b11000000, 0b00000000],
"/": [0b00000000, 0b00001100],
"0": [0b00111111, 0b00001100],
"1": [0b00000110, 0b00000000],
"2": [0b11011011, 0b00000000],
"3": [0b10001111, 0b00000000],
"4": [0b11100110, 0b00000000],
"5": [0b01101001, 0b00100000],
"6": [0b11111101, 0b00000000],
"7": [0b00000111, 0b00000000],
"8": [0b11111111, 0b00000000],
"9": [0b11101111, 0b00000000],
":": [0b00000000, 0b00010010],
";": [0b00000000, 0b00001010],
"<": [0b01000000, 0b00100100],
"=": [0b11001000, 0b00000000],
">": [0b10000000, 0b00001001],
"?": [0b10100011, 0b01100000],
"@": [0b10111011, 0b00000010],
"A": [0b11110111, 0b00000000],
"B": [0b10001111, 0b00010010],
"C": [0b00111001, 0b00000000],
"D": [0b00001111, 0b00010010],
"E": [0b11111001, 0b00000000],
"F": [0b01110001, 0b00000000],
"G": [0b10111101, 0b00000000],
"H": [0b11110110, 0b00000000],
"I": [0b00000000, 0b00010010],
"J": [0b00011110, 0b00000000],
"K": [0b01110000, 0b00100100],
"L": [0b00111000, 0b00000000],
"M": [0b00110110, 0b00000101],
"N": [0b00110110, 0b00100001],
"O": [0b00111111, 0b00000000],
"P": [0b11110011, 0b00000000],
"Q": [0b00111111, 0b00100000],
"R": [0b11110011, 0b00100000],
"S": [0b11101101, 0b00000000],
"T": [0b00000001, 0b00010010],
"U": [0b00111110, 0b00000000],
"V": [0b00110000, 0b00001100],
"W": [0b00110110, 0b00101000],
"X": [0b00000000, 0b00101101],
"Y": [0b00000000, 0b00010101],
"Z": [0b00001001, 0b00001100],
"[": [0b00111001, 0b00000000],
"\\": [0b00000000, 0b00100001],
"]": [0b00001111, 0b00000000],
"^": [0b00000011, 0b00001100],
"_": [0b00001000, 0b00000000],
"`": [0b00000000, 0b00000001],
"a": [0b01011000, 0b00010000],
"b": [0b01111000, 0b00100000],
"c": [0b11011000, 0b00000000],
"d": [0b10001110, 0b00001000],
"e": [0b01011000, 0b00001000],
"f": [0b01110001, 0b00000000],
"g": [0b10001110, 0b00000100],
"h": [0b01110000, 0b00010000],
"i": [0b00000000, 0b00010000],
"j": [0b00001110, 0b00000000],
"k": [0b00000000, 0b00110110],
"l": [0b00110000, 0b00000000],
"m": [0b11010100, 0b00010000],
"n": [0b01010000, 0b00010000],
"o": [0b11011100, 0b00000000],
"p": [0b01110000, 0b00000001],
"q": [0b10000110, 0b00000100],
"r": [0b01010000, 0b00000000],
"s": [0b10001000, 0b00100000],
"t": [0b01111000, 0b00000000],
"u": [0b00011100, 0b00000000],
"v": [0b00000100, 0b00100000],
"w": [0b00010100, 0b00101000],
"x": [0b11000000, 0b00101000],
"y": [0b00001100, 0b00100000],
"z": [0b01001000, 0b00001000],
"{": [0b01001001, 0b00001001],
"|": [0b00000000, 0b00010010],
"}": [0b10001001, 0b00100100],
"~": [0b00100000, 0b00000101]
};
const FILL = [0b11111111, 0b00111111];
const charArray = CHARS[char];
return charArray && charArray.map(value => value);
}
function format(numberOrStringOrArray) {
const stringRep = Array.isArray(numberOrStringOrArray) ? numberOrStringOrArray.join('') : numberOrStringOrArray.toString();
const chars = stringRep.split('');
const dotIndicies = chars.map((value, i) => value === '.' ? i : -1).filter(value => value != -1);
const bitmap = chars.map(charToFourteenSegment);
dotIndicies.forEach(value => bitmap[value - 1][1] |= 1 << 6);
return fixBitmap(bitmap);
}
export default function connect(setup, write, address, brightness) {
return createMatrix(setup, format, write, address, brightness);
}