atlas_scientific 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
+ SHA256:
3
+ metadata.gz: c9984113c1b34d48088d53279bbfe26f8ef88bb038aafa7e510b30eb12df615d
4
+ data.tar.gz: 36ab968dc9358881fe662a156735a93a99deb93588ad255687f1c009a95ed63b
5
+ SHA512:
6
+ metadata.gz: 01eef62a0e98a34fd15b8f8a8cc0cea9ddf63bc9df3652258a6f107b5e904cbe05d5cb1a8aecb5066ddabee57e4c8bee65ed566b61ed3b6f9630d4e38825f7c2
7
+ data.tar.gz: 39aa5e120126a4556bceea849db88ef2c3d0f48056402706bda730d8b5154e42f8a51d7e5e270bb5b6220bebb32413c6d54aae6dc214d5e12cc52fa6251bc3fd
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at Elektron1c97@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in atlas_scientific.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ atlas_scientific (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.12.2)
10
+ rake (10.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ atlas_scientific!
17
+ bundler (~> 2.0)
18
+ minitest (~> 5.0)
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yves Siegrist
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,88 @@
1
+ # AtlasScientific
2
+
3
+ AtlasScientific is an abstraction layer [atlas scientific](https://www.atlas-scientific.com) devices.
4
+ Any atlas scientific can be used, although the checked ones are supported with easier and optimized APIs.
5
+
6
+ - [x] [PH circuit](https://www.atlas-scientific.com/product_pages/circuits/ezo_ph.html)
7
+ - [x] [EC circuit](https://www.atlas-scientific.com/product_pages/circuits/ezo_ec.html)
8
+ - [x] [Temperature circuit](https://www.atlas-scientific.com/product_pages/circuits/ezo_rtd.html)
9
+ - [ ] [ORP circuit](https://www.atlas-scientific.com/product_pages/circuits/ezo_orp.html)
10
+ - [ ] [Dissolved oxygen circuit](https://www.atlas-scientific.com/dissolved-oxygen.html)
11
+ - [ ] [Carbon dioxide Sensor (CO2)](https://www.atlas-scientific.com/product_pages/probes/ezo-co2.html)
12
+ - [ ] [Pressure Sensor](https://www.atlas-scientific.com/product_pages/pressure/ezo-prs.html)
13
+ - [ ] [Flow Meter Totalizer](https://www.atlas-scientific.com/product_pages/circuits/ezo_flow.html)
14
+ - [ ] [Color Sensor](https://www.atlas-scientific.com/product_pages/probes/ezo-rgb.html)
15
+
16
+ _Disclaimer: This library only supports `i2c` mode._
17
+
18
+ **NOTE**: Although they aren't "supported" you can still use this library to access them easily. See [usage](#usage).
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'atlas_scientific'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install atlas_scientific
35
+
36
+ ## Usage
37
+
38
+ There's a base class for any AtlasScientific device which can be used like this:
39
+
40
+ ```ruby
41
+ require 'atlas_scientific'
42
+
43
+ # The path parameter will automatically look for the first `i2c-*` device in your `/dev` folder.
44
+ # But you can also explicitly pass it as an argument:
45
+ pressure = AtlasScientific::I2CDevice.new(0x6A, path: '/dev/i2c-1')
46
+ pressure.take_reading # => 12.3
47
+
48
+ # enable/disables the LED
49
+ pressure.l # => "?"
50
+
51
+ # A lot of "default" commands are support through methods, e.g. cal, factory, i, find, o, status etc.
52
+ pressure.i => "?I,psi"
53
+
54
+ # If there happens to be a command which is not implemented as a method, you can call "execute":
55
+ # This command will change the output of the pressure unit sensor as specified in the datasheet.
56
+ # On page 46: https://www.atlas-scientific.com/_files/_datasheets/_pressure/EZO-PRS-Datasheet.pdf
57
+ pressure.execute('u', 'bar')
58
+ ```
59
+
60
+ There are also better abstraction classes for the checked circuit/probes at the top:
61
+
62
+ ```ruby
63
+ # Automatically takes the default I2C address of the PH circuit (0x63)
64
+ # The default i2c addresses can be found in the datasheets of the circuits
65
+ # E.g. PH: https://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_Datasheet.pdf
66
+ ph = AtlasScientific::PH.new
67
+ ph.slope # => 7.58
68
+ ph.take_reading # => 7.58
69
+ ph.take_reading_with_temperature_compensation(29.3) # => 7.49
70
+ ```
71
+
72
+ ## Development
73
+
74
+ 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.
75
+
76
+ 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).
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/siegy22/atlas_scientific. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
+
86
+ ## Code of Conduct
87
+
88
+ Everyone interacting in the AtlasScientific project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/siegy22/atlas_scientific/blob/master/CODE_OF_CONDUCT.md).
@@ -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,25 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'atlas_scientific/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'atlas_scientific'
7
+ spec.version = AtlasScientific::VERSION
8
+ spec.authors = ['Yves Siegrist']
9
+ spec.email = ['yves@siegrist.io']
10
+
11
+ spec.summary = 'Ruby library to provide an easy abstraction of the I2C command protocol which atlas scientific devices implement'
12
+ spec.homepage = 'https://github.com/siegy22/atlas_scientific'
13
+ spec.license = 'MIT'
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 2.0'
23
+ spec.add_development_dependency 'minitest', '~> 5.0'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "atlas_scientific"
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(__FILE__)
@@ -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,9 @@
1
+ require 'atlas_scientific/version'
2
+ require 'atlas_scientific/i2c_device'
3
+ require 'atlas_scientific/ec'
4
+ require 'atlas_scientific/ph'
5
+ require 'atlas_scientific/temperature'
6
+
7
+ module AtlasScientific
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,19 @@
1
+ require 'atlas_scientific/i2c_device'
2
+
3
+ module AtlasScientific
4
+ # Abstraction layer to EZO Conductivity Circuit
5
+ # https://www.atlas-scientific.com/product_pages/circuits/ezo_ec.html
6
+ class EC < I2CDevice
7
+ def initialize(address = 0x64)
8
+ super(address)
9
+ end
10
+
11
+ def probe_type=(type)
12
+ k(type)
13
+ end
14
+
15
+ def k(*args)
16
+ execute('k', *args)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,101 @@
1
+ module AtlasScientific
2
+ class I2CDevice
3
+ class NoDataToSendError < StandardError; end
4
+ class StillProcessingError < StandardError; end
5
+ class CommandSyntaxError < StandardError; end
6
+ class UnknownStatusCodeError < StandardError; end
7
+
8
+ STILL_PROCESSING = 254
9
+ I2C_SLAVE = 0x0703
10
+
11
+
12
+ def initialize(address, path: Dir.glob('/dev/i2c-*').first)
13
+ @address = address
14
+ @path = path
15
+ end
16
+
17
+ # Takes a reading using the "r" ezo command
18
+ # and casts it to a float
19
+ def reading
20
+ r.to_f
21
+ end
22
+ alias take_reading reading
23
+ alias read reading
24
+
25
+ # Takes a reading with a given temperature
26
+ # and casts it to a float
27
+ def take_reading_with_temperature_compensation(temperature)
28
+ rt(temperature.to_s).to_f
29
+ end
30
+
31
+ def calibrated?
32
+ !execute('cal', '?').casecmp?('?cal,0')
33
+ end
34
+
35
+ [
36
+ 'baud',
37
+ 'cal',
38
+ 'factory',
39
+ 'find',
40
+ 'i',
41
+ 'i2c',
42
+ 'l',
43
+ 'o',
44
+ 'plock',
45
+ 'r',
46
+ 'rt',
47
+ 'sleep',
48
+ 'status',
49
+ 't'
50
+ ].each do |cmd|
51
+ define_method(cmd) do |*args|
52
+ execute(cmd, *args)
53
+ end
54
+ end
55
+
56
+ alias information i
57
+
58
+ alias temperature_compensation t
59
+
60
+ alias protocol_lock plock
61
+
62
+ def execute(command, *args)
63
+ io = File.open(@path, 'r+')
64
+ # Set i2c address and mode
65
+ io.ioctl(I2C_SLAVE, @address)
66
+
67
+ # Prepare EZO command like
68
+ ezo_command = [command, *args].join(',')
69
+
70
+ io.syswrite(ezo_command)
71
+ return if command == 'sleep'
72
+
73
+ # Wait for the command to finish
74
+ result, status = loop do
75
+ result = io.read(31)
76
+ status = result[0].unpack1('C')
77
+ break [result, status] unless status == STILL_PROCESSING
78
+ end
79
+
80
+ check_for_status_code(status, ezo_command)
81
+ result[1..-1].strip
82
+ ensure
83
+ io&.close
84
+ end
85
+
86
+ def check_for_status_code(code, ezo_command)
87
+ return if code == 1
88
+
89
+ case code
90
+ when 255
91
+ raise NoDataToSendError
92
+ when 2
93
+ raise CommandSyntaxError, "There was an error executing the following command: #{ezo_command}\n" \
94
+ 'Please check the documentation of your circuit.'
95
+ else
96
+ raise UnknownStatusCodeError, "Unkown Response code: #{code} received from device.\n" \
97
+ 'Check the latest datasheet of atlas scientific.'
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,15 @@
1
+ require 'atlas_scientific/i2c_device'
2
+
3
+ module AtlasScientific
4
+ # Abstraction layer to EZO pH Circuit
5
+ # https://www.atlas-scientific.com/product_pages/circuits/ezo_ph.html
6
+ class PH < I2CDevice
7
+ def initialize(address = 0x63)
8
+ super(address)
9
+ end
10
+
11
+ def slope
12
+ execute('slope', '?')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'atlas_scientific/i2c_device'
2
+
3
+ module AtlasScientific
4
+ # Abstraction layer to EZO RTD Temperature Circuit
5
+ # https://www.atlas-scientific.com/product_pages/circuits/ezo_rtd.html
6
+ class Temperature < I2CDevice
7
+ def initialize(address = 0x66)
8
+ super(address)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module AtlasScientific
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atlas_scientific
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yves Siegrist
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-18 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.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: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - yves@siegrist.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - atlas_scientific.gemspec
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/atlas_scientific.rb
73
+ - lib/atlas_scientific/ec.rb
74
+ - lib/atlas_scientific/i2c_device.rb
75
+ - lib/atlas_scientific/ph.rb
76
+ - lib/atlas_scientific/temperature.rb
77
+ - lib/atlas_scientific/version.rb
78
+ homepage: https://github.com/siegy22/atlas_scientific
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.0.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Ruby library to provide an easy abstraction of the I2C command protocol which
101
+ atlas scientific devices implement
102
+ test_files: []