Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • de.wigbels.ruby/hothotread/hothotpiper_power.rb

    r1801b32 rb62bf13  
    11require 'pi_piper'
    2 require 'eventmachine'
    3 
    42include PiPiper
    5 
    63
    74mypath = File.expand_path(File.dirname(__FILE__))
    85trigger_step = 1.0 / 96
    9 trigger_watch = 0
    106counter = 0
    11 
    127
    138def last_rrd_count(concretepath)
     
    2419end
    2520
     21
    2622watch :pin => 11, :trigger => :falling  do
    2723  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}")
    2927end
    30 
    3128
    3229rrdpath = mypath + "/power.rrd"
    3330counter = 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
     31PiPiper.wait
Note: See TracChangeset for help on using the changeset viewer.