SSD1306 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ea085c6f2b0ca893831ef89ad16d4cf8495e391
4
- data.tar.gz: 117b319e6813e0ec9272792facd3055681ddb1c6
3
+ metadata.gz: 7f6bdd49eb64a9f801a61eb64b7135a148ea3f03
4
+ data.tar.gz: 962e75ce784a53d16171ae9b9b83ab1d6f970d6c
5
5
  SHA512:
6
- metadata.gz: 62238d881b8f692ebc98e85020df5e739d38613d986dd4dc77e937efffe93d3cf8b8098efe70f15e13550f30f0d1e3d1d1534ed32ec821cf39e80c36e4bb75ef
7
- data.tar.gz: dbfdf5c35ae2e5a09b0930c96cbe7ca29f2e99f06516ce46a6aa0723135a29db027d18d81e3f7c6184724f8f060701aa3e630804d7d6f3244b9fcd2f903fbd70
6
+ metadata.gz: f5d166a8a28ba37a08e73a11a56dbf1c60954601aff8125cade56c268e17d8fdd28521691e3f7c0c4a2f7edb5e11e4dff5981cbda794534fcd6802cb087f38b3
7
+ data.tar.gz: 261705f1e7e3ffe51360734d60ecca7893f297c1dfe7d4f70fc954d7bd5e5b23cac4ce6d17cc100c56765a88720a6838576d69df9f6906e3da362b421e6d9b5d
@@ -0,0 +1,41 @@
1
+ module SSD1306
2
+ class Cursor
3
+ attr_accessor :size, :x_pos, :y_pos
4
+
5
+ def initialize
6
+ @size = 1
7
+ @x_pos = 0
8
+ @y_pos = 0
9
+ end
10
+
11
+ def increment
12
+ if @x_pos >= (126 - 5*@size)
13
+ newline
14
+ else
15
+ @x_pos += 5*size
16
+ end
17
+ end
18
+
19
+ def newline
20
+ @x_pos = 0
21
+ @y_pos += 8*size
22
+ end
23
+
24
+ def set_pos(x, y)
25
+ @x_pos = x
26
+ @y_pos = y
27
+ end
28
+
29
+ def buffer_index
30
+ page = @y_pos / 8
31
+ index = (page*128) + @x_pos
32
+ end
33
+
34
+ def position_in_buffer
35
+ index = buffer_index
36
+ page = @y_pos / 8
37
+ offset = @y_pos % 8
38
+ {index: index, x: @x_pos, page: page, page_offset: offset}
39
+ end
40
+ end
41
+ end
@@ -183,6 +183,11 @@ module SSD1306
183
183
  self.print_char 10 # 10 is ASCII for \n
184
184
  end
185
185
 
186
+ #TODO Do font_size
187
+ def font_size(new_size)
188
+ raise "font_size not yet implemented"
189
+ end
190
+
186
191
  #TODO Implement Contrast functionality
187
192
  def set_contrast(contrast)
188
193
  raise "Contrast not yet implemented"
@@ -193,12 +198,20 @@ module SSD1306
193
198
  raise "Dim not implemented yet"
194
199
  end
195
200
 
196
- private
201
+ protected
202
+
203
+ # This skips to a newlien if the byte is a LF newline,
204
+ # otherwise it prints the character, but only if it is
205
+ # in fact a character (i.e., ASCII greater than 31).
197
206
  def print_char(b)
198
- for i in 0...5
199
- @buffer[@cursor.buffer_index + i] = FONT[(b*5) + i]
207
+ if b == 10
208
+ @cursor.newline
209
+ elsif b > 31
210
+ for i in 0...5
211
+ @buffer[@cursor.buffer_index + i] = FONT[(b*5) + i]
212
+ end
213
+ @cursor.increment
200
214
  end
201
- @cursor.increment
202
215
  end
203
216
  end
204
217
  end
