pi-lights-control 0.2.0 → 1.0.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
- data/CHANGELOG.md +5 -0
- data/README.md +3 -16
- data/exe/pi-lights-control +32 -96
- data/lib/pi-lights-control.rb +13 -13
- data/lib/pi-lights-control/command.rb +3 -3
- data/lib/pi-lights-control/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b7a8a8550a1b6fbdca33a0f8ea7772caa417690
|
4
|
+
data.tar.gz: cabf059d2b62b01cfd1cd24876aef0a27f217c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0842ac706aa95f7cfd1f3037d5563f7637cefc967e471ca70e8881c8967955b9b6123db17dafa05794c984767d13c2f7ef128bea19016d2b4ca7fbecc526388a
|
7
|
+
data.tar.gz: 3a52c2e9bb8bcef9169bf38afc6b9987876880a71bb634750536f4a659eab0192d3bdbc623bbc0f6d2de1faf53b958f3cba78354202869aa1c0437141a9ad00b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Pi Lights Control
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/pi-lights-control)
|
4
|
+
|
5
|
+
This gem provides an executable and a library for sending radio frequency commands from a Raspberry Pi connected with a 433.920 MHz transmitter to one or more sets of Home Collection Remote Control Christmas Lights (Product #151-3478-6). I have only tested it with the C9 light set, it *might* work with the C6 light set too.
|
4
6
|
|
5
7
|
The gem should be compatible with any Raspberry Pi that has GPIO pins. It has been tested with a 433.920 MHz FS1000A module (pictured below) for Arduino/Raspberry Pi compatible devices. It **will not** build on MacOS as epoll is only supported on Linux.
|
6
8
|
|
@@ -138,21 +140,6 @@ c.program(:step_fade) # Lights fade from off to on but at discrete brightness st
|
|
138
140
|
|
139
141
|
(Secret: The default remote actually sends 16 different codes! However codes 9–16 trigger the same eight programs as codes 1–8.)
|
140
142
|
|
141
|
-
## Roadmap
|
142
|
-
|
143
|
-
For v0.1.0:
|
144
|
-
|
145
|
-
* Support power on/off for lights
|
146
|
-
* Support all light programs and sync
|
147
|
-
|
148
|
-
For v0.2.0:
|
149
|
-
|
150
|
-
* Add executable
|
151
|
-
|
152
|
-
For v0.3.0:
|
153
|
-
|
154
|
-
* Any cleanup/refactoring before v1.0
|
155
|
-
|
156
143
|
## Development
|
157
144
|
|
158
145
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/exe/pi-lights-control
CHANGED
@@ -1,125 +1,61 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'gli'
|
4
|
+
require 'pi-lights-control'
|
5
5
|
|
6
6
|
include GLI::App
|
7
7
|
|
8
|
-
program_desc
|
8
|
+
program_desc 'Control Home Collection Lights over GPIO and RF Transmitter'
|
9
9
|
|
10
|
-
desc
|
11
|
-
flag [:p
|
10
|
+
desc 'GPIO pin number for RF Transmitter. Mandatory.'
|
11
|
+
flag [:p, :pin], type: Integer
|
12
12
|
|
13
|
-
desc
|
14
|
-
long_desc
|
13
|
+
desc 'Turn lights on'
|
14
|
+
long_desc 'Sends a "power on" command to the lights'
|
15
15
|
command :on do |c|
|
16
|
-
c.action do |global_options
|
17
|
-
help_now!(
|
16
|
+
c.action do |global_options|
|
17
|
+
help_now!('No pin number specified') if global_options[:pin].nil?
|
18
18
|
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
19
19
|
command.power_on
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
desc
|
24
|
-
long_desc
|
23
|
+
desc 'Turn lights off'
|
24
|
+
long_desc 'Sends a "power off" command to the lights'
|
25
25
|
command :off do |c|
|
26
|
-
c.action do |global_options
|
27
|
-
help_now!(
|
26
|
+
c.action do |global_options|
|
27
|
+
help_now!('No pin number specified') if global_options[:pin].nil?
|
28
28
|
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
29
29
|
command.power_off
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
desc
|
34
|
-
long_desc
|
33
|
+
desc 'Sync multiple light sets'
|
34
|
+
long_desc 'Sends a "sync" command to any lights in range'
|
35
35
|
command :sync do |c|
|
36
|
-
c.action do |global_options
|
37
|
-
help_now!(
|
36
|
+
c.action do |global_options|
|
37
|
+
help_now!('No pin number specified') if global_options[:pin].nil?
|
38
38
|
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
39
39
|
command.sync_lights
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
desc
|
44
|
-
long_desc
|
43
|
+
desc 'Run a lights program'
|
44
|
+
long_desc %(
|
45
|
+
Sends a command to run a specific lights program. One of 'combination',
|
46
|
+
'steady', 'slow_blink', 'fast_blink', 'slow_fade', 'fast_fade',
|
47
|
+
'blink_steady', or 'step_fade'.
|
48
|
+
)
|
45
49
|
command :program do |c|
|
46
|
-
c.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
52
|
-
command.program(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
c.desc "Steady"
|
57
|
-
c.long_desc "Lights are continuously on"
|
58
|
-
c.command :steady do |p|
|
59
|
-
p.action do |global_options,options,args|
|
60
|
-
help_now!("No pin number specified") if global_options[:pin].nil?
|
61
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
62
|
-
command.program(:steady)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
c.desc "Slow Blink"
|
67
|
-
c.long_desc "Lights are on 1/2 second, then off 1/2 second"
|
68
|
-
c.command :slow_blink do |p|
|
69
|
-
p.action do |global_options,options,args|
|
70
|
-
help_now!("No pin number specified") if global_options[:pin].nil?
|
71
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
72
|
-
command.program(:slow_blink)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
c.desc "Fast Blink"
|
77
|
-
c.long_desc "Lights blink on/off much faster"
|
78
|
-
c.command :fast_blink do |p|
|
79
|
-
p.action do |global_options,options,args|
|
80
|
-
help_now!("No pin number specified") if global_options[:pin].nil?
|
81
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
82
|
-
command.program(:fast_blink)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
c.desc "Slow Fade"
|
87
|
-
c.long_desc "Lights fade from off to on at a slow rate"
|
88
|
-
c.command :slow_fade do |p|
|
89
|
-
p.action do |global_options,options,args|
|
90
|
-
help_now!("No pin number specified") if global_options[:pin].nil?
|
91
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
92
|
-
command.program(:slow_fade)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
c.desc "Fast Fade"
|
97
|
-
c.long_desc "Lights fade from off to on at a fast rate"
|
98
|
-
c.command :fast_fade do |p|
|
99
|
-
p.action do |global_options,options,args|
|
100
|
-
help_now!("No pin number specified") if global_options[:pin].nil?
|
101
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
102
|
-
command.program(:fast_fade)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
c.desc "Blink Steady"
|
107
|
-
c.long_desc "Lights blink twice, then are steady for a second or two"
|
108
|
-
c.command :blink_steady do |p|
|
109
|
-
p.action do |global_options,options,args|
|
110
|
-
help_now!("No pin number specified") if global_options[:pin].nil?
|
111
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
112
|
-
command.program(:blink_steady)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
c.desc "Step Fade"
|
117
|
-
c.long_desc "Lights fade from off to on but at discrete brightness steps instead of a continuous increase/decrease"
|
118
|
-
c.command :step_fade do |p|
|
119
|
-
p.action do |global_options,options,args|
|
120
|
-
help_now!("No pin number specified") if global_options[:pin].nil?
|
121
|
-
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
122
|
-
command.program(:step_fade)
|
50
|
+
c.action do |global_options, _options, args|
|
51
|
+
program_name = args[0]
|
52
|
+
case program_name
|
53
|
+
when 'combination', 'steady', 'slow_blink', 'fast_blink',
|
54
|
+
'slow_fade', 'fast_fade', 'blink_steady', 'step_fade'
|
55
|
+
command = PiLightsControl::Command.new(global_options[:pin].to_i)
|
56
|
+
command.program(program_name.to_sym)
|
57
|
+
else
|
58
|
+
help_now!('Unknown program name')
|
123
59
|
end
|
124
60
|
end
|
125
61
|
end
|
data/lib/pi-lights-control.rb
CHANGED
@@ -9,19 +9,19 @@ module PiLightsControl
|
|
9
9
|
1 => [4, 8],
|
10
10
|
2 => [4, 71],
|
11
11
|
3 => [26, 12]
|
12
|
-
}
|
12
|
+
}.freeze
|
13
13
|
COMMAND_TABLE = {
|
14
|
-
power_off: [3,0,1,0,1,1,0,0,1,1,1,0,1,0,0,0,1,2],
|
15
|
-
power_on: [3,0,1,0,1,1,0,0,1,1,1,0,1,0,0,0,0,2],
|
16
|
-
sync_lights: [3,0,0,1,1,0,1,1,1,0,0,0,1,1,1,0,0,2],
|
17
|
-
program_combination: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,0,0,0,2],
|
18
|
-
program_steady: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,0,0,1,2],
|
19
|
-
program_slow_blink: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,2],
|
20
|
-
program_fast_blink: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,1,2],
|
21
|
-
program_slow_fade: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,1,0,0,2],
|
22
|
-
program_fast_fade: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,1,0,1,2],
|
23
|
-
program_blink_steady: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,1,1,0,2],
|
24
|
-
program_step_fade: [3,0,1,0,1,1,0,0,1,1,1,1,0,0,1,1,1,2]
|
25
|
-
}
|
14
|
+
power_off: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 2],
|
15
|
+
power_on: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 2],
|
16
|
+
sync_lights: [3, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 2],
|
17
|
+
program_combination: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 2],
|
18
|
+
program_steady: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 2],
|
19
|
+
program_slow_blink: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 2],
|
20
|
+
program_fast_blink: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 2],
|
21
|
+
program_slow_fade: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 2],
|
22
|
+
program_fast_fade: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 2],
|
23
|
+
program_blink_steady: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 2],
|
24
|
+
program_step_fade: [3, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 2]
|
25
|
+
}.freeze
|
26
26
|
TIME_DELAY = 120 # microseconds
|
27
27
|
end
|
@@ -17,7 +17,7 @@ module PiLightsControl
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def program(name)
|
20
|
-
program_name = "program_#{name
|
20
|
+
program_name = "program_#{name}"
|
21
21
|
transmit_command(PiLightsControl::COMMAND_TABLE[program_name.to_sym])
|
22
22
|
end
|
23
23
|
|
@@ -35,10 +35,10 @@ module PiLightsControl
|
|
35
35
|
low_length = PiLightsControl::CODE_TABLE[code][1]
|
36
36
|
|
37
37
|
RPi::GPIO.set_high @pin
|
38
|
-
sleep(high_length * PiLightsControl::TIME_DELAY /
|
38
|
+
sleep(high_length * PiLightsControl::TIME_DELAY / 1E6)
|
39
39
|
|
40
40
|
RPi::GPIO.set_low @pin
|
41
|
-
sleep(low_length * PiLightsControl::TIME_DELAY /
|
41
|
+
sleep(low_length * PiLightsControl::TIME_DELAY / 1E6)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
RPi::GPIO.clean_up @pin
|