Changeset e397ced for de.wigbels.ruby/hothotread/hothotpiper_power.rb
- Timestamp:
- Mar 3, 2016, 11:44:50 AM (8 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
de.wigbels.ruby/hothotread/hothotpiper_power.rb
r7e221fe re397ced 1 1 require 'pi_piper' 2 require 'eventmachine' 3 2 4 include PiPiper 5 3 6 4 7 mypath = File.expand_path(File.dirname(__FILE__)) 5 8 trigger_step = 1.0 / 96 9 trigger_watch = 0 6 10 counter = 0 11 7 12 8 13 def last_rrd_count(concretepath) … … 19 24 end 20 25 21 22 26 watch :pin => 11, :trigger => :falling do 23 27 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 27 29 end 30 28 31 29 32 rrdpath = mypath + "/power.rrd" 30 33 counter = last_rrd_count(rrdpath) 31 PiPiper.wait 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
Note: See TracChangeset
for help on using the changeset viewer.