#!/usr/bin/env python # -*- coding: utf-8 -*- # You must initialize the gobject/dbus support for threading # before doing anything. import gobject import os import time import base64 from shutil import copyfile gobject.threads_init() from dbus import glib glib.init_threads() # Create a session bus. import dbus bus = dbus.SessionBus() import RPi.GPIO as GPIO import time import string out1 = 13 out2 = 11 out3 = 15 out4 = 12 GPIO.setmode(GPIO.BOARD) GPIO.setup(out1,GPIO.OUT) GPIO.setup(out2,GPIO.OUT) GPIO.setup(out3,GPIO.OUT) GPIO.setup(out4,GPIO.OUT) def cycle(x): total = 0 i = 0 while(total != x): if i==0: GPIO.output(out1,GPIO.HIGH) GPIO.output(out2,GPIO.LOW) GPIO.output(out3,GPIO.LOW) GPIO.output(out4,GPIO.LOW) time.sleep(0.03) #time.sleep(1) elif i==1: GPIO.output(out1,GPIO.HIGH) GPIO.output(out2,GPIO.HIGH) GPIO.output(out3,GPIO.LOW) GPIO.output(out4,GPIO.LOW) time.sleep(0.03) #time.sleep(1) elif i==2: GPIO.output(out1,GPIO.LOW) GPIO.output(out2,GPIO.HIGH) GPIO.output(out3,GPIO.LOW) GPIO.output(out4,GPIO.LOW) time.sleep(0.03) #time.sleep(1) elif i==3: GPIO.output(out1,GPIO.LOW) GPIO.output(out2,GPIO.HIGH) GPIO.output(out3,GPIO.HIGH) GPIO.output(out4,GPIO.LOW) time.sleep(0.03) #time.sleep(1) elif i==4: GPIO.output(out1,GPIO.LOW) GPIO.output(out2,GPIO.LOW) GPIO.output(out3,GPIO.HIGH) GPIO.output(out4,GPIO.LOW) time.sleep(0.03) #time.sleep(1) elif i==5: GPIO.output(out1,GPIO.LOW) GPIO.output(out2,GPIO.LOW) GPIO.output(out3,GPIO.HIGH) GPIO.output(out4,GPIO.HIGH) time.sleep(0.03) #time.sleep(1) elif i==6: GPIO.output(out1,GPIO.LOW) GPIO.output(out2,GPIO.LOW) GPIO.output(out3,GPIO.LOW) GPIO.output(out4,GPIO.HIGH) time.sleep(0.03) #time.sleep(1) elif i==7: GPIO.output(out1,GPIO.HIGH) GPIO.output(out2,GPIO.LOW) GPIO.output(out3,GPIO.LOW) GPIO.output(out4,GPIO.HIGH) time.sleep(0.03) #time.sleep(1) if i==7: i=0 continue i=i+1 total=total+1 print("total is: " + str(total)) def step_this_much(x): GPIO.output(out1,GPIO.LOW) GPIO.output(out2,GPIO.LOW) GPIO.output(out3,GPIO.LOW) GPIO.output(out4,GPIO.LOW) if(x < 0): print("Negative values not valid.") else: cycle(x) GPIO.output(out1,GPIO.LOW) GPIO.output(out2,GPIO.LOW) GPIO.output(out3,GPIO.LOW) GPIO.output(out4,GPIO.LOW) print("Begin program") keeprunning = True print("SELECT MODE") print(" NIGHT RUN DEBUG END ") while(keeprunning): selection = raw_input() if(selection == "DEBUG"): steps = str(raw_input("How many steps? :")) while (steps != "q"): step_this_much(int(steps)) steps = raw_input("How many steps? :") elif(selection in ["NIGHT RUN", "n", "N"]): print("") print( " -------- LETS SEE SOME AURORA -------") print("") exposure_time = float(raw_input("How long should camera exposure be? : ")) holder = raw_input("Open KStars. Once completed, press enter to continue.") holder = raw_input("Launch EKOS and connect Minicam. Once completed, press enter to continue.") print("Establishing connection to Camera.") time.sleep(1) # Create an object that will proxy for a particular remote object. remote_object = bus.get_object("org.kde.kstars", # Connection name "/KStars/INDI" # Object's path ) # Introspection returns an XML document containing information # about the methods supported by an interface. print ("Introspection data:\n") print remote_object.Introspect() # Get INDI interface iface = dbus.Interface(remote_object, 'org.kde.kstars.INDI') myDevices = [ "indi_qhy_ccd"] # Start INDI devices iface.start("7624", myDevices) print "Waiting for INDI devices..." # Create array for received devices devices = [] while True: devices = iface.getDevices() if (len(devices) < len(myDevices)): time.sleep(1) else: break; print "We received the following devices:" for device in devices: print device print "Establishing connection to CCD..." # Same thing for CCD Simulator iface.setSwitch("QHY CCD MINICAM5S-M-60e", "CONNECTION", "CONNECT", "On") iface.sendProperty("QHY CCD MINICAM5S-M-60e", "CONNECTION") # Wait until devices are connected while True: ccdState = iface.getPropertyState("QHY CCD MINICAM5S-M-60e", "CONNECTION") if (ccdState != "Ok"): print("Waiting... CCD state is " + str(ccdState)) time.sleep(1) else: break print "Connected to CCD is established." time_to_run = raw_input("How many minutes to run for: ") start_time = time.time() # remember when we started while ((time.time() - start_time) < (60*time_to_run)): # try: begin_spinning_lol = time.time() for i in range(0, 6): step_this_much(45) print ("Taking a " + str(exposure_time) + " second CCD exposure...") # Take 5 second exposure iface.setNumber("QHY CCD MINICAM5S-M-60e", "CCD_EXPOSURE", "CCD_EXPOSURE_VALUE", exposure_time) iface.sendProperty("QHY CCD MINICAM5S-M-60e", "CCD_EXPOSURE") # Wait until exposure is done ccdState = "Busy" while True: ccdState = iface.getPropertyState("QHY CCD MINICAM5S-M-60e", "CCD_EXPOSURE") if (ccdState != "Ok"): print("Waiting... CCD state is " + str(ccdState)) time.sleep(2) else: break fileinfo = iface.getBLOBFile("QHY CCD MINICAM5S-M-60e", "CCD1", "CCD1") print("Exposure " + str(i) + " complete.") print("We received file: ", fileinfo[0], " with format ", fileinfo[1], " and size ", fileinfo[2]) command = "fv " + fileinfo[0] os.system(command) time.sleep(1) stop_spinning_lol = time.time() time.sleep(60 - (stop_spinning_lol - begin_spinning_lol)) # print "Shutting down INDI server..." # Stop INDI server iface.stop("7624") elif(selection == "END"): keeprunning = False else: print("Try again.")