Sha256: 357c98fee1097c3627ae0181d608a8eb1130db96a482099a53fb43fbf3b74008
Contents?: true
Size: 631 Bytes
Versions: 1
Compression:
Stored size: 631 Bytes
Contents
require 'unobservable' module Frankenpins class Button include Unobservable::Support attr_event :pressed attr_event :released attr_event :changed def initialize(options) options[:pull] = :up unless options.has_key?(:pull) @pin = Frankenpins::Pin.new(options) @pin.watch do |pin| if pin.value == 0 raise_event :pressed elsif pin.value == 1 raise_event :released end # Always fire a changed event raise_event :changed end end def when(event_name, &block) send(event_name).register(&block) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
frankenpins-0.3.0 | lib/frankenpins/button.rb |