Class: MacLight::Cli

Inherits:
Optix::Cli
  • Object
show all
Defined in:
lib/maclight/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject

desc “Blink keyboard LEDs” text “Blink keyboard LEDs (capslock, numlock)” text ” text “Examples:” text “ #File.basename($0) keyboard blink -r 3 -f 00 10:0.3 01:0.3” text “ #File.basename($0) keyboard blink -r 3 10:0.3 01:0.2 00:0.1 11:0.2 00:0.07 11:0.07 00:0.07” text ” text ‘Parameters:’ text ‘ <sequence> - Space-delimited sequence; CN:T CN:T ..’ text ‘ C = capslock value, N = numlock value, T = time in seconds’ opt :repeat, “Repetitions”, :default => 0 opt :fin, “Set this state after sequence has finished (CN)”, :type => String opt :verbose, “Print state of capslock, numlock” params “<sequence>” parent “keyboard” def blink(cmd, opts, argv)

raise Optix::HelpNeeded if argv.empty?
puts "#{MacLight.capslock ? 1:0} #{MacLight.numlock ? 1:0}" if opts[:verbose]
seq = argv.map {|e| ['1'==e[0],'1'==e[1],e[3..-1].to_f] }
(0..opts[:repeat]).each do |i|
  seq.each_with_index do |mode, step|
    MacLight.capslock(mode[0])
    MacLight.numlock(mode[1])
    puts "#{MacLight.capslock ? 1:0} #{MacLight.numlock ? 1:0}" if opts[:verbose]
    sleep mode[2]
  end
end
if opts[:fin]
  MacLight.capslock('1'==opts[:fin][0])
  MacLight.numlock('1'==opts[:fin][1])
  puts "#{MacLight.capslock ? 1:0} #{MacLight.numlock ? 1:0}" if opts[:verbose]
end

end



120
121
122
# File 'lib/maclight/cli.rb', line 120

def self.start
  Optix.invoke!
end

Instance Method Details

Raises:

  • (Optix::HelpNeeded)


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/maclight/cli.rb', line 65

def blink(cmd, opts, argv)
  raise Optix::HelpNeeded if argv.empty?
  seq = argv.map {|e| ['1'==e[0],e[2..-1].to_f] }
  (0..opts[:repeat]).each do |i|
    seq.each_with_index do |mode, step|
      MacLight.all_leds(mode[0])
      sleep mode[1]
    end
  end
  if opts[:fin]
    MacLight.all_leds('1'==opts[:fin][0])
  end
end

#set(cmd, opts, argv) ⇒ Object

Raises:

  • (Optix::HelpNeeded)


43
44
45
46
47
48
49
# File 'lib/maclight/cli.rb', line 43

def set(cmd, opts, argv)
  raise Optix::HelpNeeded unless opts.values_at(:all).any?
  MacLight.all_leds(1 == opts[:all])
  #MacLight.capslock(1 == opts[:capslock]) unless opts[:capslock].nil?
  #MacLight.numlock(1 == opts[:numlock]) unless opts[:numlock].nil?
  #puts "#{MacLight.capslock ? 1:0} #{MacLight.numlock ? 1:0}" if opts[:verbose]
end

#test(cmd, opts, argv) ⇒ Object



82
83
84
# File 'lib/maclight/cli.rb', line 82

def test(cmd, opts, argv)
  blink(nil, { :repeat => 3 }, %w(1:0.3 0:0.2 0:0.1 1:0.2 0:0.07 1:0.07 0:0.07))
end