SSD1306 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3d5d18f7a2e5779d4012cf46d9b2fd360b50ace
4
+ data.tar.gz: eb30c0843ae433c37199fa7d65dd96cf1eb9cbde
5
+ SHA512:
6
+ metadata.gz: 73e2bd0cb47e00b06f23518a077dea41d3ded2ce74a1df79969d1d6ff2325981706b9c4d5b45cacc9530963a76337740042bbe7ef57573366e806cf518ff1604
7
+ data.tar.gz: efd128641d18c0664b55d38027a7f527560590257add7ebbb9da3a55f8feb9b074d3c2367368f5764f97845b4d0865fab871663d31fbc431d963ff8b71b48932
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in SSD1306.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Xavier Bick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # SSD1306
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/SSD1306`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'SSD1306'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install SSD1306
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec SSD1306` to use the gem in this directory, ignoring other installed copies of this gem.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zeiv/SSD1306-ruby.
36
+
37
+ ## Acknowledgements
38
+
39
+ This library is inspired by the Adafruit SSD1306 Python library, available here: https://github.com/adafruit/Adafruit_Python_SSD1306
40
+
41
+ ## License
42
+
43
+ Copyright (c) 2016 Xavier Bick under the MIT License. See LICENSE.txt for details.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'SSD1306/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "SSD1306"
8
+ spec.version = SSD1306::VERSION
9
+ spec.authors = ["Xavier Bick"]
10
+ spec.email = ["fxb9500@gmail.com"]
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = %q{A library for the SSD1306 OLED Display}
14
+ spec.description = %q{Use this library to interface to an SSD1306 OLED via I2C or SPI. It was developed with the Raspberry Pi in mind, but should work on any device with I2C or SPI.}
15
+ spec.homepage = "https://github.com/zeiv/SSD1306-ruby"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+
34
+ spec.add_runtime_dependency "i2c", ">= 0.4.0"
35
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "SSD1306"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "SSD1306"
@@ -0,0 +1,155 @@
1
+ require "i2c"
2
+
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
@@ -0,0 +1,3 @@
1
+ module SSD1306
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SSD1306
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Xavier Bick
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: i2c
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.0
69
+ description: Use this library to interface to an SSD1306 OLED via I2C or SPI. It
70
+ was developed with the Raspberry Pi in mind, but should work on any device with
71
+ I2C or SPI.
72
+ email:
73
+ - fxb9500@gmail.com
74
+ executables:
75
+ - SSD1306
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - SSD1306.gemspec
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/SSD1306
88
+ - lib/SSD1306.rb
89
+ - lib/SSD1306/version.rb
90
+ homepage: https://github.com/zeiv/SSD1306-ruby
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A library for the SSD1306 OLED Display
114
+ test_files: []