neotrellis 0.1.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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/Gemfile +2 -0
- data/LICENSE +674 -0
- data/README.md +113 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/datasheets/adafruit-neotrellis.pdf +0 -0
- data/datasheets/neotrellis.jpg +0 -0
- data/datasheets/seesaw-atsamd09.pdf +0 -0
- data/lib/neotrellis.rb +3 -0
- data/lib/neotrellis/keypad.rb +230 -0
- data/lib/neotrellis/neopixel.rb +198 -0
- data/lib/neotrellis/seesaw.rb +139 -0
- data/lib/neotrellis/version.rb +6 -0
- data/neotrellis.gemspec +30 -0
- metadata +146 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
# Neotrellis - Driver for Adafruit's NeoTrellis keypad
|
2
|
+
# Copyleft 2019 - Nicolas AGIUS <nicolas.agius@lps-it.fr>
|
3
|
+
|
4
|
+
###########################################################################
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
###########################################################################
|
20
|
+
|
21
|
+
require 'i2c'
|
22
|
+
|
23
|
+
# Monkey patch, sorry
|
24
|
+
class Numeric
|
25
|
+
# Helper to display hex number as string
|
26
|
+
def to_shex
|
27
|
+
"0x%02X" % [self]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Neotrellis
|
32
|
+
# Driver for Seesaw i2c generic conversion chip.
|
33
|
+
# See https://www.adafruit.com/product/3657 for example board.
|
34
|
+
#
|
35
|
+
# @example Display Seesaw's device version
|
36
|
+
# seesaw = Neotrellis::Seesaw.new(device: "/dev/i2c-1", addr: 0x2E)
|
37
|
+
# puts seesaw.version
|
38
|
+
class Seesaw
|
39
|
+
|
40
|
+
DEFAULT_I2C_ADDR = 0x49 # Default SeeSaw I2C address
|
41
|
+
|
42
|
+
private
|
43
|
+
# SeeSaw hardware ID
|
44
|
+
HW_ID_CODE = 0x55
|
45
|
+
|
46
|
+
# Internal SeeSaw registers
|
47
|
+
STATUS_BASE = 0x00
|
48
|
+
STATUS_SWRST = 0x7F
|
49
|
+
STATUS_HW_ID = 0x01
|
50
|
+
STATUS_VERSION = 0x02
|
51
|
+
|
52
|
+
public
|
53
|
+
|
54
|
+
# Initialize a Seesaw chip on the i2c bus.
|
55
|
+
# It use the i2c kernel driver to communicate with the chip.
|
56
|
+
#
|
57
|
+
# @param device [String] Linux I2C-dev file the SeeSaw device is connected to
|
58
|
+
# @param addr [Integer] I2C address of the SeeSaw device
|
59
|
+
# @param debug [Boolean] Enable debug ouput on stdout
|
60
|
+
def initialize(device: '/dev/i2c-0', addr: DEFAULT_I2C_ADDR, debug: false)
|
61
|
+
@i2c = I2C.create(device)
|
62
|
+
@addr = addr
|
63
|
+
@debug = debug
|
64
|
+
|
65
|
+
sw_reset
|
66
|
+
rescue I2C::AckError
|
67
|
+
STDERR.puts "I2C initialization error, check your wiring and I2C addresses."
|
68
|
+
raise
|
69
|
+
end
|
70
|
+
|
71
|
+
# Trigger a software reset of the SeeSaw chip
|
72
|
+
def sw_reset()
|
73
|
+
write(STATUS_BASE, STATUS_SWRST, 0xFF)
|
74
|
+
|
75
|
+
# Give some time to the device to reset (but not when testing)
|
76
|
+
sleep(0.5) unless testing?
|
77
|
+
|
78
|
+
chip_id = read_byte(STATUS_BASE, STATUS_HW_ID)
|
79
|
+
|
80
|
+
if chip_id != HW_ID_CODE
|
81
|
+
raise "Seesaw hardware ID returned #{chip_id.to_shex} is not correct! Expected #{HW_ID_CODE.to_shex}. Please check your wiring."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get the version of the Seesaw chip
|
86
|
+
#
|
87
|
+
# @return [Integer] Version number
|
88
|
+
def version()
|
89
|
+
# 4 bytes for Unsigned Int Big Endian
|
90
|
+
@i2c.read(@addr, 4, STATUS_BASE, STATUS_VERSION).unpack('I>').first
|
91
|
+
end
|
92
|
+
|
93
|
+
# Read a byte from a Seesaw register
|
94
|
+
#
|
95
|
+
# @param base_reg [Byte] Base register address
|
96
|
+
# @param function_reg [Byte] Function register address
|
97
|
+
#
|
98
|
+
# @return [Byte] Value read in the given register
|
99
|
+
def read_byte(base_reg, function_reg)
|
100
|
+
read_raw(1, base_reg, function_reg).ord
|
101
|
+
end
|
102
|
+
|
103
|
+
# Read bytes from a Seesaw register
|
104
|
+
#
|
105
|
+
# @param size [Integer] Number of bytes to read
|
106
|
+
# @param base_reg [Byte] Base register address
|
107
|
+
# @param function_reg [Byte] Function register address
|
108
|
+
#
|
109
|
+
# @return [Array] Array of bytes read in the given register
|
110
|
+
def read_bytes(size, base_reg, function_reg)
|
111
|
+
read_raw(size, base_reg, function_reg).unpack("C#{size}")
|
112
|
+
end
|
113
|
+
|
114
|
+
# Write data to the given register
|
115
|
+
#
|
116
|
+
# @param base_reg [Byte] Base register address
|
117
|
+
# @param function_reg [Byte] Function register address
|
118
|
+
# @param data [Array] Data to write. Must be an array of bytes or a binary string with big endian format
|
119
|
+
def write(base_reg, function_reg, *data)
|
120
|
+
puts "DEBUG: I2C WRITE: %02X %02X %s" % [base_reg, function_reg, data.map{|i| "%02X" % [i]}.join(' ')] if @debug
|
121
|
+
@i2c.write(@addr, base_reg, function_reg, *data)
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def read_raw(size, base_reg, function_reg)
|
127
|
+
data = @i2c.read(@addr, size, base_reg, function_reg)
|
128
|
+
puts "DEBUG: I2C READ: %02X %02X %s" % [base_reg, function_reg, data.unpack("C#{size}").map{|i| "%02X" % [i]}.join(' ')] if @debug
|
129
|
+
|
130
|
+
data
|
131
|
+
end
|
132
|
+
|
133
|
+
def testing?
|
134
|
+
ENV['RSPEC_TEST']&.downcase == 'true'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# vim: ts=4:sw=4:ai
|
data/neotrellis.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "neotrellis/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "neotrellis"
|
7
|
+
spec.version = Neotrellis::VERSION
|
8
|
+
spec.authors = ["Nicolas AGIUS"]
|
9
|
+
spec.email = ["nicolas.agius@lps-it.fr"]
|
10
|
+
|
11
|
+
spec.summary = %q{Neotrellis is a ruby driver for Adafruit's NeoTrellis keypad.}
|
12
|
+
spec.homepage = "https://github.com/nagius/neotrellis"
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "i2c", "~>0.4"
|
25
|
+
spec.add_runtime_dependency "ya_gpio", "~>0.1"
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: neotrellis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas AGIUS
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-05 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.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ya_gpio
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- nicolas.agius@lps-it.fr
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- datasheets/adafruit-neotrellis.pdf
|
113
|
+
- datasheets/neotrellis.jpg
|
114
|
+
- datasheets/seesaw-atsamd09.pdf
|
115
|
+
- lib/neotrellis.rb
|
116
|
+
- lib/neotrellis/keypad.rb
|
117
|
+
- lib/neotrellis/neopixel.rb
|
118
|
+
- lib/neotrellis/seesaw.rb
|
119
|
+
- lib/neotrellis/version.rb
|
120
|
+
- neotrellis.gemspec
|
121
|
+
homepage: https://github.com/nagius/neotrellis
|
122
|
+
licenses: []
|
123
|
+
metadata:
|
124
|
+
homepage_uri: https://github.com/nagius/neotrellis
|
125
|
+
source_code_uri: https://github.com/nagius/neotrellis
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.7.6.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Neotrellis is a ruby driver for Adafruit's NeoTrellis keypad.
|
146
|
+
test_files: []
|