#!/usr/bin/env python
# ----------------------------------------------------------------
# Stand-alone mc4020 scope application
# ----------------------------------------------------------------
from gnuradio import gr
from gnuradio import mc4020
#from gnuradio import audio
from gnuradio.eng_option import eng_option
from gnuradio.wxgui import stdgui, scopesink,fftsink
from optparse import OptionParser
import wx

class app_flow_graph (stdgui.gui_flow_graph):
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv)

        # build our flow graph
        #input_rate = 1e6
        #input_rate = 44100 #1e6
	#src0 = audio.source (input_rate)
        input_rate = 674*1024*50 #35468950 #20e6
	#define BTTV_EXTEND_RAW_LINES 0x10000000 //use modified bttv driver which can set RAWLINES to the maximum of 674. (corresponding to 304 of the 312.5 lines)  The original bttv driver sets this hardcoded to 640 whatever you tell it to use.
	#define BTTV_DO_NOT_EMULATE_AC_COUPLING 0x01000000
	#define BTTV_NOGAP 0x00100000
        src = mc4020.source (input_rate, mc4020.BTTV_EXTEND_RAW_LINES |mc4020.BTTV_DO_NOT_EMULATE_AC_COUPLING |mc4020.BTTV_NOGAP)
        cvt = gr.short_to_float ()
        #block, fft_win = fftsink.make_fft_sink_c (self, panel, "Rx Data", 512, input_rate)

        #src0 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 25.1e3, 1e3)
        #src1 = gr.sig_source_f (input_rate, gr.GR_COS_WAVE, 25.1e3, 1e3)
          # compute FIR filter taps for audio filter
	decimation=100
	#show_rate=44100
	show_rate=input_rate/decimation
	#decimation=input_rate/show_rate
   	width_of_transition_band = show_rate / 4
    	lowpass_coeffs = \
         gr.firdes.low_pass (
         1.0,            # gain
         input_rate,      # sampling rate
         show_rate/2 - width_of_transition_band,
         width_of_transition_band,
         gr.firdes.WIN_HAMMING)

    	# input: float; output: float
    	dec_filter = \
      		gr.fir_filter_fff (decimation,
                         lowpass_coeffs)

        block, fft_win = scopesink.make_scope_sink_f (self, panel, "Secret Data", show_rate)
        #self.connect (src0, (block, 0))      
        self.connect (src, cvt)
    	self.connect (cvt, dec_filter) 
	self.connect (dec_filter, (block, 0))
        #self.connect (cvt, block)
	#self.connect (cvt, (block, 0))

        vbox.Add (fft_win, 1, wx.EXPAND)


def main ():
    app = stdgui.stdapp (app_flow_graph, "O'Scope Test App")
    app.MainLoop ()

if __name__ == '__main__':
    main ()

# ----------------------------------------------------------------

