Ignore:
Timestamp:
Mar 3, 2016, 11:44:50 AM (8 years ago)
Author:
Norbert Wigbels <norbert.wigbels@…>
Branches:
master
Children:
8b9b145
Parents:
7e221fe (diff), 20d3261 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of wigbels.net:/var/git/public

File:
1 edited

Legend:

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

    r7e221fe re397ced  
    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.