Class: RfBeam::KLD7::Streamer

Inherits:
Object
  • Object
show all
Defined in:
lib/rfbeam/kld7/streamer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(radar) ⇒ Streamer

Returns a new instance of Streamer.



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

def initialize(radar)
  @radar = radar
end

Instance Attribute Details

#radarObject

Returns the value of attribute radar.



11
12
13
# File 'lib/rfbeam/kld7/streamer.rb', line 11

def radar
  @radar
end

Instance Method Details

#monitor_keypressObject



17
18
19
20
21
22
23
24
25
# File 'lib/rfbeam/kld7/streamer.rb', line 17

def monitor_keypress
  loop do
    key = $stdin.getch
    if key.casecmp('q').zero?
      @stop_streaming = true
      break
    end
  end
end

#rfftObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rfbeam/kld7/streamer.rb', line 27

def rfft
  out = StringIO.new
  def out.tty?
    true
  end

  Thread.new { monitor_keypress }

  loop do
    out.truncate(0)

    plot = rfft_plot(@radar)
    plot.render(out)

    lines = out.string.lines
    lines.each { |line| $stdout.print "\r#{line}" }
    $stdout.print "\e[0J"
    $stdout.flush
    break if @stop_streaming

    n = lines.count
    $stdout.print "\e[#{n}F"
  end
end