rpir 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rpir.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rpir (0.0.1)
5
+ wiringpi (~> 1.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ builder (3.0.0)
11
+ cucumber (1.2.1)
12
+ builder (>= 2.1.2)
13
+ diff-lcs (>= 1.1.3)
14
+ gherkin (~> 2.11.0)
15
+ json (>= 1.4.6)
16
+ diff-lcs (1.1.3)
17
+ gherkin (2.11.2)
18
+ json (>= 1.4.6)
19
+ json (1.7.5)
20
+ rspec (2.11.0)
21
+ rspec-core (~> 2.11.0)
22
+ rspec-expectations (~> 2.11.0)
23
+ rspec-mocks (~> 2.11.0)
24
+ rspec-core (2.11.1)
25
+ rspec-expectations (2.11.2)
26
+ diff-lcs (~> 1.1.3)
27
+ rspec-mocks (2.11.2)
28
+ wiringpi (1.1.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ cucumber (~> 1.2.1)
35
+ rpir!
36
+ rspec (~> 2.11.0)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # Rpir
2
+
3
+ WiringRuby's extension for special components
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rpir'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rpir
18
+
19
+ ## Usage
20
+
21
+ Use the circuit http://wiki.tolooh.com/raspberrypi/files/A822.1420.schaltplan.png
22
+
23
+ $ touch config.yml
24
+ $ vim config.yml # see the file features/support/config.yml
25
+ $ touch a822-1420.rb
26
+ $ vim a822-1420.rb # see example code https://gist.github.com/3686354
27
+ $ sudo ruby a822-1420.rb
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
File without changes
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ # change these as desired - they're the pins connected from the
2
+ # SPI port on the ADC to the Cobbler
3
+ input:
4
+ pinmiso: 4
5
+
6
+ output:
7
+ pinclock: 1
8
+ pinmosi: 5
9
+ pincs: 6
10
+
11
+ volt: 3.3
12
+
@@ -0,0 +1,5 @@
1
+ require 'antetype'
2
+ require 'debugger'
3
+
4
+
5
+
@@ -0,0 +1,67 @@
1
+ class ADC::MCP3008
2
+ # attr_accessor :config
3
+
4
+ def initialize(pi, channel)
5
+ @pi = pi
6
+ @channel = channel
7
+ # set up the SPI interface pins
8
+ @config = YAML.load_file Rpir::ROOT_CONFIG
9
+ @config[Rpir::INPUT].each do |pin|
10
+ @pi.mode(pin[1], INPUT)
11
+ @pin_miso = pin[1] if pin[0] == PIN::MISO
12
+ end
13
+ @config[Rpir::OUTPUT].each do |pin|
14
+ @pi.mode(pin[1], OUTPUT)
15
+ case pin[0]
16
+ when PIN::CLOCK
17
+ @pin_clock = pin[1]
18
+ when PIN::MOSI
19
+ @pin_mosi = pin[1]
20
+ when PIN::CS
21
+ @pin_cs = pin[1]
22
+ end
23
+ end
24
+ end
25
+
26
+ # def config
27
+ # @config = YAML.load_file Rpir::ROOT_CONFIG
28
+ # end
29
+
30
+ # def config=(str)
31
+ # @config = str
32
+ # end
33
+
34
+ # read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
35
+ def read_adc()
36
+ # temperature sensor connected 'channel' of mcp3008
37
+ return -1 if ((@channel > 7) || (@channel < 0))
38
+ @pi.write(@pin_cs,HIGH)
39
+
40
+ @pi.write(@pin_clock,LOW) # start clock low
41
+ @pi.write(@pin_cs,LOW) # bring CS low
42
+
43
+ commandout = @channel
44
+ commandout |= 0x18 # start bit + single-ended bit
45
+ commandout <<= 3 # we only need to send 5 bits here
46
+ for i in 0...5
47
+ if (commandout & 0x80) > 0
48
+ @pi.write(@pin_mosi,HIGH)
49
+ else
50
+ @pi.write(@pin_mosi,LOW)
51
+ end
52
+ commandout <<= 1
53
+ @pi.write(@pin_clock,HIGH)
54
+ @pi.write(@pin_clock,LOW)
55
+ end
56
+
57
+ @adcout = 0
58
+ # read in one empty bit, one null bit and 10 ADC bits
59
+ for i in 0...12
60
+ @pi.write(@pin_clock,HIGH)
61
+ @pi.write(@pin_clock,LOW)
62
+ @adcout <<= 1
63
+ @adcout |= 0x1 if @pi.read(@pin_miso) == HIGH
64
+ end
65
+ [@adcout /= 2, Time.now] # first bit is 'null' so drop it
66
+ end
67
+ end
@@ -0,0 +1,31 @@
1
+ require "rpir/version"
2
+ require 'yaml'
3
+
4
+ module Rpir
5
+ ROOT_RPIR = Dir.pwd
6
+ ROOT_CONFIG = ROOT_RPIR + '/config.yml'
7
+ T = {
8
+ :MCP3008 => :ADC,
9
+ :TMP36 => :TEMPERATURE,
10
+ :LM35 => :TEMPERATURE
11
+ }
12
+ OUTPUT = 'output'
13
+ INPUT = 'input'
14
+ end
15
+
16
+ module PIN
17
+ MISO = 'pinmiso'
18
+ CLOCK = 'pinclock'
19
+ MOSI = 'pinmosi'
20
+ CS = 'pincs'
21
+ end
22
+
23
+ module ADC
24
+ class MCP3008
25
+ end
26
+ end
27
+
28
+ require "adc/mcp3008"
29
+ require "temperature/temperature"
30
+ require "temperature/lm35"
31
+ require "temperature/tmp36"
@@ -0,0 +1,3 @@
1
+ module Rpir
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'temperature/temperature'
2
+
3
+ class LM35 < Temperature
4
+ def initialize(a2d, pi, channel)
5
+ super
6
+ @millivolts = adc * ( @volt * 1000.0 / 1024.0 )
7
+ @celsius = millivolts / 10
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ require 'adc/mcp3008'
2
+
3
+ class Temperature
4
+ def initialize(a2d, pi, channel)
5
+ @channel = channel
6
+ config = YAML.load_file Rpir::ROOT_CONFIG
7
+ @volt = config['volt']
8
+ @adc, @time = eval("#{Rpir::T[a2d]}::#{a2d}")
9
+ .new(pi,channel)
10
+ .read_adc()
11
+ end
12
+
13
+ def time
14
+ @time
15
+ end
16
+
17
+ def channel
18
+ @channel
19
+ end
20
+
21
+ def adc
22
+ @adc
23
+ end
24
+
25
+ def volt
26
+ @volt
27
+ end
28
+
29
+ def millivolts
30
+ @millivolts
31
+ end
32
+
33
+ def millivolts_to_s(dec=nil)
34
+ "%.#{dec}f" % @millivolts unless dec.nil?
35
+ end
36
+
37
+ def celsius
38
+ @celsius
39
+ end
40
+
41
+ def fahrenheit
42
+ ( @celsius * 9.0 / 5.0 ) + 32
43
+ end
44
+
45
+ def celsius_to_s(dec=nil)
46
+ "%.#{dec}f" % celsius unless dec.nil?
47
+ end
48
+
49
+ def fahrenheit_to_s(dec=nil)
50
+ "%.#{dec}f" % fahrenheit unless dec.nil?
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ require 'temperature/temperature'
2
+
3
+ class TMP36 < Temperature
4
+ def initialize(a2d, pi, channel)
5
+ super
6
+ @millivolts = @adc * ( @volt * 1000.0 / 1024.0 )
7
+ @celsius = ((@millivolts - 100.0) / 10.0) - 40.0
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rpir/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Gudao Luo"]
6
+ gem.email = ["gudao.luo@gmail.com"]
7
+ gem.description = %q{WiringRuby's extension for special components}
8
+ gem.summary = %q{RaspBerryPi WiringPi WiringRuby extension components}
9
+ gem.homepage = "https://github.com/cnruby/rpir"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "rpir"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Rpir::VERSION
17
+
18
+ gem.add_development_dependency 'rspec', '~> 2.11.0'
19
+ gem.add_development_dependency 'cucumber', '~> 1.2.1'
20
+
21
+ gem.add_runtime_dependency 'wiringpi', '~> 1.1.0'
22
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpir
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Gudao Luo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-09-09 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.11.0
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: cucumber
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.2.1
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: wiringpi
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.0
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ description: WiringRuby's extension for special components
49
+ email:
50
+ - gudao.luo@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - features/cn_MCP3008.feature
64
+ - features/cn_MCP3008_LM35.feature
65
+ - features/cn_MCP3008_TMP36.feature
66
+ - features/step_definitions/cn_MCP3008.rb
67
+ - features/step_definitions/cn_MCP3008_LM35.rb
68
+ - features/step_definitions/cn_MCP3008_TMP36.rb
69
+ - features/support/config.yml
70
+ - features/support/env.rb
71
+ - lib/adc/mcp3008.rb
72
+ - lib/rpir.rb
73
+ - lib/rpir/version.rb
74
+ - lib/temperature/lm35.rb
75
+ - lib/temperature/temperature.rb
76
+ - lib/temperature/tmp36.rb
77
+ - rpir.gemspec
78
+ homepage: https://github.com/cnruby/rpir
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options: []
83
+
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.22
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: RaspBerryPi WiringPi WiringRuby extension components
105
+ test_files:
106
+ - features/cn_MCP3008.feature
107
+ - features/cn_MCP3008_LM35.feature
108
+ - features/cn_MCP3008_TMP36.feature
109
+ - features/step_definitions/cn_MCP3008.rb
110
+ - features/step_definitions/cn_MCP3008_LM35.rb
111
+ - features/step_definitions/cn_MCP3008_TMP36.rb
112
+ - features/support/config.yml
113
+ - features/support/env.rb
114
+ has_rdoc: