rpi_led_simulator 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_led_simulator.rb +127 -0
- data.tar.gz.sig +0 -0
- metadata +87 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adb8c11a2870cecb4ee0b30ac76c1c95596f1d1a
|
4
|
+
data.tar.gz: a170de743d0d2e108640b9739a7fccd57e7c835b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35d5f803a2bf67c96746217d3696dc2041bce846176567203764db3f730af062fbb30a0f619050f56158902eb98ebd98f1cfa15a772a35a3f52beb2128ca8db8
|
7
|
+
data.tar.gz: aeea97b09943fd674ba9e44ec4452cd5eaa6f279413cff144305678398198c7b1c9f0254cbb0b7aa1a6f4deebc23cbd5cddde4b612b7637bf464aee0e45db982
|
checksums.yaml.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: rpi_led_simulator.rb
|
4
|
+
|
5
|
+
require 'colored'
|
6
|
+
|
7
|
+
class RPiLedSimulator
|
8
|
+
|
9
|
+
@leds = []
|
10
|
+
|
11
|
+
class PinX
|
12
|
+
|
13
|
+
HIGH = 1
|
14
|
+
LOW = 0
|
15
|
+
|
16
|
+
def initialize(id, color: :red, parent: nil)
|
17
|
+
@id = id
|
18
|
+
@on, @blinking = false, false
|
19
|
+
@color = color
|
20
|
+
@parent = parent
|
21
|
+
end
|
22
|
+
|
23
|
+
def color()
|
24
|
+
@on ? @color : :black
|
25
|
+
end
|
26
|
+
|
27
|
+
def on(duration=nil)
|
28
|
+
@on = true
|
29
|
+
|
30
|
+
(sleep duration; self.off) if duration
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def off(duration=nil)
|
35
|
+
|
36
|
+
return if self.off?
|
37
|
+
@on, @blinking = false, false
|
38
|
+
(sleep duration; self.on) if duration
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
alias stop off
|
44
|
+
|
45
|
+
def blink(seconds=0.5, duration: nil)
|
46
|
+
|
47
|
+
@blinking = true
|
48
|
+
t2 = Time.now + duration if duration
|
49
|
+
|
50
|
+
Thread.new do
|
51
|
+
while @blinking do
|
52
|
+
(@on = true; sleep seconds; @on = false; sleep seconds)
|
53
|
+
@on = false; @blinking = false if duration and Time.now >= t2
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def on?() @on end
|
60
|
+
def off?() !@on end
|
61
|
+
|
62
|
+
def to_s()
|
63
|
+
@id
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Void
|
68
|
+
def on(duration=nil) end
|
69
|
+
def off() end
|
70
|
+
def blink(seconds=0, duration=nil) end
|
71
|
+
alias stop off
|
72
|
+
end
|
73
|
+
|
74
|
+
def initialize(x=[], color: :red, symbol: '▋')
|
75
|
+
|
76
|
+
@color, @symbol = color, symbol
|
77
|
+
|
78
|
+
a = case x
|
79
|
+
when Fixnum
|
80
|
+
[x]
|
81
|
+
when String
|
82
|
+
[x]
|
83
|
+
when Array
|
84
|
+
x
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
@pins = a.map {|pin| PinX.new pin, color: color, parent: self }
|
89
|
+
|
90
|
+
def @pins.[](i)
|
91
|
+
|
92
|
+
if i.respond_to? :to_i and i.to_i >= self.length then
|
93
|
+
puts "RPi warning: PinX instance #{i.inspect} not found"
|
94
|
+
Void.new
|
95
|
+
else
|
96
|
+
super(i)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
def pin() @pins.first end
|
103
|
+
def pins() @pins end
|
104
|
+
|
105
|
+
def refresh(n=0)
|
106
|
+
|
107
|
+
# get the pin value
|
108
|
+
|
109
|
+
colors = @pins.map {|pin| pin.color }
|
110
|
+
a = [" ".on_white]
|
111
|
+
a.concat colors.map{|c| @symbol.method((c.to_s + '_on_white').to_sym).call }
|
112
|
+
|
113
|
+
print "\r " + a.join + " ".on_white
|
114
|
+
|
115
|
+
return if n < 1
|
116
|
+
|
117
|
+
sleep 0.01
|
118
|
+
refresh n-1
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
def watch(n=2.8)
|
123
|
+
refresh n * 100
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpi_led_simulator
|
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
|
+
8ixkARkWAmV1MB4XDTE2MDIyODE1MDY0MVoXDTE3MDIyNzE1MDY0MVowSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
|
+
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
+
ggEBAPI3W+VdfHNRISVMY9C/+VyajhPjTq4259k2pEapadn9yILlZBX9NY4UlaKZ
|
19
|
+
xgi/VDc7OW+Cyp0nuPidp60if7gu5JwTHgsLPwAFKB4o+a3j6BhckJC6ftgijXGd
|
20
|
+
aIaAp1Gw6yqOGrn8su7MiNd3f50h3iKBHAbEAfE3GH6vkSNABfti7CKgNRt8IA1A
|
21
|
+
3F4r9DV8AQnNI++X8bjs8VQoe7TU+imKHNrRcCeTchFbHJaZS8kiyBLvrtvtJW6v
|
22
|
+
pfH6Hv4vdcQCz/T+xFPXe5c8lQ8b6woSwZO6xPot2s6b1OuKGyXUJDu5dVp1xpom
|
23
|
+
EH9ia64ELuOPwqNdcuYR3OQJQK8CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
|
24
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUJvk9Z5l5IK7I57Yv6yHRxrIcECswJgYDVR0RBB8w
|
25
|
+
HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
|
26
|
+
c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEA5FXh3Rt8
|
27
|
+
kz/kUTukMq+V3ctrO3N+VogoePl9Av6hR2LxP5bvB3IZC3oNf8ITG9g/Gjqb9x91
|
28
|
+
w/FltJD/TX+50zjchGCRts0cz9Nim5sPvjofqFTQXXBVW4jI49iTqxglG/5JMFPc
|
29
|
+
hBWSph87YB7YC1bERR2P3BqWXbVqy9SI1LkaSAjh3217NpnMbqwhVm5RGu+9ICcv
|
30
|
+
WHykbpTwyfbg1wmjqPFcY1HyQKBGoKhxjwCp1G9v9JzE+w0kyr/l8jAhlgYmIKWj
|
31
|
+
bwR7OTPxfUGtsltpk/G06ubaiEebf43FWKslAIXKvk6NNAQr1lIPxsAQAHKDIX8P
|
32
|
+
zsvqgrA/hRrQgw==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: colored
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.2'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.2'
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.2'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.2'
|
56
|
+
description:
|
57
|
+
email: james@r0bertson.co.uk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/rpi_led_simulator.rb
|
63
|
+
homepage: https://github.com/jrobertson/rpi_led_simulator
|
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: Simulates the rpi gem's functionality for controlling LEDs.
|
87
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|