oled-control 0.2.0 → 0.2.1

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: e775137c40f4aa32848dfc96daaa21d080b13a64
4
- data.tar.gz: 4d3976367e2133f52dedced9e7972b59bbd8af08
3
+ metadata.gz: 6ef89f0ae721f6a29e325cdd5d199b753b491c13
4
+ data.tar.gz: a9b4f40492ec195919a67c047374e13ad98902de
5
5
  SHA512:
6
- metadata.gz: 763f6a112a2a2dc42f9e3d82e9988afe87a889e1ca23136d2bd6bba77c1e677db0c6917aa1e7ab788dee3d885531ac2765a3e39305e907f986fefee310d472d0
7
- data.tar.gz: 3544ed8545d58fb5781f8ad614c222b0fde6cd160715c69d7dc4d43e3055a279a53a1b4699404ec50607c3e363679c715db152f92b4109e522dc22b25601ebf6
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
- if(!i2c_write_bytes(DATA, s))
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, 1);
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
- size_t len = sizeof(uint8_t) + strlen(data);
23
- // allocate room for reg + data + trailing null character:
24
- char *buf = calloc(1, len+1);
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], &reg, 1);
26
- memcpy(&buf[1], data, strlen(data));
27
- // write the reg + data, minus the trailing null character
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);
@@ -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
- self.write_string(encoded_string.pack("c*"))
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.0
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-12 00:00:00.000000000 Z
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