コード例 #1
0
	print "Initializing All Devices..."
	gc.initializeAllDevices(inputDevices+setableDevices,GPIO)

	#write the file headers
	gc.initFile(inputDevices+setableDevices,control)

	#variable that kills everything
	on = 1

	print "Starting the main control loop"
	while on:
		print ""
		print "-----------------------"
		print "--Starting Main Loop --"
		print "-----------------------"
		control.check(gc.getDateTime(0,0,0,1)) # needs the devices so it can recreate the headers for the file names
		print "Reading Status"
		gc.readStatus(inputDevices)
		print "Running deviceControl"
		gc.deviceControl(setableDevices,control, gc.getDateTime(0,0,1,0),GPIO) #time in is epoch
		print "Running writeStatus"
		gc.writeStatus(inputDevices+setableDevices,control.fileName, gc.getDateTime(1,1,0,0), gc.getDateTime(0,0,1,0))
		print "Going to sleep"
		sleep(control.recordInterval)
			
except KeyboardInterrupt:
	# allow the user to end program with CTRL+C
	gc.errorDisplay("User Initiated Quit")
except Exception as e:
	# If there are any errors, this should catch them
	gc.errorDisplay("Unhandeled Exception: " + str(sys.exc_info()[0]))
コード例 #2
0
ファイル: readConfig.py プロジェクト: denck007/growControl
def readConfig(GPIO):
# This will eventually be the function that reads in the configuration file and does all of the initial validation
# Until then, this function will have kind of random things happening in it
# This function will eventually only need to be passed the GPIO module and the config file name
	
	# Check the relay type, allows support for normally open and normally closed relays
	# The intention here is to make the device methods easier to understand
	# 		by not having things turn on when set to low
	
	print "Starting to parse the config file"
	
	import growControl as gc
	import ConfigParser
	
	curTimeEpoch = gc.getDateTime(0,0,1,0)
	currentTimeString = gc.getDateTime(0,0,0,1)
	
	def ConfigSectionMap(section):
		dict1 = {}
		options = Config.options(section)
		for option in options:
			try:
				dict1[option] = Config.get(section, option)
				if dict1[option] == -1:
					DebugPrint("skip: %s" % option)
			except:
				print("exception on %s!" % option)
				dict1[option] = None
		return dict1
    
	inputs = []
	outputs = []
	controls = -1
	
	Config = ConfigParser.ConfigParser()

	configFile = '/home/pi/git/growControl/growControl.config' 
	#configFile = 'C:\\Users\\Neil\\Documents\\GitHub\\growControl\\growControl.config'
	Config.read(configFile)

	print "Devices found in the config file:"
	sectionNames = Config.sections()
	print sectionNames

	for ii in range(len(sectionNames)):
		try:
			name = sectionNames[ii][:-3]
			number = int(sectionNames[ii][-3:])
		except:
			gc.errorDisplay("Error in reading in a section name from the config file")
			
#controls
		if name == "controls":
			print "Creating controls"
			maxTemp = int(ConfigSectionMap(sectionNames[ii])['max_temp'])
			minTemp = int(ConfigSectionMap(sectionNames[ii])['min_temp'])
			recordInterval =int(ConfigSectionMap(sectionNames[ii])['record_interval']) #how often to record, in seconds
			baseFileName = ConfigSectionMap(sectionNames[ii])['base_file_name'] #the file name to start with
			fileLength = int(ConfigSectionMap(sectionNames[ii])['file_length']) #number of lines to record in the file
			controls = gc.control.control(maxTemp,minTemp,recordInterval,fileLength,baseFileName, currentTimeString)
			
#temp sensor
		elif name == "temp":
			print "Creating " + sectionNames[ii]
			id = number
			pin = int(ConfigSectionMap(sectionNames[ii])['pin'])
			sensorType = ConfigSectionMap(sectionNames[ii])['sensor_type']
			libraryPath = ConfigSectionMap(sectionNames[ii])['library_path']
			inputs.append(gc.tempSensor.tempSensor(number, pin, sensorType, libraryPath))

#fan
		elif name == "fan":
			print "Creating " + sectionNames[ii]
			id = number
			pin = int(ConfigSectionMap(sectionNames[ii])['pin'])
			fanOnType= int(ConfigSectionMap(sectionNames[ii])['fan_on_type'])
			timeOn = int(ConfigSectionMap(sectionNames[ii])['time_on'])
			timeOff = int(ConfigSectionMap(sectionNames[ii])['time_off'])
			relayOn, relayOff = checkRelayType(GPIO, ConfigSectionMap(sectionNames[ii])['relay_type'])
			outputs.append(gc.fan.fan(number, pin, fanOnType, timeOn, timeOff, relayOn, relayOff))
			
#light
		elif name == "light":
			print "Creating " + sectionNames[ii]
			id = number
			pin = int(ConfigSectionMap(sectionNames[ii])['pin'])
			timeOn = int(ConfigSectionMap(sectionNames[ii])['time_on'])
			timeOff = int(ConfigSectionMap(sectionNames[ii])['time_off'])
			relayOn, relayOff = checkRelayType(GPIO, ConfigSectionMap(sectionNames[ii])['relay_type'])
			outputs.append(gc.light.light(number, pin, timeOn, timeOff, relayOn, relayOff))


	return [inputs, outputs, controls]