blinkenlights 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/README.en +2 -3
- data/VERSION +1 -1
- data/examples/loadbar.rb +24 -0
- data/examples/netblinker.rb +1 -1
- data/lib/blinkenlights.rb +29 -14
- metadata +9 -7
data/CHANGES
ADDED
data/README.en
CHANGED
@@ -27,9 +27,8 @@ $ ruby make_doc.rb
|
|
27
27
|
and the API documentation is generated by your rdoc command in
|
28
28
|
the doc/ sub-directory.
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
root.
|
30
|
+
Some small examples can be found in the examples directory of the distribution
|
31
|
+
directory. You very likely have to run it as root.
|
33
32
|
|
34
33
|
Author
|
35
34
|
======
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/examples/loadbar.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'blinkenlights'
|
4
|
+
include BlinkenLights::Constants
|
5
|
+
|
6
|
+
proc_loadavg = '/proc/loadavg'
|
7
|
+
|
8
|
+
bl = BlinkenLights.new
|
9
|
+
trap(:INT) do
|
10
|
+
bl.close if bl
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
bl.off
|
15
|
+
loop do
|
16
|
+
loadavg = File.read(proc_loadavg).scan(/\d+\.\d+/)[0].to_f
|
17
|
+
case loadavg
|
18
|
+
when 0.00..0.25 then bl.digital = 0
|
19
|
+
when 0.25..0.50 then bl.digital = LED_LEFT
|
20
|
+
when 0.50..0.75 then bl.digital = LED_LEFT | LED_MIDDLE
|
21
|
+
when 0.75..1.00 then bl.digital = LED_LEFT | LED_MIDDLE | LED_RIGHT
|
22
|
+
else bl.flash
|
23
|
+
end
|
24
|
+
end
|
data/examples/netblinker.rb
CHANGED
data/lib/blinkenlights.rb
CHANGED
@@ -46,9 +46,10 @@
|
|
46
46
|
# 100.times { bl.random }
|
47
47
|
# bl.close
|
48
48
|
#
|
49
|
-
# There's also
|
50
|
-
# directory of this library, that
|
51
|
-
# packets are received/transmitted on
|
49
|
+
# There's also two short examples examples/netblinker.rb and
|
50
|
+
# examples/loadbar.rb in the distribution directory of this library, that show
|
51
|
+
# how to let the lights blink if network packets are received/transmitted on
|
52
|
+
# your host or how high the cpu load average is.
|
52
53
|
class BlinkenLights
|
53
54
|
|
54
55
|
# Module to hold the BlinkenLights constants.
|
@@ -94,6 +95,12 @@ class BlinkenLights
|
|
94
95
|
|
95
96
|
# The right LED
|
96
97
|
LED_RIGHT = 1
|
98
|
+
|
99
|
+
# None of the LEDs
|
100
|
+
LED_NONE = 0
|
101
|
+
|
102
|
+
# All of the LEDs
|
103
|
+
LED_ALL = 7
|
97
104
|
end
|
98
105
|
include Constants
|
99
106
|
|
@@ -135,16 +142,24 @@ class BlinkenLights
|
|
135
142
|
|
136
143
|
# Switch off all LEDs.
|
137
144
|
def off
|
138
|
-
set
|
145
|
+
set LED_NONE
|
139
146
|
self
|
140
147
|
end
|
141
148
|
|
142
149
|
# Switch on all LEDs.
|
143
150
|
def on
|
144
|
-
set
|
151
|
+
set LED_ALL
|
145
152
|
self
|
146
153
|
end
|
147
154
|
|
155
|
+
# First switches all LEDs on, then off. Sleep for _delay_ seconds after
|
156
|
+
# switching them on.
|
157
|
+
def flash(delay = 0.0)
|
158
|
+
on
|
159
|
+
sleep delay
|
160
|
+
off
|
161
|
+
end
|
162
|
+
|
148
163
|
# Set LEDs to _number_ in binary digital mode.
|
149
164
|
def digital=(number)
|
150
165
|
number %= 8
|
@@ -207,7 +222,7 @@ class BlinkenLights
|
|
207
222
|
|
208
223
|
# Switch some of the LEDs on by random. Then sleep for _delay_ seconds.
|
209
224
|
def random(delay = 0.0)
|
210
|
-
self.digital = rand(
|
225
|
+
self.digital = rand(LED_ALL + 1)
|
211
226
|
sleep delay
|
212
227
|
self
|
213
228
|
end
|
@@ -235,7 +250,7 @@ class BlinkenLights
|
|
235
250
|
# Return the state of the Scroll Lock LED: true for switched on, false for
|
236
251
|
# off.
|
237
252
|
def scr
|
238
|
-
(get & LED_SCR) !=
|
253
|
+
(get & LED_SCR) != LED_NONE
|
239
254
|
end
|
240
255
|
|
241
256
|
# Switch the Scroll Lock LED on, if _toggle_ is true, off, otherwise.
|
@@ -252,13 +267,13 @@ class BlinkenLights
|
|
252
267
|
# LED off, if it was on before.
|
253
268
|
def toggle_scr(delay = 0.0)
|
254
269
|
self.scr = !scr
|
255
|
-
sleep
|
270
|
+
sleep delay
|
256
271
|
self
|
257
272
|
end
|
258
273
|
|
259
274
|
# Return the state of the Caps Lock LED: true for switched on, false for off.
|
260
275
|
def cap
|
261
|
-
(get & LED_CAP) !=
|
276
|
+
(get & LED_CAP) != LED_NONE
|
262
277
|
end
|
263
278
|
|
264
279
|
# Switch the Caps Lock LED on, if _toggle_ is true, off, otherwise.
|
@@ -281,7 +296,7 @@ class BlinkenLights
|
|
281
296
|
|
282
297
|
# Return the state of the Num Lock LED: true for switched on, false for off.
|
283
298
|
def num
|
284
|
-
(get & LED_NUM) !=
|
299
|
+
(get & LED_NUM) != LED_NONE
|
285
300
|
end
|
286
301
|
|
287
302
|
# Switch the Num Lock LED on, if _toggle_ is true, off, otherwise.
|
@@ -304,7 +319,7 @@ class BlinkenLights
|
|
304
319
|
# Return the state of the left LED: true for switched on, false for
|
305
320
|
# off.
|
306
321
|
def left
|
307
|
-
(digital & LED_LEFT) !=
|
322
|
+
(digital & LED_LEFT) != LED_NONE
|
308
323
|
end
|
309
324
|
|
310
325
|
# Switch the left LED on, if _toggle_ is true, off, otherwise.
|
@@ -321,13 +336,13 @@ class BlinkenLights
|
|
321
336
|
# LED off, if it was on before.
|
322
337
|
def toggle_left(delay = 0.0)
|
323
338
|
self.left = !left
|
324
|
-
sleep
|
339
|
+
sleep delay
|
325
340
|
self
|
326
341
|
end
|
327
342
|
|
328
343
|
# Return the state of the middle LED: true for switched on, false for off.
|
329
344
|
def middle
|
330
|
-
(digital & LED_MIDDLE) !=
|
345
|
+
(digital & LED_MIDDLE) != LED_NONE
|
331
346
|
end
|
332
347
|
|
333
348
|
# Switch the middle LED on, if _toggle_ is true, off, otherwise.
|
@@ -350,7 +365,7 @@ class BlinkenLights
|
|
350
365
|
|
351
366
|
# Return the state of the right LED: true for switched on, false for off.
|
352
367
|
def right
|
353
|
-
(digital & LED_RIGHT) !=
|
368
|
+
(digital & LED_RIGHT) != LED_NONE
|
354
369
|
end
|
355
370
|
|
356
371
|
# Switch the right LED on, if _toggle_ is true, off, otherwise.
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: blinkenlights
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2005-10-
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2005-10-19 00:00:00 +02:00
|
8
8
|
summary: Control the Blinkenlights on your keyboard from Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,15 +29,17 @@ cert_chain:
|
|
29
29
|
authors:
|
30
30
|
- Florian Frank
|
31
31
|
files:
|
32
|
-
- Rakefile
|
33
|
-
- GPL
|
34
32
|
- examples
|
35
|
-
- README.en
|
36
|
-
- VERSION
|
37
33
|
- install.rb
|
38
|
-
-
|
34
|
+
- GPL
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- CHANGES
|
39
38
|
- lib
|
39
|
+
- make_doc.rb
|
40
|
+
- README.en
|
40
41
|
- examples/netblinker.rb
|
42
|
+
- examples/loadbar.rb
|
41
43
|
- lib/blinkenlights.rb
|
42
44
|
test_files: []
|
43
45
|
rdoc_options:
|