Class: RfBeam::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/rfbeam/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/rfbeam/cli.rb', line 13

def logger
  @logger
end

#radarObject

Returns the value of attribute radar.



13
14
15
# File 'lib/rfbeam/cli.rb', line 13

def radar
  @radar
end

Instance Method Details

#config(radar_id) ⇒ Object



31
32
33
34
# File 'lib/rfbeam/cli.rb', line 31

def config(radar_id)
  init_radar(radar_id)
  puts @radar.config
end

#ddat(radar_id) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rfbeam/cli.rb', line 53

def ddat(radar_id)
  init_radar radar_id

  if options[:stream]
    Thread.new { monitor_keypress }
    spinner = TTY::Spinner.new('[:spinner] :title ', format: :bouncing_ball)
    loop do
      break if @stop_streaming
      spinner.spin
      data = @radar.ddat
      spinner.update title: "Searching... #{data[:detection_str]}"
      @logger.success "#{@radar.tdat}" if data[:detection]
    end
    puts "\nTask Quit."
  else
    puts "\n#{@radar.ddat}"
  end
end

#listObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rfbeam/cli.rb', line 16

def list
  logger = TTY::Logger.new
  devices = RfBeam.connected
  logger.info 'No Radar modules found.' unless devices.count.positive?

  table = TTY::Table.new(header: %w[id Path Version])

  devices.each.with_index do |path, index|
    init_radar(index)
    table << ["#{index}", path, @radar.sw_version]
  end
  puts table.render(:ascii)
end

#pdat(radar_id) ⇒ Object



73
74
75
76
# File 'lib/rfbeam/cli.rb', line 73

def pdat(radar_id)
  init_radar radar_id
  puts @radar.pdat
end

#reset(radar_id) ⇒ Object



37
38
39
40
# File 'lib/rfbeam/cli.rb', line 37

def reset(radar_id)
  init_radar(radar_id)
  @logger.success 'Radar reset to factory defaults' if @radar.reset
end

#rfft(radar_id) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rfbeam/cli.rb', line 81

def rfft(radar_id)
  init_radar(radar_id)

  case
  when options[:stream]
    streamer = RfBeam::KLD7::Streamer.new(@radar)
    streamer.rfft
  when options[:raw]
    print @radar.rfft
  else
    plot = rfft_plot(@radar)
    p plot.render
  end
end

#set_param(radar_id, param, value) ⇒ Object



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

def set_param(radar_id, param, value)
  init_radar radar_id
  return @logger.warn("Invalid param: '#{param}'") unless RfBeam::KLD7::RADAR_PARAMETERS.include?(param.to_sym)

  @radar.send("#{param}=", value.to_i)
  @logger.success "Set #{@radar.formatted_parameter(param.to_sym)}"
end