jwhitehorn / pi_piper

Event driven Raspberry Pi GPIO programming in Ruby
BSD 2-Clause "Simplified" License
694 stars 71 forks source link

Event every x number of time? #22

Open ghost opened 10 years ago

ghost commented 10 years ago

Would it be possible to add a feature so we can enter an event loop and beforehand setup functions that would run every x milliseconds? This way we can concurrently check for different sensors. I know I could do this with event machine but it seems that would defeat the purpose of this library if its supposed to be event driven.

bguest commented 10 years ago

You don't need event machine to do this, ruby threads work just fine.

checker_thread = Thread.new do
  loop do
      check_your_sensors
      sleep 1       # or however many seconds you want to sleep
   end
end

Now that you have a reference to that thread, you can join or kill it as you please.

jwhitehorn commented 10 years ago

I like the idea! It's something I've thought about before.

Unfortunately, work and personal life have me swamped lately. So I doubt I'll be able to get to this in short order. Though, I'd never say "no" to a pull request :smile: