rpi_photocell 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
- checksums.yaml.gz.sig +0 -0
- data/lib/rpi_photocell.rb +97 -0
- data.tar.gz.sig +1 -0
- metadata +88 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2ea1c123b7590b31ecafd08d9f68fac7eb0bdf0
|
4
|
+
data.tar.gz: f8334bdd05eb38b666a573dcdfe3d395c704432e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75eee578b9e217e0dab5866b7a7d8fa10cd3ad63c3a9a6a8be4c6c770fa43426083fbc199348b1c46e30fbb580715547b410900d250eda4485e304b30dd07eae
|
7
|
+
data.tar.gz: 0e510e52351da01895d053f21a985b7cf6ae21ef09e7495457dddefd0ef2819c24bc1ecd0c800af43bf5a23203585b4f714524f900eeecdf3073e9a07ea0e194
|
checksums.yaml.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: rpi_photocell.rb
|
4
|
+
|
5
|
+
require 'pi_piper'
|
6
|
+
|
7
|
+
# To use this gem you will need the following:
|
8
|
+
#
|
9
|
+
# * a Raspberry Pi
|
10
|
+
# * an MCP3008 10-bit Analog-to-Digital Converter (ADC)
|
11
|
+
# * a Photoresistor https://en.wikipedia.org/wiki/Photoresistor
|
12
|
+
|
13
|
+
|
14
|
+
class RPiPhotocell
|
15
|
+
|
16
|
+
def initialize(pin: 0, clock: 18, dout: 23, din: 24, cs: 25)
|
17
|
+
|
18
|
+
@adc_pin = pin
|
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
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def read()
|
39
|
+
read_adc(@adc_pin, @clock, @adc_in, @adc_out, @cs)
|
40
|
+
end
|
41
|
+
|
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
|
+
|
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
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
if __FILE__ == $0 then
|
93
|
+
|
94
|
+
RPiPhotocell.new.read
|
95
|
+
|
96
|
+
end
|
97
|
+
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
FqO*V�~�LY�>������L��f�K_2{t|3�ZF�Y&���)w�� �2��z3��P/o����q���;m]XK�z��rkJ��)6�l�f`�Ù�����9���������||���]�n�p����pXy@I��#,Q�c^�+ܦN���wEu㞋L6'D�A_Y�@x?�����w~�K��D_����_C�6�Di��;ԙ%��K��,��A�>8�;X4����¢���۳UK���zkbC����8i
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpi_photocell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTE2MDIxOTE5NTMxNFoXDTE3MDIxODE5NTMxNFowSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
|
+
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
+
ggEBANDwlU9NaayvpR7g/KXPUBa5KXGhGWjyXCHLlBaJkmyXZIHWcfPaNTQ6hydE
|
19
|
+
FkXZxFMJnlyb4PIFldQKGahsjcThDQ0z16octSxbt+W6DEbh42x/nEteBwaI+NAF
|
20
|
+
qaPlur9Fqk6BDFEBxlgbolRhu0g0IDi6LmOuTE0c6dQso/lf6F8M/xokwseFlStz
|
21
|
+
P5t9XedEfv2q2lKi5cVfEJpmYvt/fqvt6xiYhRiBLMgB7oQqUNfhb4VrDRNUstdJ
|
22
|
+
vpbgnDi60BaLMLkrqeMdTGPGFNIyxjYavLFtJjJj96RFoMQ2mddVkGYInjdYk4SX
|
23
|
+
Qkz7jXbOWOIe6G/TfgNL6wHFWV8CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
|
24
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUBGwht+71J/Gk6S+JGnW6bMWO6CAwJgYDVR0RBB8w
|
25
|
+
HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
|
26
|
+
c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEANQqKdc+0
|
27
|
+
PsPiHb3msuBBU/GF0/U6wUiHlCymTkTWf/BPKwv6qe6ku0wD/FsO6Ya4bw5WXF3b
|
28
|
+
gsjfh3FljpDkua7JmodTzbPp8VCiZGmT1G2EZIc1qFTRyEo5Brd41EQaL0KwetOV
|
29
|
+
csCZQnDiBCp9gLEZiJVXwj8pyR3xvXzU+NfoF+64EH7VMVwb+JadfAFySXveYGmX
|
30
|
+
+cYx53tv1heql6lxkZhe3+hAnlyg88O0uzMBkn0iM67o3BLVs7i1HVt2bFYgoQzc
|
31
|
+
/sp+XQNiQEfBHbrDRdepJjiLhCex10OM4VqvNZIqb+0ANEvl+nqHwhFQ11k4zzKg
|
32
|
+
7otM8+kxj5i8tA==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: pi_piper
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.9'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.9.9
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.9'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.9.9
|
56
|
+
description:
|
57
|
+
email: james@r0bertson.co.uk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/rpi_photocell.rb
|
63
|
+
homepage: https://github.com/jrobertson/rpi_photocell
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.8
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Use with a Raspberry Pi + MCP3008 10 bit analog to digital converter + photoresistor
|
87
|
+
to detect ambient light intensity.
|
88
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|