Class: Pedalboard::Components::Pedal

Inherits:
BaseComponent show all
Defined in:
lib/pedalboard/components/pedal.rb

Constant Summary collapse

LONG_TIME =
0.4

Instance Attribute Summary collapse

Attributes inherited from BaseComponent

#pedalboard, #pin

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Pedal

Returns a new instance of Pedal.



12
13
14
15
16
17
18
19
# File 'lib/pedalboard/components/pedal.rb', line 12

def initialize opts={}
  super opts

  @press = opts.fetch(:press) { ->{} }
  @long_press = opts.fetch(:long_press) { ->{} }

  configure_dino_component
end

Instance Attribute Details

#long_pressObject (readonly)

Returns the value of attribute long_press.



10
11
12
# File 'lib/pedalboard/components/pedal.rb', line 10

def long_press
  @long_press
end

#pressObject (readonly)

Returns the value of attribute press.



10
11
12
# File 'lib/pedalboard/components/pedal.rb', line 10

def press
  @press
end

Instance Method Details

#configure_dino_componentObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pedalboard/components/pedal.rb', line 21

def configure_dino_component
  dino_component.down do
    begin
      @start_time = Time.now
    rescue Exception => e
      puts e.message
    end
  end

  dino_component.up do
    begin
      interval = Time.now - @start_time
      if interval > LONG_TIME
        run_command long_press
      else
        run_command press
      end
    rescue Exception => e
      puts e.message
    end
  end
end