Class: Ev3dev::Sound

Inherits:
Device show all
Defined in:
lib/ev3dev/sound.rb

Constant Summary collapse

PATH =
"/sys/devices/platform"

Instance Attribute Summary

Attributes inherited from Device

#device_path

Instance Method Summary collapse

Methods inherited from Device

#method_missing

Constructor Details

#initializeSound

Returns a new instance of Sound.



5
6
7
8
9
10
11
12
13
# File 'lib/ev3dev/sound.rb', line 5

def initialize()
  Dir.glob("#{PATH}/*").each do |path|
    if File.exist?("#{path}/tone")
      super path
      return
    end
  end
  raise "couldn't find sound attributes"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ev3dev::Device

Instance Method Details

#aplay(*args) ⇒ Object



31
32
33
# File 'lib/ev3dev/sound.rb', line 31

def aplay(*args)
   `aplay #{args.first}`
end

#beep(*args) ⇒ Object



27
28
29
# File 'lib/ev3dev/sound.rb', line 27

def beep(*args)
  `beep #{args.first}`
end

#espeak(arg) ⇒ Object



35
36
37
# File 'lib/ev3dev/sound.rb', line 35

def espeak(arg)
  `espeak #{arg} --stdout | aplay`
end

#mpg123(*args) ⇒ Object



39
40
41
# File 'lib/ev3dev/sound.rb', line 39

def mpg123(*args)
  `mpg123 #{args.first}`
end

#tone(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ev3dev/sound.rb', line 15

def tone(*args)
  raise "couldn't find sound attributes" if @device_path.nil?
  param = File.join @device_path, "tone"
  raise "no such attribute: #{param}" unless File.exist? param
  if args.first.nil?
    IO.read(param).strip
  else
    IO.write param, args.join(" ")
    self
  end
end