Floppy-currentcost 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -1
- data/bin/currentcost_tray_monitor.rb +45 -2
- metadata +2 -2
data/README
CHANGED
@@ -36,6 +36,8 @@ usage. To use the program, run:
|
|
36
36
|
currentcost_tray_monitor.rb -p your_serial_port_name
|
37
37
|
|
38
38
|
The program requires the Gtk2 libraries for Ruby (available from
|
39
|
-
http://ruby-gnome2.sourceforge.jp/).
|
39
|
+
http://ruby-gnome2.sourceforge.jp/). If the EEML gem (http://github.com/Floppy/eeml-ruby)
|
40
|
+
is installed, it can also serve your power data over an HTTP connection to a system like
|
41
|
+
Pachube (http://www.pachube.com).
|
40
42
|
|
41
43
|
For more details, see http://github.com/Floppy/currentcost-ruby/wikis/currentcosttraymonitor
|
@@ -8,15 +8,29 @@ require 'rubygems'
|
|
8
8
|
require 'currentcost'
|
9
9
|
require 'optparse'
|
10
10
|
|
11
|
+
# If EEML is available, start a simple server which will serve power information
|
12
|
+
begin
|
13
|
+
require 'eeml'
|
14
|
+
require 'webrick'
|
15
|
+
$eeml_server_enabled = true
|
16
|
+
rescue LoadError
|
17
|
+
$eeml_server_enabled = false
|
18
|
+
end
|
19
|
+
|
20
|
+
|
11
21
|
# Command-line options
|
12
22
|
options = {:port => '/dev/ttyS0'}
|
13
23
|
OptionParser.new do |opts|
|
14
24
|
opts.on("-p", "--serial_port SERIAL_PORT", "serial port") do |p|
|
15
25
|
options[:port] = p
|
16
|
-
end
|
26
|
+
end
|
27
|
+
if $eeml_server_enabled == true
|
28
|
+
opts.on("-h", "--http_port HTTP_PORT", "http port") do |h|
|
29
|
+
options[:http_port] = h
|
30
|
+
end
|
31
|
+
end
|
17
32
|
end.parse!
|
18
33
|
|
19
|
-
|
20
34
|
# Pixbuf images - generated from PNG files with gdk-pixbuf-csource --raw
|
21
35
|
GREY =
|
22
36
|
# Pixbuf magic (0x47646b50)
|
@@ -300,6 +314,7 @@ about_item.signal_connect('activate') {
|
|
300
314
|
|
301
315
|
quit_item.signal_connect('activate') {
|
302
316
|
$meter.close
|
317
|
+
$eeml_server.shutdown if $eeml_server_enabled && $eeml_server.status == :Running
|
303
318
|
Gtk.main_quit
|
304
319
|
}
|
305
320
|
|
@@ -326,6 +341,11 @@ class MeterObserver
|
|
326
341
|
end
|
327
342
|
# Set tooltip
|
328
343
|
$tray.tooltip = "#{watts} watts"
|
344
|
+
# Update EEML data
|
345
|
+
if $eeml_server_enabled && $eeml_server.status == :Running
|
346
|
+
$eeml_environment[0].value = watts
|
347
|
+
$eeml_environment.set_updated!
|
348
|
+
end
|
329
349
|
rescue
|
330
350
|
$tray.pixbuf = $grey_pixbuf
|
331
351
|
end
|
@@ -336,5 +356,28 @@ $meter = CurrentCost::Meter.new(options[:port])
|
|
336
356
|
obs = MeterObserver.new
|
337
357
|
$meter.add_observer(obs)
|
338
358
|
|
359
|
+
# Create EEML HTTP server if options are set
|
360
|
+
if $eeml_server_enabled && options[:http_port]
|
361
|
+
# Create EEML environment
|
362
|
+
$eeml_environment = EEML::Environment.new
|
363
|
+
# Create data object
|
364
|
+
data = EEML::Data.new(0)
|
365
|
+
data.unit = EEML::Unit.new("Watts", :symbol => 'W', :type => :derivedSI)
|
366
|
+
$eeml_environment << data
|
367
|
+
# Create WEBrick server
|
368
|
+
$eeml_server = WEBrick::HTTPServer.new( :Port => options[:http_port] )
|
369
|
+
# Create a simple webrick servlet for index.eeml
|
370
|
+
class EEMLServlet < WEBrick::HTTPServlet::AbstractServlet
|
371
|
+
def do_GET(request, response)
|
372
|
+
response.status = 200
|
373
|
+
response['Content-Type'] = "text/xml"
|
374
|
+
response.body = $eeml_environment.to_eeml
|
375
|
+
end
|
376
|
+
end
|
377
|
+
$eeml_server.mount("/index.eeml", EEMLServlet)
|
378
|
+
trap("INT") {$eeml_server.shutdown}
|
379
|
+
Thread.new{$eeml_server.start}
|
380
|
+
end
|
381
|
+
|
339
382
|
# Go
|
340
383
|
Gtk.main
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Floppy-currentcost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Smith
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|