Exemple #1
0
def manual_move_loop():
    import RPi.GPIO as GPIO
    from time import sleep
    from GPIOUtility import curtain_is_closed, curtain_is_fully_open, motor_is_engaged
    from DBFunctions import  connect_to_DB, curtain_length, \
           current_position, set_current_position

    while True:
        cnx, cursor = connect_to_DB()

        if motor_is_engaged(
        ):  # motor is currently activated; wait before next check
            sleep(INTERVAL_BETWEEN_MANUAL_MOVEMENT_CHECKS)
            continue

        length = curtain_length(cursor)
        position = current_position(cursor)
        # if curtain open and position not marked at open end
        if curtain_is_fully_open() and length != position:
            DBFunctions.set_current_position(cnx, cursor, length)
        # if curtain closed and position not marked at closed end
        elif curtain_is_closed() and position:
            DBFunctions.set_current_position(cnx, cursor, 0)

        cnx.close()
        sleep(INTERVAL_BETWEEN_MANUAL_MOVEMENT_CHECKS)
def predictor_loop():
    from DBFunctions import connect_to_DB, event_predictor

    while True:
        cnx, cursor = connect_to_DB()

        if event_predictor(cursor):
            schedule_future_events()
            sleep(EVENT_PREDICTOR_SLEEP)

        cnx.close()
        sleep(EVENT_PREDICTOR_CHECK_SLEEP)
Exemple #3
0
def sunrise_loop():
	from DBFunctions import 	add_event, connect_to_DB, curtain_length, \
								event_set_at_approximate_time, sunrise_open

	while True:
		cnx, cursor = connect_to_DB()

		if sunrise_open(cursor):
			sunrise = sunrise_time()
			if is_null_sleep_then(sunrise): continue
			open_position = curtain_length(cursor)
			if not event_set_at_approximate_time(cursor, open_position, sunrise):
				add_event(cnx, cursor, open_position, sunrise)

		sleep(SUNRISE_LOOP_WAIT)

		cnx.close()
Exemple #4
0
def sunset_loop():
	from DBFunctions import 	add_event, connect_to_DB, \
								event_set_at_approximate_time, sunset_close

	while True:
		cnx, cursor = connect_to_DB()

		if sunset_close(cursor):
			sunset = sunset_time()
			if is_null_sleep_then(sunset): continue
			# check if sunset event already set
			if not event_set_at_approximate_time(cursor, 0, sunset):
				add_event(cnx, cursor, 0, sunset)

		sleep(SUNSET_LOOP_WAIT)

		cnx.close()