#!/usr/bin/env	python
#coding: utf8
# Copyright CERN, 2011
# Author: Ross Millar <ross.millar@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org

import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc_test_suite
import fmc_adc
import cp210x_gpio
#from pylab import *
#from ptsexcept import *
import fcntl, struct, termios, os
import time
import array


hw_en =0
sw_en =1
chan_for_thresh = 0x1  	# check that this is masked in the fmc class
int_thresh = 0x1000   	# 16 bit in twos comp
slope = 1		# 1 for positive, 0 for negative
delay = 0		# Trigger delay
edge_detect = 0		# Trig on Rising or falling edges, depends on slope

pre_trig_val =10
post_trig_val = 10

thresh_negative = 0
thresh_positive = 0
error=0

def main (default_directory='.'):
	
#	if (int_thresh & 0x8000) >> 15 ==0x1:
#		int_thresh = -0x10000 + int_thresh
#		thresh_negative = 1
#	else:
#		thresh_positive = 1
	
	
	# Object Declaration
	spec = rr.Gennum() # bind to the SPEC board
	fmc = fmc_adc.CFmcAdc100ks(spec)
	
	# Set trigger Register
	#fmc.set_trig_config(hw_en,sw_en,chan_for_thresh,int_thresh,slope,delay,edge_detect)
	
	# Do acq on the same channel as selected channel for thresh trig
	result =  fmc.do_acq( chan_for_thresh, "all_chans" ,"y",post_trig_val,pre_trig_val,0)
	print result
	
							
if __name__ == '__main__':
    main()        
    
