lib/rfbeam/kld7/streamer.rb in rfbeam-0.5.1 vs lib/rfbeam/kld7/streamer.rb in rfbeam-0.5.8
- old
+ new
@@ -1,11 +1,12 @@
-# rubocop:disable all
-require "unicode_plot"
-require "io/console"
-require "stringio"
-require "tty-screen"
+# frozen_string_literal: true
+require 'io/console'
+require 'stringio'
+require 'tty-screen'
+require 'unicode_plot'
+
module RfBeam
module KLD7
class Streamer
attr_accessor :radar
@@ -13,12 +14,12 @@
@radar = radar
end
def monitor_keypress
loop do
- key = STDIN.getch
- if key.downcase == "q"
+ key = $stdin.getch
+ if key.casecmp('q').zero?
@stop_streaming = true
break
end
end
end
@@ -52,30 +53,30 @@
def plot_data(data)
{
x: Array(-128...128),
series1: data.shift(256).map { |value| value / 100 },
- series2: data.shift(256).map { |value| value.to_i / 100 }
+ series2: data.shift(256).map { |value| Integer(value, 10) / 100 }
}
end
def rfft_plot(radar)
width = TTY::Screen.width * 0.65
data = plot_data(radar.rfft)
plot =
UnicodePlot.lineplot(
data[:x],
data[:series1],
- name: "IF1/2 Averaged",
- title: "Raw FFT",
+ name: 'IF1/2 Averaged',
+ title: 'Raw FFT',
height: 25,
- width: width,
- xlabel: "Speed (km/h)",
- ylabel: "Signal (db)",
+ width:,
+ xlabel: 'Speed (km/h)',
+ ylabel: 'Signal (db)',
xlim: [-128, 128],
ylim: [0, 100]
)
- UnicodePlot.lineplot!(plot, data[:x], data[:series2], name: "Threshold")
+ UnicodePlot.lineplot!(plot, data[:x], data[:series2], name: 'Threshold')
plot
end
end
end
end