Class: HumbleRPiPluginButton
- Inherits:
-
Object
- Object
- HumbleRPiPluginButton
- Defined in:
- lib/humble_rpi-plugin-button.rb
Instance Method Summary collapse
-
#initialize(settings: {}, variables: {}, verbose: false) ⇒ HumbleRPiPluginButton
constructor
A new instance of HumbleRPiPluginButton.
- #start ⇒ Object (also: #on_start)
Constructor Details
#initialize(settings: {}, variables: {}, verbose: false) ⇒ HumbleRPiPluginButton
Returns a new instance of HumbleRPiPluginButton.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/humble_rpi-plugin-button.rb', line 12 def initialize(settings: {}, variables: {}, verbose: false) pins = settings[:pins] settings.delete :pins h1 = { capture_rate: 0.25, # seconds mode: :default }.merge settings h2 = {device_id: 'pi'}.merge variables h3 = { pull: :up, subtopic: 'button', descriptor: 'pressed', verbose: verbose } h = h1.merge(h2).merge(h3) @pins = pins.map.with_index do |x,i| params = {} if x.is_a? String or x.is_a? Integer then pin, params = x, h elsif x.is_a? Hash pin = x.keys.first.to_s params = h.merge(id: x.values.first.to_s) params.merge!({mode: x[:mode]}) if x[:mode] params.merge!({capture_rate: x[:capture_rate]}) if x[:capture_rate] end RPiPinInMsgOut.new pin, params.merge(index: i+1) end end |
Instance Method Details
#start ⇒ Object Also known as: on_start
55 56 57 58 59 60 61 |
# File 'lib/humble_rpi-plugin-button.rb', line 55 def start() puts 'ready to detect buttons' @pins.each {|pin| Thread.new { pin.capture} } end |