rpi_photocell 0.1.0 → 0.2.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rpi_photocell.rb +6 -67
- metadata +7 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6df7c4c2aa532adfec8e164ef17ef747ed06b4ef
|
4
|
+
data.tar.gz: ab6c10ff2cd7fbc47f05f22a706d495c8473bca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19ae87afb4b730c3e57d8dd3820e58434ccec23a511bcb3b7304c20978b836bc00163152e46790ed32330040bfd07ae4a56d877bd12449474a644807c3d7ff60
|
7
|
+
data.tar.gz: fbd9ae67c3121249a1647f6968095a3208d5e4cc46a2b7052878e489ab734f2e95efe0df021f9f6eb7e41e863afa07e3728b6ad90949ca5807f41ce3511e0f72
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/rpi_photocell.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# file: rpi_photocell.rb
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'mcp3008pi'
|
6
6
|
|
7
7
|
# To use this gem you will need the following:
|
8
8
|
#
|
@@ -11,81 +11,21 @@ require 'pi_piper'
|
|
11
11
|
# * a Photoresistor https://en.wikipedia.org/wiki/Photoresistor
|
12
12
|
|
13
13
|
|
14
|
-
class RPiPhotocell
|
14
|
+
class RPiPhotocell < Mcp3008Pi
|
15
15
|
|
16
16
|
def initialize(pin: 0, clock: 18, dout: 23, din: 24, cs: 25)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
a = [clock, dout, din, cs]
|
21
|
-
unexport_all a
|
22
|
-
|
23
|
-
@clock = PiPiper::Pin.new :pin => clock, :direction => :out
|
24
|
-
@adc_out = PiPiper::Pin.new :pin => dout
|
25
|
-
@adc_in = PiPiper::Pin.new :pin => din, :direction => :out
|
26
|
-
@cs = PiPiper::Pin.new :pin => cs, :direction => :out
|
27
|
-
|
28
|
-
at_exit do
|
29
|
-
|
30
|
-
# to avoid "Device or resource busy @ fptr_finalize - /sys/class/gpio/export"
|
31
|
-
# we unexport the pins we used
|
32
|
-
|
33
|
-
unexport_all a
|
34
|
-
end
|
18
|
+
super pin, clock, dout, din, cs
|
35
19
|
|
36
20
|
end
|
37
21
|
|
22
|
+
# reads the analog value
|
23
|
+
#
|
38
24
|
def read()
|
39
|
-
|
25
|
+
super()
|
40
26
|
end
|
41
27
|
|
42
|
-
private
|
43
|
-
|
44
|
-
def read_adc(adc_pin, clockpin, adc_in, adc_out, cspin)
|
45
|
-
|
46
|
-
cspin.on
|
47
|
-
clockpin.off
|
48
|
-
cspin.off
|
49
|
-
|
50
|
-
command_out = adc_pin
|
51
|
-
command_out |= 0x18
|
52
|
-
command_out <<= 3
|
53
|
-
|
54
|
-
(0..4).each do
|
55
|
-
adc_in.update_value((command_out & 0x80) > 0)
|
56
|
-
command_out <<= 1
|
57
|
-
clockpin.on
|
58
|
-
clockpin.off
|
59
|
-
end
|
60
|
-
|
61
|
-
result = 0
|
62
|
-
|
63
|
-
(0..11).each do
|
64
|
-
clockpin.on
|
65
|
-
clockpin.off
|
66
|
-
result <<= 1
|
67
|
-
adc_out.read
|
68
|
-
if adc_out.on?
|
69
|
-
result |= 0x1
|
70
|
-
end
|
71
|
-
end
|
72
28
|
|
73
|
-
cspin.on
|
74
|
-
|
75
|
-
result >> 1
|
76
|
-
end
|
77
|
-
|
78
|
-
def unexport_all(pins)
|
79
|
-
|
80
|
-
pins.each do |pin|
|
81
|
-
|
82
|
-
next unless File.exists? '/sys/class/gpio/gpio' + pin.to_s
|
83
|
-
|
84
|
-
File.write '/sys/class/gpio/unexport', pin
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
29
|
end
|
90
30
|
|
91
31
|
|
@@ -94,4 +34,3 @@ if __FILE__ == $0 then
|
|
94
34
|
RPiPhotocell.new.read
|
95
35
|
|
96
36
|
end
|
97
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpi_photocell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,28 +31,28 @@ cert_chain:
|
|
31
31
|
/sp+XQNiQEfBHbrDRdepJjiLhCex10OM4VqvNZIqb+0ANEvl+nqHwhFQ11k4zzKg
|
32
32
|
7otM8+kxj5i8tA==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-
|
34
|
+
date: 2016-03-06 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: mcp3008pi
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1
|
42
|
+
version: '0.1'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
45
|
+
version: 0.1.0
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1
|
52
|
+
version: '0.1'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 0.1.0
|
56
56
|
description:
|
57
57
|
email: james@r0bertson.co.uk
|
58
58
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|