oled-control 0.1.1 → 0.2.0
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/extconf.rb +2 -0
- data/ext/oled-control/main.c +1 -1
- data/ext/oled-control/oled-control-gem.c +26 -3
- data/ext/oled-control/oled-control.c +18 -2
- data/ext/oled-control/oled-control.h +2 -1
- data/lib/oled-control/oled.rb +10 -1
- 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: e775137c40f4aa32848dfc96daaa21d080b13a64
|
4
|
+
data.tar.gz: 4d3976367e2133f52dedced9e7972b59bbd8af08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 763f6a112a2a2dc42f9e3d82e9988afe87a889e1ca23136d2bd6bba77c1e677db0c6917aa1e7ab788dee3d885531ac2765a3e39305e907f986fefee310d472d0
|
7
|
+
data.tar.gz: 3544ed8545d58fb5781f8ad614c222b0fde6cd160715c69d7dc4d43e3055a279a53a1b4699404ec50607c3e363679c715db152f92b4109e522dc22b25601ebf6
|
data/ext/oled-control/extconf.rb
CHANGED
data/ext/oled-control/main.c
CHANGED
@@ -24,14 +24,15 @@ static VALUE write_string(VALUE self, VALUE str) {
|
|
24
24
|
return Qtrue;
|
25
25
|
}
|
26
26
|
|
27
|
-
static VALUE init(VALUE self, VALUE i2cbus, VALUE i2caddress) {
|
27
|
+
static VALUE init(VALUE self, VALUE i2cbus, VALUE i2caddress, VALUE orientation) {
|
28
28
|
const char *bus = RSTRING_PTR(i2cbus);
|
29
29
|
uint8_t a = NUM2UINT(i2caddress);
|
30
|
+
uint8_t o = NUM2UINT(orientation);
|
30
31
|
|
31
32
|
if(!configure_display(bus, a))
|
32
33
|
rb_raise(rb_eRuntimeError, "can't detect display! Bus/address wrong?");
|
33
34
|
|
34
|
-
if(!init_display())
|
35
|
+
if(!init_display(o))
|
35
36
|
rb_raise(rb_eRuntimeError, "failure initializing display");
|
36
37
|
|
37
38
|
return Qtrue;
|
@@ -60,6 +61,27 @@ static VALUE disable(VALUE self) {
|
|
60
61
|
return Qtrue;
|
61
62
|
}
|
62
63
|
|
64
|
+
static VALUE create_character(VALUE self, VALUE position, VALUE chardata) {
|
65
|
+
uint8_t data[8];
|
66
|
+
Check_Type(chardata, T_ARRAY);
|
67
|
+
Check_Type(position, T_FIXNUM);
|
68
|
+
|
69
|
+
uint8_t pos = NUM2UINT(position);
|
70
|
+
int len = RARRAY_LEN(chardata);
|
71
|
+
if((len > 8) || (len < 8)) {
|
72
|
+
rb_raise(rb_eRuntimeError, "error: array must be exactly of size 8");
|
73
|
+
return Qnil;
|
74
|
+
} else {
|
75
|
+
for(int i=0; i<8; i++)
|
76
|
+
data[i] = rb_ary_entry(chardata, i);
|
77
|
+
}
|
78
|
+
if(!create_custom_character(pos, data)) {
|
79
|
+
rb_raise(rb_eRuntimeError, "error creating custom character");
|
80
|
+
return Qnil;
|
81
|
+
}
|
82
|
+
return Qtrue;
|
83
|
+
}
|
84
|
+
|
63
85
|
static VALUE send_command(VALUE self, VALUE command) {
|
64
86
|
uint8_t cmd = NUM2UINT(command);
|
65
87
|
if(!send_cmd(cmd)) {
|
@@ -94,8 +116,9 @@ void Init_oled_control(void) {
|
|
94
116
|
rb_define_method(klass, "set_contrast", set_contrast, 1);
|
95
117
|
rb_define_method(klass, "enable", enable, 0);
|
96
118
|
rb_define_method(klass, "disable", disable, 0);
|
119
|
+
rb_define_method(klass, "create_character", create_character, 2);
|
97
120
|
rb_define_protected_method(klass, "send_command", send_command, 1);
|
98
121
|
rb_define_protected_method(klass, "send_raw_command", send_raw_command, 1);
|
99
122
|
rb_define_protected_method(klass, "write_string", write_string, 1);
|
100
|
-
rb_define_protected_method(klass, "init", init,
|
123
|
+
rb_define_protected_method(klass, "init", init, 3);
|
101
124
|
}
|
@@ -91,7 +91,23 @@ int configure_display(const char* bus, uint8_t address) {
|
|
91
91
|
return configured;
|
92
92
|
}
|
93
93
|
|
94
|
-
int
|
94
|
+
int create_custom_character(uint8_t pos, uint8_t map[]) {
|
95
|
+
pos &= 0x7;
|
96
|
+
if(!i2c_write_byte(CMD, 0x40 | (pos << 3)))
|
97
|
+
return FALSE;
|
98
|
+
|
99
|
+
usleep(30);
|
100
|
+
int result;
|
101
|
+
for (int i=0; i<8; i++) {
|
102
|
+
result = i2c_write_byte(DATA, map[i] >> 1);
|
103
|
+
if(!result)
|
104
|
+
break;
|
105
|
+
usleep(40);
|
106
|
+
}
|
107
|
+
return result;
|
108
|
+
}
|
109
|
+
|
110
|
+
int init_display(uint8_t orientation) {
|
95
111
|
if(!configured)
|
96
112
|
return FALSE;
|
97
113
|
|
@@ -124,7 +140,7 @@ int init_display() {
|
|
124
140
|
i2c_write_byte(CMD, 0x78) &&
|
125
141
|
i2c_write_byte(CMD, 0x28) &&
|
126
142
|
i2c_write_byte(CMD, 0x2a) &&
|
127
|
-
i2c_write_byte(CMD,
|
143
|
+
i2c_write_byte(CMD, orientation) &&
|
128
144
|
i2c_write_byte(CMD, 0x28) &&
|
129
145
|
i2c_write_byte(CMD, 0x01) &&
|
130
146
|
i2c_write_byte(CMD, 0x80) &&
|
@@ -31,7 +31,8 @@ int display_enable();
|
|
31
31
|
int display_disable();
|
32
32
|
int send_cmd(uint8_t cmd);
|
33
33
|
int send_raw_cmd(uint8_t cmd);
|
34
|
+
int create_custom_character(uint8_t pos, uint8_t map[]);
|
34
35
|
int configure_display(const char* bus, uint8_t address);
|
35
|
-
int init_display();
|
36
|
+
int init_display(uint8_t orientation);
|
36
37
|
|
37
38
|
#endif //OLED_CONTROL_OLED_CONTROL_H
|
data/lib/oled-control/oled.rb
CHANGED
@@ -46,7 +46,12 @@ class OLED
|
|
46
46
|
0xE3 => 0x61, # ã -> a
|
47
47
|
0xC3 => 0x41, # Ã -> A
|
48
48
|
}
|
49
|
-
|
49
|
+
orientation = if @flipped
|
50
|
+
FLIPPED
|
51
|
+
else
|
52
|
+
NORMAL
|
53
|
+
end
|
54
|
+
self.init(i2c_bus, i2c_address, orientation)
|
50
55
|
end
|
51
56
|
|
52
57
|
def clear_row(row)
|
@@ -71,6 +76,10 @@ class OLED
|
|
71
76
|
end
|
72
77
|
end
|
73
78
|
|
79
|
+
def raw_write(str)
|
80
|
+
self.write_string(str);
|
81
|
+
end
|
82
|
+
|
74
83
|
def write(str)
|
75
84
|
unless str.is_a?(String)
|
76
85
|
str = str.to_s
|
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.
|
4
|
+
version: 0.2.0
|
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-12 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
|