@@ -0,0 +1,260 @@
1
+ module SSD1306
2
+ FONT = [
3
+ 0x00, 0x00, 0x00, 0x00, 0x00,
4
+ 0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
5
+ 0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
6
+ 0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
7
+ 0x18, 0x3C, 0x7E, 0x3C, 0x18,
8
+ 0x1C, 0x57, 0x7D, 0x57, 0x1C,
9
+ 0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
10
+ 0x00, 0x18, 0x3C, 0x18, 0x00,
11
+ 0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
12
+ 0x00, 0x18, 0x24, 0x18, 0x00,
13
+ 0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
14
+ 0x30, 0x48, 0x3A, 0x06, 0x0E,
15
+ 0x26, 0x29, 0x79, 0x29, 0x26,
16
+ 0x40, 0x7F, 0x05, 0x05, 0x07,
17
+ 0x40, 0x7F, 0x05, 0x25, 0x3F,
18
+ 0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
19
+ 0x7F, 0x3E, 0x1C, 0x1C, 0x08,
20
+ 0x08, 0x1C, 0x1C, 0x3E, 0x7F,
21
+ 0x14, 0x22, 0x7F, 0x22, 0x14,
22
+ 0x5F, 0x5F, 0x00, 0x5F, 0x5F,
23
+ 0x06, 0x09, 0x7F, 0x01, 0x7F,
24
+ 0x00, 0x66, 0x89, 0x95, 0x6A,
25
+ 0x60, 0x60, 0x60, 0x60, 0x60,
26
+ 0x94, 0xA2, 0xFF, 0xA2, 0x94,
27
+ 0x08, 0x04, 0x7E, 0x04, 0x08,
28
+ 0x10, 0x20, 0x7E, 0x20, 0x10,
29
+ 0x08, 0x08, 0x2A, 0x1C, 0x08,
30
+ 0x08, 0x1C, 0x2A, 0x08, 0x08,
31
+ 0x1E, 0x10, 0x10, 0x10, 0x10,
32
+ 0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
33
+ 0x30, 0x38, 0x3E, 0x38, 0x30,
34
+ 0x06, 0x0E, 0x3E, 0x0E, 0x06,
35
+ 0x00, 0x00, 0x00, 0x00, 0x00,
36
+ 0x00, 0x00, 0x5F, 0x00, 0x00,
37
+ 0x00, 0x07, 0x00, 0x07, 0x00,
38
+ 0x14, 0x7F, 0x14, 0x7F, 0x14,
39
+ 0x24, 0x2A, 0x7F, 0x2A, 0x12,
40
+ 0x23, 0x13, 0x08, 0x64, 0x62,
41
+ 0x36, 0x49, 0x56, 0x20, 0x50,
42
+ 0x00, 0x08, 0x07, 0x03, 0x00,
43
+ 0x00, 0x1C, 0x22, 0x41, 0x00,
44
+ 0x00, 0x41, 0x22, 0x1C, 0x00,
45
+ 0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
46
+ 0x08, 0x08, 0x3E, 0x08, 0x08,
47
+ 0x00, 0x80, 0x70, 0x30, 0x00,
48
+ 0x08, 0x08, 0x08, 0x08, 0x08,
49
+ 0x00, 0x00, 0x60, 0x60, 0x00,
50
+ 0x20, 0x10, 0x08, 0x04, 0x02,
51
+ 0x3E, 0x51, 0x49, 0x45, 0x3E,
52
+ 0x00, 0x42, 0x7F, 0x40, 0x00,
53
+ 0x72, 0x49, 0x49, 0x49, 0x46,
54
+ 0x21, 0x41, 0x49, 0x4D, 0x33,
55
+ 0x18, 0x14, 0x12, 0x7F, 0x10,
56
+ 0x27, 0x45, 0x45, 0x45, 0x39,
57
+ 0x3C, 0x4A, 0x49, 0x49, 0x31,
58
+ 0x41, 0x21, 0x11, 0x09, 0x07,
59
+ 0x36, 0x49, 0x49, 0x49, 0x36,
60
+ 0x46, 0x49, 0x49, 0x29, 0x1E,
61
+ 0x00, 0x00, 0x14, 0x00, 0x00,
62
+ 0x00, 0x40, 0x34, 0x00, 0x00,
63
+ 0x00, 0x08, 0x14, 0x22, 0x41,
64
+ 0x14, 0x14, 0x14, 0x14, 0x14,
65
+ 0x00, 0x41, 0x22, 0x14, 0x08,
66
+ 0x02, 0x01, 0x59, 0x09, 0x06,
67
+ 0x3E, 0x41, 0x5D, 0x59, 0x4E,
68
+ 0x7C, 0x12, 0x11, 0x12, 0x7C,
69
+ 0x7F, 0x49, 0x49, 0x49, 0x36,
70
+ 0x3E, 0x41, 0x41, 0x41, 0x22,
71
+ 0x7F, 0x41, 0x41, 0x41, 0x3E,
72
+ 0x7F, 0x49, 0x49, 0x49, 0x41,
73
+ 0x7F, 0x09, 0x09, 0x09, 0x01,
74
+ 0x3E, 0x41, 0x41, 0x51, 0x73,
75
+ 0x7F, 0x08, 0x08, 0x08, 0x7F,
76
+ 0x00, 0x41, 0x7F, 0x41, 0x00,
77
+ 0x20, 0x40, 0x41, 0x3F, 0x01,
78
+ 0x7F, 0x08, 0x14, 0x22, 0x41,
79
+ 0x7F, 0x40, 0x40, 0x40, 0x40,
80
+ 0x7F, 0x02, 0x1C, 0x02, 0x7F,
81
+ 0x7F, 0x04, 0x08, 0x10, 0x7F,
82
+ 0x3E, 0x41, 0x41, 0x41, 0x3E,
83
+ 0x7F, 0x09, 0x09, 0x09, 0x06,
84
+ 0x3E, 0x41, 0x51, 0x21, 0x5E,
85
+ 0x7F, 0x09, 0x19, 0x29, 0x46,
86
+ 0x26, 0x49, 0x49, 0x49, 0x32,
87
+ 0x03, 0x01, 0x7F, 0x01, 0x03,
88
+ 0x3F, 0x40, 0x40, 0x40, 0x3F,
89
+ 0x1F, 0x20, 0x40, 0x20, 0x1F,
90
+ 0x3F, 0x40, 0x38, 0x40, 0x3F,
91
+ 0x63, 0x14, 0x08, 0x14, 0x63,
92
+ 0x03, 0x04, 0x78, 0x04, 0x03,
93
+ 0x61, 0x59, 0x49, 0x4D, 0x43,
94
+ 0x00, 0x7F, 0x41, 0x41, 0x41,
95
+ 0x02, 0x04, 0x08, 0x10, 0x20,
96
+ 0x00, 0x41, 0x41, 0x41, 0x7F,
97
+ 0x04, 0x02, 0x01, 0x02, 0x04,
98
+ 0x40, 0x40, 0x40, 0x40, 0x40,
99
+ 0x00, 0x03, 0x07, 0x08, 0x00,
100
+ 0x20, 0x54, 0x54, 0x78, 0x40,
101
+ 0x7F, 0x28, 0x44, 0x44, 0x38,
102
+ 0x38, 0x44, 0x44, 0x44, 0x28,
103
+ 0x38, 0x44, 0x44, 0x28, 0x7F,
104
+ 0x38, 0x54, 0x54, 0x54, 0x18,
105
+ 0x00, 0x08, 0x7E, 0x09, 0x02,
106
+ 0x18, 0xA4, 0xA4, 0x9C, 0x78,
107
+ 0x7F, 0x08, 0x04, 0x04, 0x78,
108
+ 0x00, 0x44, 0x7D, 0x40, 0x00,
109
+ 0x20, 0x40, 0x40, 0x3D, 0x00,
110
+ 0x7F, 0x10, 0x28, 0x44, 0x00,
111
+ 0x00, 0x41, 0x7F, 0x40, 0x00,
112
+ 0x7C, 0x04, 0x78, 0x04, 0x78,
113
+ 0x7C, 0x08, 0x04, 0x04, 0x78,
114
+ 0x38, 0x44, 0x44, 0x44, 0x38,
115
+ 0xFC, 0x18, 0x24, 0x24, 0x18,
116
+ 0x18, 0x24, 0x24, 0x18, 0xFC,
117
+ 0x7C, 0x08, 0x04, 0x04, 0x08,
118
+ 0x48, 0x54, 0x54, 0x54, 0x24,
119
+ 0x04, 0x04, 0x3F, 0x44, 0x24,
120
+ 0x3C, 0x40, 0x40, 0x20, 0x7C,
121
+ 0x1C, 0x20, 0x40, 0x20, 0x1C,
122
+ 0x3C, 0x40, 0x30, 0x40, 0x3C,
123
+ 0x44, 0x28, 0x10, 0x28, 0x44,
124
+ 0x4C, 0x90, 0x90, 0x90, 0x7C,
125
+ 0x44, 0x64, 0x54, 0x4C, 0x44,
126
+ 0x00, 0x08, 0x36, 0x41, 0x00,
127
+ 0x00, 0x00, 0x77, 0x00, 0x00,
128
+ 0x00, 0x41, 0x36, 0x08, 0x00,
129
+ 0x02, 0x01, 0x02, 0x04, 0x02,
130
+ 0x3C, 0x26, 0x23, 0x26, 0x3C,
131
+ 0x1E, 0xA1, 0xA1, 0x61, 0x12,
132
+ 0x3A, 0x40, 0x40, 0x20, 0x7A,
133
+ 0x38, 0x54, 0x54, 0x55, 0x59,
134
+ 0x21, 0x55, 0x55, 0x79, 0x41,
135
+ 0x22, 0x54, 0x54, 0x78, 0x42,
136
+ 0x21, 0x55, 0x54, 0x78, 0x40,
137
+ 0x20, 0x54, 0x55, 0x79, 0x40,
138
+ 0x0C, 0x1E, 0x52, 0x72, 0x12,
139
+ 0x39, 0x55, 0x55, 0x55, 0x59,
140
+ 0x39, 0x54, 0x54, 0x54, 0x59,
141
+ 0x39, 0x55, 0x54, 0x54, 0x58,
142
+ 0x00, 0x00, 0x45, 0x7C, 0x41,
143
+ 0x00, 0x02, 0x45, 0x7D, 0x42,
144
+ 0x00, 0x01, 0x45, 0x7C, 0x40,
145
+ 0x7D, 0x12, 0x11, 0x12, 0x7D,
146
+ 0xF0, 0x28, 0x25, 0x28, 0xF0,
147
+ 0x7C, 0x54, 0x55, 0x45, 0x00,
148
+ 0x20, 0x54, 0x54, 0x7C, 0x54,
149
+ 0x7C, 0x0A, 0x09, 0x7F, 0x49,
150
+ 0x32, 0x49, 0x49, 0x49, 0x32,
151
+ 0x3A, 0x44, 0x44, 0x44, 0x3A,
152
+ 0x32, 0x4A, 0x48, 0x48, 0x30,
153
+ 0x3A, 0x41, 0x41, 0x21, 0x7A,
154
+ 0x3A, 0x42, 0x40, 0x20, 0x78,
155
+ 0x00, 0x9D, 0xA0, 0xA0, 0x7D,
156
+ 0x3D, 0x42, 0x42, 0x42, 0x3D,
157
+ 0x3D, 0x40, 0x40, 0x40, 0x3D,
158
+ 0x3C, 0x24, 0xFF, 0x24, 0x24,
159
+ 0x48, 0x7E, 0x49, 0x43, 0x66,
160
+ 0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
161
+ 0xFF, 0x09, 0x29, 0xF6, 0x20,
162
+ 0xC0, 0x88, 0x7E, 0x09, 0x03,
163
+ 0x20, 0x54, 0x54, 0x79, 0x41,
164
+ 0x00, 0x00, 0x44, 0x7D, 0x41,
165
+ 0x30, 0x48, 0x48, 0x4A, 0x32,
166
+ 0x38, 0x40, 0x40, 0x22, 0x7A,
167
+ 0x00, 0x7A, 0x0A, 0x0A, 0x72,
168
+ 0x7D, 0x0D, 0x19, 0x31, 0x7D,
169
+ 0x26, 0x29, 0x29, 0x2F, 0x28,
170
+ 0x26, 0x29, 0x29, 0x29, 0x26,
171
+ 0x30, 0x48, 0x4D, 0x40, 0x20,
172
+ 0x38, 0x08, 0x08, 0x08, 0x08,
173
+ 0x08, 0x08, 0x08, 0x08, 0x38,
174
+ 0x2F, 0x10, 0xC8, 0xAC, 0xBA,
175
+ 0x2F, 0x10, 0x28, 0x34, 0xFA,
176
+ 0x00, 0x00, 0x7B, 0x00, 0x00,
177
+ 0x08, 0x14, 0x2A, 0x14, 0x22,
178
+ 0x22, 0x14, 0x2A, 0x14, 0x08,
179
+ 0x55, 0x00, 0x55, 0x00, 0x55,
180
+ 0xAA, 0x55, 0xAA, 0x55, 0xAA,
181
+ 0xFF, 0x55, 0xFF, 0x55, 0xFF,
182
+ 0x00, 0x00, 0x00, 0xFF, 0x00,
183
+ 0x10, 0x10, 0x10, 0xFF, 0x00,
184
+ 0x14, 0x14, 0x14, 0xFF, 0x00,
185
+ 0x10, 0x10, 0xFF, 0x00, 0xFF,
186
+ 0x10, 0x10, 0xF0, 0x10, 0xF0,
187
+ 0x14, 0x14, 0x14, 0xFC, 0x00,
188
+ 0x14, 0x14, 0xF7, 0x00, 0xFF,
189
+ 0x00, 0x00, 0xFF, 0x00, 0xFF,
190
+ 0x14, 0x14, 0xF4, 0x04, 0xFC,
191
+ 0x14, 0x14, 0x17, 0x10, 0x1F,
192
+ 0x10, 0x10, 0x1F, 0x10, 0x1F,
193
+ 0x14, 0x14, 0x14, 0x1F, 0x00,
194
+ 0x10, 0x10, 0x10, 0xF0, 0x00,
195
+ 0x00, 0x00, 0x00, 0x1F, 0x10,
196
+ 0x10, 0x10, 0x10, 0x1F, 0x10,
197
+ 0x10, 0x10, 0x10, 0xF0, 0x10,
198
+ 0x00, 0x00, 0x00, 0xFF, 0x10,
199
+ 0x10, 0x10, 0x10, 0x10, 0x10,
200
+ 0x10, 0x10, 0x10, 0xFF, 0x10,
201
+ 0x00, 0x00, 0x00, 0xFF, 0x14,
202
+ 0x00, 0x00, 0xFF, 0x00, 0xFF,
203
+ 0x00, 0x00, 0x1F, 0x10, 0x17,
204
+ 0x00, 0x00, 0xFC, 0x04, 0xF4,
205
+ 0x14, 0x14, 0x17, 0x10, 0x17,
206
+ 0x14, 0x14, 0xF4, 0x04, 0xF4,
207
+ 0x00, 0x00, 0xFF, 0x00, 0xF7,
208
+ 0x14, 0x14, 0x14, 0x14, 0x14,
209
+ 0x14, 0x14, 0xF7, 0x00, 0xF7,
210
+ 0x14, 0x14, 0x14, 0x17, 0x14,
211
+ 0x10, 0x10, 0x1F, 0x10, 0x1F,
212
+ 0x14, 0x14, 0x14, 0xF4, 0x14,
213
+ 0x10, 0x10, 0xF0, 0x10, 0xF0,
214
+ 0x00, 0x00, 0x1F, 0x10, 0x1F,
215
+ 0x00, 0x00, 0x00, 0x1F, 0x14,
216
+ 0x00, 0x00, 0x00, 0xFC, 0x14,
217
+ 0x00, 0x00, 0xF0, 0x10, 0xF0,
218
+ 0x10, 0x10, 0xFF, 0x10, 0xFF,
219
+ 0x14, 0x14, 0x14, 0xFF, 0x14,
220
+ 0x10, 0x10, 0x10, 0x1F, 0x00,
221
+ 0x00, 0x00, 0x00, 0xF0, 0x10,
222
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
223
+ 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
224
+ 0xFF, 0xFF, 0xFF, 0x00, 0x00,
225
+ 0x00, 0x00, 0x00, 0xFF, 0xFF,
226
+ 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
227
+ 0x38, 0x44, 0x44, 0x38, 0x44,
228
+ 0xFC, 0x4A, 0x4A, 0x4A, 0x34,
229
+ 0x7E, 0x02, 0x02, 0x06, 0x06,
230
+ 0x02, 0x7E, 0x02, 0x7E, 0x02,
231
+ 0x63, 0x55, 0x49, 0x41, 0x63,
232
+ 0x38, 0x44, 0x44, 0x3C, 0x04,
233
+ 0x40, 0x7E, 0x20, 0x1E, 0x20,
234
+ 0x06, 0x02, 0x7E, 0x02, 0x02,
235
+ 0x99, 0xA5, 0xE7, 0xA5, 0x99,
236
+ 0x1C, 0x2A, 0x49, 0x2A, 0x1C,
237
+ 0x4C, 0x72, 0x01, 0x72, 0x4C,
238
+ 0x30, 0x4A, 0x4D, 0x4D, 0x30,
239
+ 0x30, 0x48, 0x78, 0x48, 0x30,
240
+ 0xBC, 0x62, 0x5A, 0x46, 0x3D,
241
+ 0x3E, 0x49, 0x49, 0x49, 0x00,
242
+ 0x7E, 0x01, 0x01, 0x01, 0x7E,
243
+ 0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
244
+ 0x44, 0x44, 0x5F, 0x44, 0x44,
245
+ 0x40, 0x51, 0x4A, 0x44, 0x40,
246
+ 0x40, 0x44, 0x4A, 0x51, 0x40,
247
+ 0x00, 0x00, 0xFF, 0x01, 0x03,
248
+ 0xE0, 0x80, 0xFF, 0x00, 0x00,
249
+ 0x08, 0x08, 0x6B, 0x6B, 0x08,
250
+ 0x36, 0x12, 0x36, 0x24, 0x36,
251
+ 0x06, 0x0F, 0x09, 0x0F, 0x06,
252
+ 0x00, 0x00, 0x18, 0x18, 0x00,
253
+ 0x00, 0x00, 0x10, 0x10, 0x00,
254
+ 0x30, 0x40, 0xFF, 0x01, 0x01,
255
+ 0x00, 0x1F, 0x01, 0x01, 0x1E,
256
+ 0x00, 0x19, 0x1D, 0x17, 0x12,
257
+ 0x00, 0x3C, 0x3C, 0x3C, 0x3C,
258
+ 0x00, 0x00, 0x00, 0x00, 0x00
259
+ ]
260
+ end
@@ -1,3 +1,3 @@
1
1
  module SSD1306
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SSD1306
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Bick
@@ -100,7 +100,9 @@ files:
100
100
  - bin/setup
101
101
  - exe/SSD1306
102
102
  - lib/SSD1306.rb
103
+ - lib/SSD1306/cursor.rb
103
104
  - lib/SSD1306/display.rb
105
+ - lib/SSD1306/font.rb
104
106
  - lib/SSD1306/version.rb
105
107
  homepage: https://github.com/zeiv/SSD1306-ruby
106
108
  licenses: