sysfs_one_wire 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/.rspec +2 -0
- data/Gemfile +1 -0
- data/LICENSE +22 -0
- data/README.md +75 -0
- data/Rakefile +7 -0
- data/bin/console +9 -0
- data/bin/setup +7 -0
- data/lib/one_wire.rb +61 -0
- data/lib/one_wire/base.rb +41 -0
- data/lib/one_wire/thermometer.rb +13 -0
- data/one_wire.gemspec +21 -0
- data/spec/base_spec.rb +53 -0
- data/spec/fixtures/sys_bus_w1_devices/00-000000000000/name +1 -0
- data/spec/fixtures/sys_bus_w1_devices/00-000000000000/w1_slave +2 -0
- data/spec/fixtures/sys_bus_w1_devices/08-000000000004/name +1 -0
- data/spec/fixtures/sys_bus_w1_devices/08-000000000004/w1_slave +2 -0
- data/spec/fixtures/sys_bus_w1_devices/28-000000000001/name +1 -0
- data/spec/fixtures/sys_bus_w1_devices/28-000000000001/w1_slave +2 -0
- data/spec/fixtures/sys_bus_w1_devices/28-000000000002/name +1 -0
- data/spec/fixtures/sys_bus_w1_devices/28-000000000002/w1_slave +2 -0
- data/spec/fixtures/sys_bus_w1_devices/28-000000000003/name +1 -0
- data/spec/fixtures/sys_bus_w1_devices/28-000000000003/w1_slave +3 -0
- data/spec/spec_helper.rb +3 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 767be903b9b0f5499c7b176faf0105e154e4facf
|
4
|
+
data.tar.gz: 157afd2037881682e55fedad30c3248d5765b836
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 722a00b944df3a8af7baf2d4e11d4f7b80cdcc785aa6226312ad99e68158aa59176dadd5cf00a5348875fff2c57e0c4e081e7c022720fafb92da0df4a4ca051c
|
7
|
+
data.tar.gz: e37922e67092d604818fe1ea5c4f980edfccadec55f4c1903651c65fb620d2763e34418cefb613d90db0fa8a7f07ca8b71505f3bea2db73a206bb7e023c9df1f
|
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 ASAPP SARL <opensource@asapp.fr>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# One Wire
|
2
|
+
This is a ruby gem offering binding to w1-gpio kernel module.
|
3
|
+
|
4
|
+
GPIO w1 bus master driver by Ville Syrjala <syrjala@sci.fi>
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
`w1-gpio` module should be loaded,
|
8
|
+
```
|
9
|
+
modprobe w1-gpio
|
10
|
+
```
|
11
|
+
|
12
|
+
depending on the device you want to control load one of these.
|
13
|
+
```
|
14
|
+
modprobe -a w1_bq27000 w1_ds2413 w1_ds2431 w1_ds2760 w1_ds2781 w1_therm w1_ds2408 w1_ds2423 w1_ds2433 w1_ds2780 w1_ds28e04 w1_smem
|
15
|
+
```
|
16
|
+
and of course
|
17
|
+
```ruby
|
18
|
+
gem 'sysfs_one_wire'
|
19
|
+
#or
|
20
|
+
gem install sysfs_one_wire
|
21
|
+
```
|
22
|
+
|
23
|
+
for loading after reboot and depending on your OS you could try following commands
|
24
|
+
|
25
|
+
### Debian/Raspian/Ubuntu
|
26
|
+
```
|
27
|
+
/etc/modules.conf
|
28
|
+
/etc/modprobe.d/modeprobe.conf
|
29
|
+
/etc/modprobe.d/
|
30
|
+
```
|
31
|
+
|
32
|
+
### Raspian
|
33
|
+
You will also need to activate the device tree :
|
34
|
+
```
|
35
|
+
cat 'dtoverlay=w1-gpio' > /boot/config.txt
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
```ruby
|
40
|
+
OneWire.slaves # return the paths of the slaves
|
41
|
+
OneWire.find(/2GAE/) # return the paths of corresponding slave.
|
42
|
+
|
43
|
+
OneWire.load(path) # return the devices objects for a given path
|
44
|
+
OneWire.devices # return all the devices objects
|
45
|
+
```
|
46
|
+
|
47
|
+
### Extend
|
48
|
+
```ruby
|
49
|
+
class Mermory < OneWire::Base
|
50
|
+
|
51
|
+
PREFIX = %w{06 08 0A 0C}
|
52
|
+
attr_reader :last_value
|
53
|
+
|
54
|
+
def value
|
55
|
+
@last_value = @value
|
56
|
+
@value = w1_slave[/some regexp to isolate the content/, 1]
|
57
|
+
end
|
58
|
+
|
59
|
+
def value= arg
|
60
|
+
@last_value = @value
|
61
|
+
File.write(File.join(@path.to_s, 'w1_slave'), arg)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
## Limitation/Alternative
|
67
|
+
This is a work in progress. It only support thermometer for now, but will be extented (and this is quite easy to do it)
|
68
|
+
|
69
|
+
If you need more, Maxim's Integrated offers a whole filesystem with OWFS
|
70
|
+
|
71
|
+
[https://github.com/mholling/one_wire]
|
72
|
+
[https://github.com/pedrocr/ownet]
|
73
|
+
|
74
|
+
|
75
|
+
**Need this? come and give a hand !**
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/one_wire.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'one_wire/base'
|
2
|
+
require 'one_wire/thermometer'
|
3
|
+
|
4
|
+
module OneWire
|
5
|
+
class << self
|
6
|
+
def slaves &block
|
7
|
+
Dir.glob(File.join(File::SEPARATOR, 'sys', 'bus', 'w1', 'devices', '*-*'), &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def find query
|
11
|
+
query = Regexp.new query if query.is_a? String
|
12
|
+
slaves.keep_if { |v| v =~ query }
|
13
|
+
end
|
14
|
+
|
15
|
+
# def find query, &block
|
16
|
+
# devices = slaves.keep_if { |v| v =~ query }
|
17
|
+
# devices = devices.collect { |path| load(path) }
|
18
|
+
# devices.each &block if block_given?
|
19
|
+
# devices
|
20
|
+
# end
|
21
|
+
|
22
|
+
def all &block
|
23
|
+
devices = slaves.collect { |path| load(path) rescue nil }.compact
|
24
|
+
devices.each &block if block_given?
|
25
|
+
devices
|
26
|
+
end
|
27
|
+
|
28
|
+
# def find_by_type
|
29
|
+
# end
|
30
|
+
|
31
|
+
# def find_by_id
|
32
|
+
# end
|
33
|
+
|
34
|
+
# def find_by_name
|
35
|
+
# end
|
36
|
+
|
37
|
+
def load path
|
38
|
+
case File.basename(path)[/([\da-f]{2})-[\da-f]{12}/, 1]
|
39
|
+
when *Thermometer::PREFIX then return Thermometer.new(path)
|
40
|
+
# when *%w{06 08 0A 0C} then Memory.new(path)
|
41
|
+
when %{00} then return nil
|
42
|
+
else Base.new(path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def devices
|
47
|
+
slaves.collect { |path| load(path) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Maxim's Integrated devices types :
|
53
|
+
# Identification only
|
54
|
+
# Identification plus control
|
55
|
+
# Identification plus temperature
|
56
|
+
# Identification plus time
|
57
|
+
# Identification plus NV SRAM
|
58
|
+
# Identification plus (one time programmable) OTP EPROM
|
59
|
+
# Identification plus EEPROM
|
60
|
+
# Identification plus SHA-1 secure EEPROM
|
61
|
+
# Identification plus logging
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module OneWire
|
2
|
+
class Base
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize path = nil
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
read_attr 'name'
|
11
|
+
end
|
12
|
+
|
13
|
+
def id
|
14
|
+
read_attr 'id'
|
15
|
+
end
|
16
|
+
|
17
|
+
def w1_slave
|
18
|
+
read_attr 'w1_slave'
|
19
|
+
end
|
20
|
+
|
21
|
+
alias_method :to_s, :w1_slave
|
22
|
+
|
23
|
+
def value *args
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def last_value *args
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
|
31
|
+
def dump
|
32
|
+
[self.class, @path]
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def read_attr value
|
38
|
+
File.read(File.join(@path.to_s, value)).chomp('')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/one_wire.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "sysfs_one_wire"
|
3
|
+
spec.version = '0.1.0'
|
4
|
+
|
5
|
+
spec.authors = ["as:app worker"]
|
6
|
+
spec.summary = %q{asapp_gem}
|
7
|
+
spec.description = %q{Maxim's 1-wire binding backed on w1-gpio driver}
|
8
|
+
spec.email = %q{opensource@asapp.fr}
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.homepage = %q{https://github.com/asapp/one_wire}
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($\)
|
13
|
+
spec.require_paths = ["lib"]
|
14
|
+
|
15
|
+
spec.extra_rdoc_files = Dir['*.md']
|
16
|
+
spec.rdoc_options = ["--charset=UTF-8"]
|
17
|
+
|
18
|
+
spec.add_development_dependency 'rake'
|
19
|
+
spec.add_development_dependency 'rspec'
|
20
|
+
spec.add_development_dependency 'rdoc'
|
21
|
+
end
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OneWire do
|
4
|
+
before do
|
5
|
+
allow(File).to receive(:join).and_call_original
|
6
|
+
allow(File).to receive(:join).with(File::SEPARATOR, 'sys', 'bus', 'w1', 'devices', '*-*').and_return(File.expand_path "#{__dir__}/fixtures/sys_bus_w1_devices/*-*")
|
7
|
+
end
|
8
|
+
|
9
|
+
it { expect(subject.slaves).to all( match /fixtures\/sys_bus_w1_devices\/.{2}-.{12}/ ) }
|
10
|
+
|
11
|
+
it { expect(subject.find "00-").to all( match "00-" ) }
|
12
|
+
it { expect(subject.find "00-").to all( match /00-/ ) }
|
13
|
+
it { expect(subject.find /00-/).to all( match "00-" ) }
|
14
|
+
it { expect(subject.find /00-/).to all( match /00-/ ) }
|
15
|
+
it { expect(subject.find(/00-/).first).to match /fixtures\/sys_bus_w1_devices\/0{2}-0{12}/ }
|
16
|
+
|
17
|
+
it { expect(subject.load(subject.find(/00-/).first)).to be_nil}
|
18
|
+
it { expect(subject.load(subject.find(/28-/).first)).to be_kind_of OneWire::Thermometer}
|
19
|
+
|
20
|
+
it { expect(subject.all).to all(be_kind_of(OneWire::Base))}
|
21
|
+
|
22
|
+
describe OneWire::Base do
|
23
|
+
it { is_expected.to be_kind_of OneWire::Base }
|
24
|
+
it { expect{ subject.name }.to raise_error Errno::ENOENT }
|
25
|
+
|
26
|
+
let(:empty_device) {OneWire::Base.new(OneWire.find(/00-/).first)}
|
27
|
+
it { expect(empty_device.name).to eq "00-000000000000" }
|
28
|
+
xit { expect(empty_device.id).to eq "" } # don't know how to read `id` file
|
29
|
+
it { expect(empty_device.w1_slave).to eq "empty device" }
|
30
|
+
|
31
|
+
it { expect { empty_device.value }.to raise_error(NotImplementedError) }
|
32
|
+
it { expect { empty_device.last_value }.to raise_error(NotImplementedError) }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe OneWire::Thermometer do
|
36
|
+
subject {OneWire::Thermometer.new(OneWire.find(/-000000000003/).first)}
|
37
|
+
|
38
|
+
it { is_expected.to be_kind_of OneWire::Thermometer }
|
39
|
+
it { expect(subject.name).to eq "28-000000000003" }
|
40
|
+
xit { expect(subject.id).to eq "" } # don't know how to read `id` file
|
41
|
+
it { expect(subject.w1_slave).to eq "9f 01 4b 46 7f ff 01 10 40 : crc=40 YES\n9f 01 4b 46 7f ff 01 10 40 t=25937" }
|
42
|
+
|
43
|
+
it { expect(subject.value).to eq 25.937 }
|
44
|
+
|
45
|
+
it "should update the last value" do
|
46
|
+
expect(subject.last_value).to be_nil
|
47
|
+
subject.value
|
48
|
+
expect(subject.last_value).to be_nil
|
49
|
+
subject.value
|
50
|
+
expect(subject.last_value).to eq 25.937
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
00-000000000000
|
@@ -0,0 +1 @@
|
|
1
|
+
08-000000000004
|
@@ -0,0 +1 @@
|
|
1
|
+
28-000000000001
|
@@ -0,0 +1 @@
|
|
1
|
+
28-000000000002
|
@@ -0,0 +1 @@
|
|
1
|
+
28-000000000003
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sysfs_one_wire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- as:app worker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rspec
|
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: rdoc
|
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
|
+
description: Maxim's 1-wire binding backed on w1-gpio driver
|
56
|
+
email: opensource@asapp.fr
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- README.md
|
61
|
+
files:
|
62
|
+
- ".rspec"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- lib/one_wire.rb
|
70
|
+
- lib/one_wire/base.rb
|
71
|
+
- lib/one_wire/thermometer.rb
|
72
|
+
- one_wire.gemspec
|
73
|
+
- spec/base_spec.rb
|
74
|
+
- spec/fixtures/sys_bus_w1_devices/00-000000000000/name
|
75
|
+
- spec/fixtures/sys_bus_w1_devices/00-000000000000/w1_slave
|
76
|
+
- spec/fixtures/sys_bus_w1_devices/08-000000000004/name
|
77
|
+
- spec/fixtures/sys_bus_w1_devices/08-000000000004/w1_slave
|
78
|
+
- spec/fixtures/sys_bus_w1_devices/28-000000000001/name
|
79
|
+
- spec/fixtures/sys_bus_w1_devices/28-000000000001/w1_slave
|
80
|
+
- spec/fixtures/sys_bus_w1_devices/28-000000000002/name
|
81
|
+
- spec/fixtures/sys_bus_w1_devices/28-000000000002/w1_slave
|
82
|
+
- spec/fixtures/sys_bus_w1_devices/28-000000000003/name
|
83
|
+
- spec/fixtures/sys_bus_w1_devices/28-000000000003/w1_slave
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: https://github.com/asapp/one_wire
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options:
|
91
|
+
- "--charset=UTF-8"
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.5
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: asapp_gem
|
110
|
+
test_files: []
|