A program to read a Phidget IR sensor and log pull-ups with Fitbit's API
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

try to detect twitchy sensor data and ignore 2 pullups in 1 second

+7 -1
+7 -1
lib/sensor/phidget.rb
··· 14 14 @parent = parent 15 15 @state = :idle 16 16 @last_state_change = Time.now 17 + @last_pullup = nil 17 18 @cur_time = nil 18 19 end 19 20 ··· 83 84 @parent.vputs "state is now #{state} (#{self.cur_value})" 84 85 85 86 if state == :pulled_up 86 - @parent.log_pullup!(@cur_time) 87 + if @last_pullup && (@cur_time.to_f - @last_pullup.to_f < 1.0) 88 + @parent.vputs "ignoring bad sensor data (duplicate pull-up)" 89 + else 90 + @parent.log_pullup!(@cur_time) 91 + @last_pullup = @cur_time 92 + end 87 93 end 88 94 end 89 95 end