SSD1306 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3d5d18f7a2e5779d4012cf46d9b2fd360b50ace
4
- data.tar.gz: eb30c0843ae433c37199fa7d65dd96cf1eb9cbde
3
+ metadata.gz: b031d58816b19b11bb94f14762fcc9ab3f01d187
4
+ data.tar.gz: 3b4deb86c9018c941db2255405760b2ded612ce8
5
5
  SHA512:
6
- metadata.gz: 73e2bd0cb47e00b06f23518a077dea41d3ded2ce74a1df79969d1d6ff2325981706b9c4d5b45cacc9530963a76337740042bbe7ef57573366e806cf518ff1604
7
- data.tar.gz: efd128641d18c0664b55d38027a7f527560590257add7ebbb9da3a55f8feb9b074d3c2367368f5764f97845b4d0865fab871663d31fbc431d963ff8b71b48932
6
+ metadata.gz: ea3b0571651b1f1608254ebe8fe5f88128881363e2f2719092ec78f8f286af204389e8f2776fba6318b96317f22697a1341cfa7b095374485d97a028847b0b2a
7
+ data.tar.gz: b18ad76bf7f16fd14ce822fe1b53c86fbcd1504ed0306f2b2048b986120a7174ce381b6f68964140248ef6a52df2960388a71a8470bb9f246d738448694f74c7
data/lib/SSD1306.rb CHANGED
@@ -1,155 +1,4 @@
1
1
  require "i2c"
2
2
 
3
3
  require "SSD1306/version"
