68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
#! env/bin/python3
|
|
|
|
import RPi.GPIO as GPIO
|
|
import time
|
|
from datetime import datetime
|
|
|
|
def check_state(inputs):
|
|
|
|
# Define alias variables for input devices.
|
|
green_button = inputs['green_button']
|
|
yellow_button = inputs['yellow_button']
|
|
blue_button = inputs['blue_button']
|
|
|
|
# Define state variables for each of the output devices.
|
|
pump_state = inputs['pump']
|
|
lamp_state = inputs['lamp']
|
|
|
|
# Get mode and schedule information.
|
|
mode = inputs['mode']
|
|
hour = inputs['hour']
|
|
minute = inputs['minute']
|
|
|
|
# Determine state.
|
|
|
|
# Assume no change in state.
|
|
pump_out = pump_state
|
|
lamp_out = lamp_state
|
|
|
|
# Automatic mode.
|
|
if mode == "AUTO":
|
|
|
|
detect = False
|
|
|
|
if 6 < hour < 22:
|
|
lamp_out = True
|
|
pump_out = True
|
|
else:
|
|
lamp_out = False
|
|
pump_out = False
|
|
|
|
# Manual mode.
|
|
if mode == "MANUAL":
|
|
|
|
detect = False
|
|
|
|
# Pump Flip-Flop
|
|
if not detect and blue_button and pump_state:
|
|
pump_out = False
|
|
detect = True
|
|
if not detect and blue_button and not pump_state:
|
|
pump_out = True
|
|
detect = True
|
|
# Lamp Flip-Flop
|
|
if not detect and yellow_button and lamp_state:
|
|
lamp_out = False
|
|
detect = True
|
|
if not detect and yellow_button and not lamp_state:
|
|
lamp_out = True
|
|
detect = True
|
|
|
|
# Define alias variables for input devices.
|
|
outputs = {
|
|
'detect' : detect,
|
|
'pump' : pump_out,
|
|
'lamp' : lamp_out,
|
|
}
|
|
|
|
return outputs |