oled-control 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/oled-control/oled-control-gem.c +4 -3
- data/ext/oled-control/oled-control.c +8 -5
- data/ext/oled-control/oled-control.h +1 -0
- data/lib/oled-control/oled.rb +9 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ef89f0ae721f6a29e325cdd5d199b753b491c13
|
4
|
+
data.tar.gz: a9b4f40492ec195919a67c047374e13ad98902de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d80555c9096337a726bab1d64eae0bc061009633f452468cd405e0ca16d276a3255539c2530d800b7d579c83d6927a1837e6d89fbdcc8edbdf01b6100575195d
|
7
|
+
data.tar.gz: fbd3bf62f01f7611cae76cc81da193c278691c4e40f6e55ecdc8b56d4568fb4656dd63b82936c2c40aa29b8565a0cf5b6406d68178c5dfa20337d6f17bdb05cf
|
@@ -16,9 +16,10 @@ static VALUE set_cursor(VALUE self, VALUE col, VALUE row) {
|
|
16
16
|
return Qtrue;
|
17
17
|
}
|
18
18
|
|
19
|
-
static VALUE write_string(VALUE self, VALUE str) {
|
19
|
+
static VALUE write_string(VALUE self, VALUE str, VALUE len) {
|
20
20
|
const char *s = RSTRING_PTR(str);
|
21
|
-
|
21
|
+
size_t length = NUM2SIZET(len);
|
22
|
+
if(!i2c_write_n_bytes(DATA, s, length))
|
22
23
|
rb_raise(rb_eRuntimeError, "unable to write string to display");
|
23
24
|
|
24
25
|
return Qtrue;
|
@@ -119,6 +120,6 @@ void Init_oled_control(void) {
|
|
119
120
|
rb_define_method(klass, "create_character", create_character, 2);
|
120
121
|
rb_define_protected_method(klass, "send_command", send_command, 1);
|
121
122
|
rb_define_protected_method(klass, "send_raw_command", send_raw_command, 1);
|
122
|
-
rb_define_protected_method(klass, "write_string", write_string,
|
123
|
+
rb_define_protected_method(klass, "write_string", write_string, 2);
|
123
124
|
rb_define_protected_method(klass, "init", init, 3);
|
124
125
|
}
|
@@ -19,12 +19,15 @@ int i2c_write_byte(uint8_t reg, uint8_t data) {
|
|
19
19
|
}
|
20
20
|
|
21
21
|
int i2c_write_bytes(uint8_t reg, const char* data) {
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
return i2c_write_n_bytes(reg, data, strlen(data));
|
23
|
+
}
|
24
|
+
|
25
|
+
int i2c_write_n_bytes(uint8_t reg, const char* data, size_t length) {
|
26
|
+
size_t len = sizeof(uint8_t) + length;
|
27
|
+
char *buf = calloc(1, len);
|
25
28
|
memcpy(&buf[0], ®, 1);
|
26
|
-
memcpy(&buf[1], data,
|
27
|
-
|
29
|
+
memcpy(&buf[1], data, length);
|
30
|
+
|
28
31
|
if(write(i2c_bus_handle, buf, len) != len) {
|
29
32
|
fprintf(stderr, "Write to device failed\n");
|
30
33
|
free(buf);
|
@@ -24,6 +24,7 @@
|
|
24
24
|
|
25
25
|
int i2c_write_byte(uint8_t reg, uint8_t data);
|
26
26
|
int i2c_write_bytes(uint8_t reg, const char* data);
|
27
|
+
int i2c_write_n_bytes(uint8_t reg, const char* data, size_t length);
|
27
28
|
int set_cursor_position(uint8_t col, uint8_t row);
|
28
29
|
int clear_display();
|
29
30
|
int set_contrast_level(uint8_t level);
|
data/lib/oled-control/oled.rb
CHANGED
@@ -38,6 +38,12 @@ class OLED
|
|
38
38
|
0xA3 => 0xA1, # £
|
39
39
|
0xFA => 0xEA, # ú
|
40
40
|
0xDA => 0xE5, # Ú
|
41
|
+
0x5B => 0xFA, # [
|
42
|
+
0x5D => 0xFC, # ]
|
43
|
+
0x7B => 0xFD, # {
|
44
|
+
0x7D => 0xFF, # }
|
45
|
+
0xE8 => 0xA4, # è
|
46
|
+
0xC8 => 0xC4, # È
|
41
47
|
# unsupported characters are mapped to closest match
|
42
48
|
0xEF => 0x69, # ï -> i
|
43
49
|
0xCF => 0x49, # Ï -> I
|
@@ -77,7 +83,7 @@ class OLED
|
|
77
83
|
end
|
78
84
|
|
79
85
|
def raw_write(str)
|
80
|
-
self.write_string(str);
|
86
|
+
self.write_string(str, str.size);
|
81
87
|
end
|
82
88
|
|
83
89
|
def write(str)
|
@@ -87,6 +93,7 @@ class OLED
|
|
87
93
|
iso_string = str.encode('iso-8859-1')
|
88
94
|
encoded_string = []
|
89
95
|
iso_string.each_byte{|b| encoded_string << (@character_conversion[b.ord].nil? ? b.ord : @character_conversion[b.ord]) }
|
90
|
-
|
96
|
+
result = encoded_string.pack("c*")
|
97
|
+
self.write_string(result, result.size)
|
91
98
|
end
|
92
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oled-control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Lønaas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby Gem for SSD1311 based 20x4 OLED display
|
14
14
|
email: christian.lonaas@discombobulator.org
|