Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from views import *

import subprocess

class FreqShowController(object):
"""Class which controls the views shown in the application and mediates
changing between views.
"""
rtl_fm_process = None
aplay_process = None
demodulating = False
prev_center_freq = 90.3

def __init__(self, model):
"""Initialize controller with specified FreqShow model."""
self.model = model
Expand All @@ -42,7 +47,32 @@ def __init__(self, model):
self._current_view = None
self.change_to_instant()

def change_view(self, view):
def demodulate(self, *args):
#kill the previous sub process
if self.rtl_fm_process is not None:
self.rtl_fm_process.terminate()

if self.aplay_process is not None:
self.aplay_process.terminate()

if not self.demodulating:
self.model.close_sdr()
self.prev_center_freq = self.model.get_center_freq()
freq = self.prev_center_freq * 1000000.0
self.rtl_fm_process = subprocess.Popen(["rtl_fm", "-M", "fm", "-s", "200000", "-r", "48000", "-f", str(freq) ], stdout=subprocess.PIPE)
self.aplay_process = subprocess.Popen(["aplay", "-r", "48000", "-f", "S16_LE"], stdin=self.rtl_fm_process.stdout)
self.demodulating = True
else:
#reopen sdr for system
self.model.open_sdr()
self.model.set_center_freq(self.prev_center_freq)
self.demodulating = False

def change_view(self, view):
#if currently demodulating stop
if self.demodulating:
self.demodulate()

"""Change to specified view."""
self._prev_view = self._current_view
self._current_view = view
Expand Down
2 changes: 1 addition & 1 deletion freqshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@
fscontroller.current().click(pygame.mouse.get_pos())
# Update and render the current view.
fscontroller.current().render(screen)
pygame.display.update()
pygame.display.update()
12 changes: 10 additions & 2 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from rtlsdr import *

import freqshow

import time

class FreqShowModel(object):
def __init__(self, width, height):
Expand All @@ -47,6 +47,14 @@ def __init__(self, width, height):
self.set_sample_rate(2.4)
self.set_gain('AUTO')

def close_sdr(self):
self.sdr.close()

def open_sdr(self):
self.sdr.close()
time.sleep(1)
self.sdr.open()

def _clear_intensity(self):
if self.min_auto_scale:
self.min_intensity = None
Expand All @@ -59,7 +67,7 @@ def get_center_freq(self):
return self.sdr.get_center_freq()/1000000.0

def set_center_freq(self, freq_mhz):
"""Set tuner center frequency to provided megahertz value."""
"""Set tuner center frequency to provided megahertz value."""
try:
self.sdr.set_center_freq(freq_mhz*1000000.0)
self._clear_intensity()
Expand Down
4 changes: 3 additions & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ def __init__(self, model, controller):
self.buttons.add(0, 2, gain_text, colspan=4, click=self.gain_click)
self.buttons.add(0, 3, min_text, colspan=2, click=self.min_click)
self.buttons.add(2, 3, max_text, colspan=2, click=self.max_click)
self.buttons.add(0, 4, 'BACK', click=self.controller.change_to_main)
self.buttons.add(0, 4, 'Demodulation', colspan=2, click=self.controller.demodulate)
self.buttons.add(2, 4, 'BACK', colspan=2, click=self.controller.change_to_main)

def render(self, screen):
# Clear view and render buttons.
Expand Down Expand Up @@ -339,6 +340,7 @@ def __init__(self, model, controller):
self.buttons.add(3, 0, 'QUIT', click=self.quit_click,
bg_color=freqshow.CANCEL_BG)
self.overlay_enabled = True
model.open_sdr()

def render_spectrogram(self, screen):
"""Subclass should implement spectorgram rendering in the provided
Expand Down