Ignore:
File:
1 edited

Legend:

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

    rb62bf13 r1801b32  
    11require 'pi_piper'
     2require 'eventmachine'
     3
    24include PiPiper
     5
    36
    47mypath = File.expand_path(File.dirname(__FILE__))
    58trigger_step = 1.0 / 96
     9trigger_watch = 0
    610counter = 0
     11
    712
    813def last_rrd_count(concretepath)
     
    1924end
    2025
    21 
    2226watch :pin => 11, :trigger => :falling  do
    2327  puts('updated power consumption')
    24   counter = counter + trigger_step
    25   trigger_update = trigger_step * 3600000.0
    26   system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_update}")
     28  trigger_watch = 1
    2729end
     30
    2831
    2932rrdpath = mypath + "/power.rrd"
    3033counter = last_rrd_count(rrdpath)
    31 PiPiper.wait
     34puts('Counter restored to: ' + counter.to_s)
     35
     36
     37EventMachine.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
     47end
Note: See TracChangeset for help on using the changeset viewer.