4
-
5
- # Constants
6
- SSD1306_I2C_ADDRESS = 0x3C # 011110+SA0+RW - 0x3C or 0x3D
7
- SSD1306_SETCONTRAST = 0x81
8
- SSD1306_DISPLAYALLON_RESUME = 0xA4
9
- SSD1306_DISPLAYALLON = 0xA5
10
- SSD1306_NORMALDISPLAY = 0xA6
11
- SSD1306_INVERTDISPLAY = 0xA7
12
- SSD1306_DISPLAYOFF = 0xAE
13
- SSD1306_DISPLAYON = 0xAF
14
- SSD1306_SETDISPLAYOFFSET = 0xD3
15
- SSD1306_SETCOMPINS = 0xDA
16
- SSD1306_SETVCOMDETECT = 0xDB
17
- SSD1306_SETDISPLAYCLOCKDIV = 0xD5
18
- SSD1306_SETPRECHARGE = 0xD9
19
- SSD1306_SETMULTIPLEX = 0xA8
20
- SSD1306_SETLOWCOLUMN = 0x00
21
- SSD1306_SETHIGHCOLUMN = 0x10
22
- SSD1306_SETSTARTLINE = 0x40
23
- SSD1306_MEMORYMODE = 0x20
24
- SSD1306_COLUMNADDR = 0x21
25
- SSD1306_PAGEADDR = 0x22
26
- SSD1306_COMSCANINC = 0xC0
27
- SSD1306_COMSCANDEC = 0xC8
28
- SSD1306_SEGREMAP = 0xA0
29
- SSD1306_CHARGEPUMP = 0x8D
30
- SSD1306_EXTERNALVCC = 0x1
31
- SSD1306_SWITCHCAPVCC = 0x2
32
-
33
- # Scrolling constants
34
- SSD1306_ACTIVATE_SCROLL = 0x2F
35
- SSD1306_DEACTIVATE_SCROLL = 0x2E
36
- SSD1306_SET_VERTICAL_SCROLL_AREA = 0xA3
37
- SSD1306_RIGHT_HORIZONTAL_SCROLL = 0x26
38
- SSD1306_LEFT_HORIZONTAL_SCROLL = 0x27
39
- SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29
40
- SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A
41
-
42
- class SSD1306
43
- attr_accessor :protocol, :path, :address, :width, :height
44
-
45
- def initialize(opts = {})
46
- default_options = {
47
- protocol: :i2c,
48
- path: '/dev/i2c-1',
49
- address: 0x3C,
50
- width: 128,
51
- height: 64
52
- }
53
- options = default_options.merge(opts)
54
-
55
- # Attributes for attr_accessor
56
- @protocol = options[:protocol]
57
- @path = options[:path]
58
- @address = options[:address]
59
- @width = options[:width]
60
- @height = options[:height]
61
-
62
- # Variables needed internally
63
- @pages = @height / 8
64
- @buffer = [0]*(@width*@pages)
65
- if @protocol == :i2c
66
- @interface = I2C.create(@path)
67
- elsif @protocol == :spi
68
- raise "SPI Not Supported Currently"
69
- else
70
- raise "Unrecognized protocol"
71
- end
72
-
73
- self.command SSD1306_DISPLAYON
74
-
75
- # For 128 x 64 display
76
- if @height == 64
77
- self.command SSD1306_DISPLAYOFF
78
- self.command SSD1306_SETDISPLAYCLOCKDIV
79
- self.command 0x80
80
- self.command SSD1306_SETMULTIPLEX
81
- self.command 0x3F
82
- self.command SSD1306_SETDISPLAYOFFSET
83
- self.command 0x0
84
- self.command(SSD1306_SETSTARTLINE | 0x0)
85
- self.command SSD1306_CHARGEPUMP
86
- self.command 0x10
87
- #TODO VCCSTATE?
88
- self.command SSD1306_MEMORYMODE
89
- self.command 0x00
90
- self.command(SSD1306_SEGREMAP | 0x1)
91
- self.command SSD1306_COMSCANDEC
92
- self.command SSD1306_SETCOMPINS
93
- self.command 0x12
94
- self.command SSD1306_SETCONTRAST
95
- #TODO EXTERNAL VCC?
96
- self.command 0x9F
97
- self.command SSD1306_SETPRECHARGE
98
- #TODO VCC?
99
- self.command 0x22
100
- self.command SSD1306_SETVCOMDETECT
101
- self.command 0x40
102
- self.command SSD1306_DISPLAYALLON_RESUME
103
- self.command SSD1306_NORMALDISPLAY
104
- end
105
- end
106
-
107
- def command(c)
108
- control = 0x00
109
- @interface.write @address, control, c
110
- end
111
-
112
- def data(d)
113
- control = 0x40
114
- @interface.write @address, control, c
115
- end
116
-
117
- def display!
118
- self.command SSD1306_COLUMNADDR
119
- self.command 0
120
- self.command(@width - 1)
121
- self.command SSD1306_PAGEADDR
122
- self.command 0
123
- self.command(@pages - 1)
124
- # Write buffer data
125
- # TODO: This works for I2C only
126
- for i in range(0, @buffer.length, 16)
127
- control = 0x40
128
- @interface.write control, @buffer[i:i+16]
129
- end
130
- end
131
-
132
- #TODO Complete image processing
133
- def image(image)
134
- raise "Image functionality not implemented yet"
135
- end
136
-
137
- def clear
138
- @buffer = [0]*(@width*@pages)
139
- end
140
-
141
- def clear!
142
- self.clear
143
- self.display
144
- end
145
-
146
- #TODO Implement Contrast functionality
147
- def set_contrast(contrast)
148
- raise "Contrast not yet implemented"
149
- end
150
-
151
- #TODO Implement Dimming functionality
152
- def dim(dim)
153
- raise "Dim not implemented yet"
154
- end
155
- end
4
+ require "SSD1306/display"
@@ -0,0 +1,153 @@
1
+ module SSD1306
2
+ # Constants
3
+ SSD1306_I2C_ADDRESS = 0x3C # 011110+SA0+RW - 0x3C or 0x3D
4
+ SSD1306_SETCONTRAST = 0x81
5
+ SSD1306_DISPLAYALLON_RESUME = 0xA4
6
+ SSD1306_DISPLAYALLON = 0xA5
7
+ SSD1306_NORMALDISPLAY = 0xA6
8
+ SSD1306_INVERTDISPLAY = 0xA7
9
+ SSD1306_DISPLAYOFF = 0xAE
10
+ SSD1306_DISPLAYON = 0xAF
11
+ SSD1306_SETDISPLAYOFFSET = 0xD3
12
+ SSD1306_SETCOMPINS = 0xDA
13
+ SSD1306_SETVCOMDETECT = 0xDB
14
+ SSD1306_SETDISPLAYCLOCKDIV = 0xD5
15
+ SSD1306_SETPRECHARGE = 0xD9
16
+ SSD1306_SETMULTIPLEX = 0xA8
17
+ SSD1306_SETLOWCOLUMN = 0x00
18
+ SSD1306_SETHIGHCOLUMN = 0x10
19
+ SSD1306_SETSTARTLINE = 0x40
20
+ SSD1306_MEMORYMODE = 0x20
21
+ SSD1306_COLUMNADDR = 0x21
22
+ SSD1306_PAGEADDR = 0x22
23
+ SSD1306_COMSCANINC = 0xC0
24
+ SSD1306_COMSCANDEC = 0xC8
25
+ SSD1306_SEGREMAP = 0xA0
26
+ SSD1306_CHARGEPUMP = 0x8D
27
+ SSD1306_EXTERNALVCC = 0x1
28
+ SSD1306_SWITCHCAPVCC = 0x2
29
+
30
+ # Scrolling constants
31
+ SSD1306_ACTIVATE_SCROLL = 0x2F
32
+ SSD1306_DEACTIVATE_SCROLL = 0x2E
33
+ SSD1306_SET_VERTICAL_SCROLL_AREA = 0xA3
34
+ SSD1306_RIGHT_HORIZONTAL_SCROLL = 0x26
35
+ SSD1306_LEFT_HORIZONTAL_SCROLL = 0x27
36
+ SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29
37
+ SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A
38
+
39
+ class Display
40
+ attr_accessor :protocol, :path, :address, :width, :height
41
+
42
+ def initialize(opts = {})
43
+ default_options = {
44
+ protocol: :i2c,
45
+ path: '/dev/i2c-1',
46
+ address: 0x3C,
47
+ width: 128,
48
+ height: 64
49
+ }
50
+ options = default_options.merge(opts)
51
+
52
+ # Attributes for attr_accessor
53
+ @protocol = options[:protocol]
54
+ @path = options[:path]
55
+ @address = options[:address]
56
+ @width = options[:width]
57
+ @height = options[:height]
58
+
59
+ # Variables needed internally
60
+ @pages = @height / 8
61
+ @buffer = [0]*(@width*@pages)
62
+ if @protocol == :i2c
63
+ @interface = I2C.create(@path)
64
+ elsif @protocol == :spi
65
+ raise "SPI Not Supported Currently"
66
+ else
67
+ raise "Unrecognized protocol"
68
+ end
69
+
70
+ self.command SSD1306_DISPLAYON
71
+
72
+ # For 128 x 64 display
73
+ if @height == 64
74
+ self.command SSD1306_DISPLAYOFF
75
+ self.command SSD1306_SETDISPLAYCLOCKDIV
76
+ self.command 0x80
77
+ self.command SSD1306_SETMULTIPLEX
78
+ self.command 0x3F
79
+ self.command SSD1306_SETDISPLAYOFFSET
80
+ self.command 0x0
81
+ self.command(SSD1306_SETSTARTLINE | 0x0)
82
+ self.command SSD1306_CHARGEPUMP
83
+ self.command 0x10
84
+ #TODO VCCSTATE?
85
+ self.command SSD1306_MEMORYMODE
86
+ self.command 0x00
87
+ self.command(SSD1306_SEGREMAP | 0x1)
88
+ self.command SSD1306_COMSCANDEC
89
+ self.command SSD1306_SETCOMPINS
90
+ self.command 0x12
91
+ self.command SSD1306_SETCONTRAST
92
+ #TODO EXTERNAL VCC?
93
+ self.command 0x9F
94
+ self.command SSD1306_SETPRECHARGE
95
+ #TODO VCC?
96
+ self.command 0x22
97
+ self.command SSD1306_SETVCOMDETECT
98
+ self.command 0x40
99
+ self.command SSD1306_DISPLAYALLON_RESUME
100
+ self.command SSD1306_NORMALDISPLAY
101
+ end
102
+ end
103
+
104
+ def command(c)
105
+ control = 0x00
106
+ @interface.write @address, control, c
107
+ end
108
+
109
+ def data(d)
110
+ control = 0x40
111
+ @interface.write @address, control, c
112
+ end
113
+
114
+ def display!
115
+ self.command SSD1306_COLUMNADDR
116
+ self.command 0
117
+ self.command(@width - 1)
118
+ self.command SSD1306_PAGEADDR
119
+ self.command 0
120
+ self.command(@pages - 1)
121
+ # Write buffer data
122
+ # TODO: This works for I2C only
123
+ for i in range(0, @buffer.length, 16)
124
+ control = 0x40
125
+ @interface.write control, @buffer[i:i+16]
126
+ end
127
+ end
128
+
129
+ #TODO Complete image processing
130
+ def image(image)
131
+ raise "Image functionality not implemented yet"
132
+ end
133
+
134
+ def clear
135
+ @buffer = [0]*(@width*@pages)
136
+ end
137
+
138
+ def clear!
139
+ self.clear
140
+ self.display
141
+ end
142
+
143
+ #TODO Implement Contrast functionality
144
+ def set_contrast(contrast)
145
+ raise "Contrast not yet implemented"
146
+ end
147
+
148
+ #TODO Implement Dimming functionality
149
+ def dim(dim)
150
+ raise "Dim not implemented yet"
151
+ end
152
+ end
153
+ end
@@ -1,3 +1,3 @@
1
1
  module SSD1306
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Bick
@@ -86,6 +86,7 @@ files:
86
86
  - bin/setup
87
87
  - exe/SSD1306
88
88
  - lib/SSD1306.rb
89
+ - lib/SSD1306/display.rb
89
90
  - lib/SSD1306/version.rb
90
91
  homepage: https://github.com/zeiv/SSD1306-ruby
91
92
  licenses: