######################################## oscopeLJU3yy.py ##################################
# Example oscilloscope program that reads FIO0 and FIO1

# Note that because the graphics are slow, you won't be able to use a sample period less than 0.5 seconds.

import sys
mypath=sys.path[0]
if mypath.find('my_python') == -1:       #If true, then "my_python" could not be found
  print "Sorry.  You need to be in my_python for Halverson's program to work."
  print "(That''s because I am assuming that the oscopegraphlib.py and ezu3.py libraries are there.)"
  exit()
sys.path[0]=mypath[0:mypath.find('my_python')]+'my_python'

from oscopegraphlibyy import *
from accurate_sleep import *
import math
import u3
from ezu3 import *
from time import sleep

def get_Volts_data(LJU3):  
  Va=ain0(LJU3)
  Vb=ain1(LJU3)                     #You can change this too be any FIO input
  Volts_data=[Va,Vb]
  return Volts_data

LJU3 = u3.U3() # Opens the first LabJackU3 found on the USB
u3setup(LJU3,['ain','ain','din','din','ain','ain','ain','ain'])

print "Multi-channel oscilloscope"
my_sample_period = input("How many seconds between each measurement  (Can't be less than 0.5 s)? ")
data_length= input("How many samples per sweep? ")
sensor_data_list=get_Volts_data(LJU3)
number_of_sensors=len(sensor_data_list)
save_to_file=(raw_input("Do you want to save the data to a file? y/n: ")=="y")
print "Press button 2 to stop"
n_loops=0
while True:
  sensor_data_list=get_Volts_data(LJU3)
  elapsed_time=n_loops*my_sample_period
  print "Time=",elapsed_time," sec.  Sensor voltages= ",
  for i in range(0,number_of_sensors):
    print sensor_data_list[i],"  ",
  print  
  #def oscope(user_y_list,smallest_y=0.0,biggest_y=2.5,sample_period=0.1,samples_per_sweep=20,  \
  #         record_for_xgraph=False,use_seconds_since_midnight=False):
  oscope(sensor_data_list,0,5,my_sample_period,data_length,save_to_file,use_seconds_since_midnight=True)     
  accurate_sleep(my_sample_period)
  n_loops=n_loops+1
  if din2(LJU3):
    quit=raw_input("Do you want to quit (y/n)?  ")
    if quit == "y":
      break
print "That was fun.  Be nice to Dr. Halverson!"
