- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
de.wigbels.ruby/hothotread/hothotpiper_power.rb
r1801b32 rb62bf13 1 1 require 'pi_piper' 2 require 'eventmachine'3 4 2 include PiPiper 5 6 3 7 4 mypath = File.expand_path(File.dirname(__FILE__)) 8 5 trigger_step = 1.0 / 96 9 trigger_watch = 010 6 counter = 0 11 12 7 13 8 def last_rrd_count(concretepath) … … 24 19 end 25 20 21 26 22 watch :pin => 11, :trigger => :falling do 27 23 puts('updated power consumption') 28 trigger_watch = 1 24 counter = counter + trigger_step 25 trigger_update = trigger_step * 3600000.0 26 system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_update}") 29 27 end 30 31 28 32 29 rrdpath = mypath + "/power.rrd" 33 30 counter = last_rrd_count(rrdpath) 34 puts('Counter restored to: ' + counter.to_s) 35 36 37 EventMachine.run do 38 EM.add_periodic_timer(1) do 39 if trigger_watch == 1 then 40 counter = counter + trigger_step 41 trigger_update = trigger_step * 3600000.0 42 system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_update}") 43 puts('Counter updated to: ' + counter.to_s) 44 trigger_watch = 0 45 end 46 end 47 end 31 PiPiper.wait
Note:
See TracChangeset
for help on using the changeset viewer.