i2c-lcd 0.0.4
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 +7 -0
- data/.gitignore +18 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG +11 -0
- data/CONTRIBUTING.md +43 -0
- data/Gemfile +4 -0
- data/Guardfile +12 -0
- data/LICENSE.txt +23 -0
- data/README.markdown +41 -0
- data/Rakefile +9 -0
- data/TODO.markdown +2 -0
- data/bin/bargraph +20 -0
- data/bin/lcd +28 -0
- data/bin/spritz +25 -0
- data/i2c-lcd.gemspec +32 -0
- data/lib/i2c/drivers/lcd.rb +10 -0
- data/lib/i2c/drivers/lcd/display.rb +192 -0
- data/lib/i2c/drivers/lcd/version.rb +7 -0
- data/test/extensions/fakefs.rb +7 -0
- data/test/helper.rb +13 -0
- data/test/unit/test_item.rb +37 -0
- metadata +196 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e44e9ac1d2e007cf2e0734ebb529500a1e80cb8b7dda3f85174eb9366548860
|
4
|
+
data.tar.gz: b9d819af5b8635cd1a3ddb9d3ac3e9e70b400a7cc239fa88ce19071b15107505
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3929a9ca5314c8001581647731cdbb7cd1772a2e7bf00eb0ec51f759c073e9f3f12f7c2d22b0d8ade8121a61442fce7a3d0657d79b4731ea118326029f9ba5f
|
7
|
+
data.tar.gz: 5b13e16eb0d8b948a4197193388747a7bc9cf2e849b131f7ad5632233167e971a1528fb0b9fa1cae33440fe6005baef2af61ae67ccc9d927ab056a9054605b90
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.3
|
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# How to contribute
|
2
|
+
|
3
|
+
I like to encourage you to contribute to the repository.
|
4
|
+
This should be as easy as possible for you but there are a few things to consider when contributing.
|
5
|
+
The following guidelines for contribution should be followed if you want to submit a pull request.
|
6
|
+
|
7
|
+
## How to prepare
|
8
|
+
|
9
|
+
* You need a [GitHub account](https://github.com/signup/free)
|
10
|
+
* Submit an [issue ticket](https://github.com/anselmh/CONTRIBUTING.md/issues) for your issue if the is no one yet.
|
11
|
+
* Describe the issue and include steps to reproduce if it's a bug.
|
12
|
+
* Ensure to mention the earliest version that you know is affected.
|
13
|
+
* If you are able and want to fix this, fork the repository on GitHub
|
14
|
+
|
15
|
+
## Make Changes
|
16
|
+
|
17
|
+
* In your forked repository, create a topic branch for your upcoming patch. (e.g. `feature--autoplay` or `bugfix--ios-crash`)
|
18
|
+
* Usually this is based on the master branch.
|
19
|
+
* Create a branch based on master; `git branch
|
20
|
+
fix/master/my_contribution master` then checkout the new branch with `git
|
21
|
+
checkout fix/master/my_contribution`. Please avoid working directly on the `master` branch.
|
22
|
+
* Make sure you stick to the coding style that is used already.
|
23
|
+
* Make use of the `.editorconfig`-file if provided with the repository.
|
24
|
+
* Make commits of logical units and describe them properly.
|
25
|
+
* Check for unnecessary whitespace with `git diff --check` before committing.
|
26
|
+
|
27
|
+
* If possible, submit tests to your patch / new feature so it can be tested easily.
|
28
|
+
* Assure nothing is broken by running all the tests.
|
29
|
+
|
30
|
+
## Submit Changes
|
31
|
+
|
32
|
+
* Push your changes to a topic branch in your fork of the repository.
|
33
|
+
* Open a pull request to the original repository and choose the right original branch you want to patch.
|
34
|
+
_Advanced users may install the `hub` gem and use the [`hub pull-request` command](https://github.com/defunkt/hub#git-pull-request)._
|
35
|
+
* If not done in commit messages (which you really should do) please reference and update your issue with the code changes. But _please do not close the issue yourself_.
|
36
|
+
_Notice: You can [turn your previously filed issues into a pull-request here](http://issue2pr.herokuapp.com/)._
|
37
|
+
* Even if you have write access to the repository, do not directly push or merge pull-requests. Let another team member review your pull request and approve.
|
38
|
+
|
39
|
+
# Additional Resources
|
40
|
+
|
41
|
+
* [General GitHub documentation](http://help.github.com/)
|
42
|
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
43
|
+
* [Read the Issue Guidelines by @necolas](https://github.com/necolas/issue-guidelines/blob/master/CONTRIBUTING.md) for more details
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
guard 'bundler' do
|
2
|
+
watch('Gemfile')
|
3
|
+
watch(%r|^.*\.gemspec|)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard 'minitest' do
|
7
|
+
watch(%r|^test/unit/test_(.*)\.rb|)
|
8
|
+
watch(%r|^lib/*\.rb|){'test/unit'}
|
9
|
+
watch(%r|^lib/.*/*\.rb|){'test/unit'}
|
10
|
+
watch(%r{^lib/.*/([^/]+)\.rb$}){|m| "test/unit/test_#{m[1]}.rb"}
|
11
|
+
watch(%r|^test/helper\.rb|){'test/unit'}
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2014 Nicholas E. Rabenau
|
2
|
+
Copyright (c) 2017 Daisuke Suzuki
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# LCD I2C driver (1602/2004/..)
|
2
|
+
|
3
|
+
This is a Ruby driver for the 2004A/1602 LCD display with I2C adapter
|
4
|
+
(tested with PCF8574T),
|
5
|
+
forked from [i2c-ss1602](https://github.com/nerab/i2c-ss1602).
|
6
|
+
|
7
|
+
The original i2c-ss1602 was partially ported from [raspi-gpio](https://github.com/paulbarber/raspi-gpio/blob/master/lcd_display.py).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem 'i2c-lcd'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```
|
26
|
+
$ gem install i2c-lcd
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'i2c/drivers/lcd'
|
33
|
+
display = I2C::Drivers::LCD::Display.new('/dev/i2c-1', 0x27, rows=20, cols=4)
|
34
|
+
display.clear
|
35
|
+
display.text('Hello', 0)
|
36
|
+
display.text('World', 1)
|
37
|
+
display.text('Line3', 2)
|
38
|
+
display.text('Line4', 3)
|
39
|
+
```
|
40
|
+
|
41
|
+
'rows' and 'cols' options are optional. The default value is 20 and 4.
|
data/Rakefile
ADDED
data/TODO.markdown
ADDED
data/bin/bargraph
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'i2c/drivers/lcd'
|
5
|
+
|
6
|
+
display = I2C::Drivers::LCD::Display.new('/dev/i2c-1', 0x27)
|
7
|
+
|
8
|
+
x = ARGV[0].to_f
|
9
|
+
r = (0..100)
|
10
|
+
|
11
|
+
unless r.include?(x)
|
12
|
+
STDERR.puts "#{x} is not within the acceptable range of #{r}"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
char = ARGV[1] || '#'
|
17
|
+
|
18
|
+
bar = char * (x / 100 * display.cols)
|
19
|
+
clean_bar = sprintf('%-1$*2$s', bar, display.cols)
|
20
|
+
display.text(clean_bar, 0)
|
data/bin/lcd
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# Sample use:
|
5
|
+
#
|
6
|
+
# TZ='Europe/Berlin' date "+%d.%m.%Y %H:%M Uhr 24'C" | bin/lcd2004a
|
7
|
+
#
|
8
|
+
|
9
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
|
+
require 'i2c/drivers/lcd'
|
11
|
+
|
12
|
+
trap('INT'){
|
13
|
+
exit
|
14
|
+
}
|
15
|
+
|
16
|
+
ARGF.binmode
|
17
|
+
txt = ARGF.read
|
18
|
+
|
19
|
+
d = I2C::Drivers::LCD::Display.new('/dev/i2c-1', 0x27)
|
20
|
+
|
21
|
+
# Spread text over lines
|
22
|
+
(0..(d.rows - 1)).each do |row|
|
23
|
+
x0 = row * d.cols
|
24
|
+
x1 = x0 + d.cols - 1
|
25
|
+
|
26
|
+
output = (txt[x0..x1] || '').chomp
|
27
|
+
d.text(output, row, true)
|
28
|
+
end
|
data/bin/spritz
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'i2c/drivers/lcd'
|
5
|
+
|
6
|
+
trap('INT'){
|
7
|
+
exit
|
8
|
+
}
|
9
|
+
|
10
|
+
ARGF.binmode
|
11
|
+
|
12
|
+
begin
|
13
|
+
display = I2C::Drivers::LCD::Display.new('/dev/i2c-1', 0x27)
|
14
|
+
|
15
|
+
ARGF.each do |line|
|
16
|
+
line.split.each do |arg|
|
17
|
+
display.off
|
18
|
+
display.text(arg, 0, true)
|
19
|
+
display.on
|
20
|
+
sleep 0.5
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ensure
|
24
|
+
display.clear if display
|
25
|
+
end
|
data/i2c-lcd.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'i2c/drivers/lcd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'i2c-lcd'
|
8
|
+
spec.version = I2C::Drivers::LCD::VERSION
|
9
|
+
spec.authors = ['Daisuke SUZUKI']
|
10
|
+
spec.email = ['daisuke.suzuki@gmail.com']
|
11
|
+
spec.description = %q{Ruby driver for 2004/1602 LCD display with I2C adapter}
|
12
|
+
spec.summary = %q{Driver for the 2004/1602 LCD display}
|
13
|
+
spec.homepage = 'https://github.com/daisukesuzuki/i2c-lcd'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'i2c'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'guard-bundler'
|
26
|
+
spec.add_development_dependency 'guard-minitest'
|
27
|
+
spec.add_development_dependency 'fakefs'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_development_dependency 'byebug'
|
31
|
+
spec.add_development_dependency 'pry-byebug'
|
32
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'i2c'
|
2
|
+
|
3
|
+
module I2C
|
4
|
+
module Drivers
|
5
|
+
module LCD
|
6
|
+
#
|
7
|
+
# Driver class for the 2004/1602 I2C LCD Display.
|
8
|
+
# forked from https://github.com/nerab/i2c-ss1602
|
9
|
+
#
|
10
|
+
# see https://github.com/andec/i2c
|
11
|
+
# Parts copied from https://github.com/paulbarber/raspi-gpio/blob/master/lcd_display.py
|
12
|
+
#
|
13
|
+
class Display
|
14
|
+
attr_reader :rows, :cols, :cursor, :device
|
15
|
+
|
16
|
+
def initialize(bus_or_bus_name, device_address, cols=20, rows=4, dotsize=8)
|
17
|
+
if bus_or_bus_name.respond_to?(:write)
|
18
|
+
@device = BusDevice.new(bus_or_bus_name, device_address)
|
19
|
+
else
|
20
|
+
@device = BusDevice.new(I2C.create(bus_or_bus_name), device_address)
|
21
|
+
end
|
22
|
+
|
23
|
+
@cols = cols
|
24
|
+
@rows = rows
|
25
|
+
@dotsize = dotsize
|
26
|
+
|
27
|
+
init_sequence
|
28
|
+
|
29
|
+
@cursor = Cursor.new(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def clear
|
33
|
+
write(COMMAND_CLEARDISPLAY)
|
34
|
+
write(COMMAND_RETURNHOME)
|
35
|
+
end
|
36
|
+
|
37
|
+
def text(string, row, pad = false)
|
38
|
+
case row
|
39
|
+
when 0
|
40
|
+
write(LCD_LINE_0)
|
41
|
+
when 1
|
42
|
+
write(LCD_LINE_1)
|
43
|
+
when 2
|
44
|
+
write(LCD_LINE_2)
|
45
|
+
when 3
|
46
|
+
write(LCD_LINE_3)
|
47
|
+
else
|
48
|
+
raise "Only rows #{0..(@rows - 1)} are supported"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Right-pad with spaces so that the line only shows string
|
52
|
+
string = sprintf('%-1$*2$s', string, @cols) if pad
|
53
|
+
|
54
|
+
string.each_char do |c|
|
55
|
+
write(c.ord, BIT_RS)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def on
|
60
|
+
write(COMMAND_DISPLAYCONTROL | FLAG_DISPLAYON)
|
61
|
+
end
|
62
|
+
|
63
|
+
def off
|
64
|
+
write(COMMAND_DISPLAYCONTROL | FLAG_DISPLAYOFF)
|
65
|
+
end
|
66
|
+
|
67
|
+
def backlight_on
|
68
|
+
device.write(FLAG_BACKLIGHT)
|
69
|
+
end
|
70
|
+
|
71
|
+
def backlight_off
|
72
|
+
device.write(FLAG_NOBACKLIGHT)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Send a low-level command to the display
|
77
|
+
#
|
78
|
+
def write(cmd, mode = 0)
|
79
|
+
write_four_bits(mode | (cmd & 0xF0))
|
80
|
+
write_four_bits(mode | ((cmd << 4) & 0xF0))
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
# commands
|
86
|
+
COMMAND_CLEARDISPLAY = 0x01
|
87
|
+
COMMAND_RETURNHOME = 0x02
|
88
|
+
COMMAND_ENTRYMODESET = 0x04
|
89
|
+
COMMAND_DISPLAYCONTROL = 0x08
|
90
|
+
COMMAND_CURSORSHIFT = 0x10
|
91
|
+
COMMAND_FUNCTIONSET = 0x20
|
92
|
+
COMMAND_SETCGRAMADDR = 0x40
|
93
|
+
COMMAND_SETDDRAMADDR = 0x80
|
94
|
+
|
95
|
+
# flags for display entry mode
|
96
|
+
FLAG_ENTRYRIGHT = 0x00
|
97
|
+
FLAG_ENTRYLEFT = 0x02
|
98
|
+
FLAG_ENTRYSHIFTINCREMENT = 0x01
|
99
|
+
FLAG_ENTRYSHIFTDECREMENT = 0x00
|
100
|
+
|
101
|
+
# flags for display on/off control
|
102
|
+
FLAG_DISPLAYON = 0x04
|
103
|
+
FLAG_DISPLAYOFF = 0x00
|
104
|
+
FLAG_CURSORON = 0x02
|
105
|
+
FLAG_CURSOROFF = 0x00
|
106
|
+
FLAG_BLINKON = 0x01
|
107
|
+
FLAG_BLINKOFF = 0x00
|
108
|
+
|
109
|
+
# flags for display/cursor shift
|
110
|
+
FLAG_DISPLAYMOVE = 0x08
|
111
|
+
FLAG_CURSORMOVE = 0x00
|
112
|
+
FLAG_MOVERIGHT = 0x04
|
113
|
+
FLAG_MOVELEFT = 0x00
|
114
|
+
|
115
|
+
# flags for function set
|
116
|
+
FLAG_8BITMODE = 0x10
|
117
|
+
FLAG_4BITMODE = 0x00
|
118
|
+
FLAG_2LINE = 0x08
|
119
|
+
FLAG_1LINE = 0x00
|
120
|
+
FLAG_5x10DOTS = 0x04
|
121
|
+
FLAG_5x8DOTS = 0x00
|
122
|
+
|
123
|
+
# flags for backlight control
|
124
|
+
FLAG_BACKLIGHT = 0x08
|
125
|
+
FLAG_NOBACKLIGHT = 0x00
|
126
|
+
|
127
|
+
# lcd ram address
|
128
|
+
LCD_LINE_0 = 0x80
|
129
|
+
LCD_LINE_1 = 0xC0
|
130
|
+
LCD_LINE_2 = 0x94
|
131
|
+
LCD_LINE_3 = 0xD4
|
132
|
+
|
133
|
+
BIT_EN = 0b00000100 # Enable bit
|
134
|
+
BIT_RW = 0b00000010 # Read/Write bit
|
135
|
+
BIT_RS = 0b00000001 # Register select bit
|
136
|
+
|
137
|
+
class BusDevice
|
138
|
+
def initialize(bus, address)
|
139
|
+
@bus, @address = bus, address
|
140
|
+
end
|
141
|
+
|
142
|
+
def write(data)
|
143
|
+
@bus.write(@address, data)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class Cursor
|
148
|
+
def initialize(display)
|
149
|
+
@display = display
|
150
|
+
end
|
151
|
+
|
152
|
+
def on
|
153
|
+
@display.write(COMMAND_DISPLAYCONTROL | FLAG_CURSORON)
|
154
|
+
end
|
155
|
+
|
156
|
+
def off
|
157
|
+
@display.write(COMMAND_DISPLAYCONTROL | FLAG_CURSOROFF)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def init_sequence
|
162
|
+
write(0x03)
|
163
|
+
write(0x03)
|
164
|
+
write(0x03)
|
165
|
+
write(0x02)
|
166
|
+
|
167
|
+
write(COMMAND_FUNCTIONSET | FLAG_2LINE | FLAG_5x8DOTS | FLAG_4BITMODE)
|
168
|
+
|
169
|
+
on
|
170
|
+
clear
|
171
|
+
write(COMMAND_ENTRYMODESET | FLAG_ENTRYLEFT)
|
172
|
+
sleep(0.2)
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Clocks EN to latch command
|
177
|
+
#
|
178
|
+
def strobe(data)
|
179
|
+
@device.write(data | BIT_EN | FLAG_BACKLIGHT)
|
180
|
+
sleep(0.0005)
|
181
|
+
@device.write(((data & ~BIT_EN) | FLAG_BACKLIGHT))
|
182
|
+
sleep(0.001)
|
183
|
+
end
|
184
|
+
|
185
|
+
def write_four_bits(data)
|
186
|
+
@device.write(data | FLAG_BACKLIGHT)
|
187
|
+
strobe(data)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/i2c/drivers/lcd'
|
3
|
+
|
4
|
+
class MiniTest::Test
|
5
|
+
def initialize(name = nil)
|
6
|
+
@test_name = name
|
7
|
+
super(name) unless name.nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def fixture(name = @test_name)
|
11
|
+
File.join(File.dirname(__FILE__), 'fixtures', name)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fakefs/safe'
|
3
|
+
require_relative '../extensions/fakefs'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class TestDisplay < MiniTest::Test
|
7
|
+
def setup
|
8
|
+
FakeFS.activate!
|
9
|
+
|
10
|
+
@io = fixture
|
11
|
+
FileUtils.mkdir_p(File.dirname(@io))
|
12
|
+
FileUtils.touch(@io)
|
13
|
+
|
14
|
+
@display = I2C::Drivers::LCD::Display.new(@io, 0x42)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
FakeFS.deactivate!
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_clear
|
22
|
+
@display.clear
|
23
|
+
s = File.read(@io).unpack('B*')
|
24
|
+
|
25
|
+
# Not sure why assert_equal chokes if FakeFs is still active
|
26
|
+
FakeFS.deactivate!
|
27
|
+
assert_equal('TBD', s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_text_0
|
31
|
+
@display.text('FOOBAR', 0)
|
32
|
+
s = File.read(@io).unpack('B*')
|
33
|
+
|
34
|
+
FakeFS.deactivate!
|
35
|
+
assert_equal('TBD', s)
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i2c-lcd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daisuke SUZUKI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i2c
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fakefs
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Ruby driver for 2004/1602 LCD display with I2C adapter
|
140
|
+
email:
|
141
|
+
- daisuke.suzuki@gmail.com
|
142
|
+
executables:
|
143
|
+
- bargraph
|
144
|
+
- lcd
|
145
|
+
- spritz
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- ".gitignore"
|
150
|
+
- ".ruby-version"
|
151
|
+
- ".travis.yml"
|
152
|
+
- CHANGELOG
|
153
|
+
- CONTRIBUTING.md
|
154
|
+
- Gemfile
|
155
|
+
- Guardfile
|
156
|
+
- LICENSE.txt
|
157
|
+
- README.markdown
|
158
|
+
- Rakefile
|
159
|
+
- TODO.markdown
|
160
|
+
- bin/bargraph
|
161
|
+
- bin/lcd
|
162
|
+
- bin/spritz
|
163
|
+
- i2c-lcd.gemspec
|
164
|
+
- lib/i2c/drivers/lcd.rb
|
165
|
+
- lib/i2c/drivers/lcd/display.rb
|
166
|
+
- lib/i2c/drivers/lcd/version.rb
|
167
|
+
- test/extensions/fakefs.rb
|
168
|
+
- test/helper.rb
|
169
|
+
- test/unit/test_item.rb
|
170
|
+
homepage: https://github.com/daisukesuzuki/i2c-lcd
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubygems_version: 3.1.2
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: Driver for the 2004/1602 LCD display
|
193
|
+
test_files:
|
194
|
+
- test/extensions/fakefs.rb
|
195
|
+
- test/helper.rb
|
196
|
+
- test/unit/test_item.rb
|