Exemplo n.º 1
0
class Pin:
    def __init__(self, pin: int, direction: PinDirection, init=-1):
        self._pin = pin
        self._pulse_width = None
        self._direction = direction
        self._out = False
        self._underlying = None

        if init == -1:
            init = None

        if direction == PinDirection.IN:
            self._underlying = Button(pin=pin,
                                      pull_up=None,
                                      active_state=True,
                                      hold_time=0.25)
        elif direction == PinDirection.OUT:
            self._underlying = LED(pin=pin,
                                   active_high=True,
                                   initial_value=init)
        elif direction == PinDirection.IN_PULL_LOW:
            self._underlying = Button(pin=pin, pull_up=False)
        elif direction == PinDirection.IN_PULL_UP:
            self._underlying = Button(pin=pin, pull_up=True)
        else:
            raise Exception("Pin richtung ist falsch")

    def turnOn(self):
        self._underlying.on()
        logging.getLogger("Launch").getChild("Tools.Pin").debug(
            "turnON({})".format(self._pin))

    def turnOff(self):
        logging.getLogger("Launch").getChild("Tools.Pin").debug(
            "turnOff({})".format(self._pin))
        self._underlying.off()

    def toggle(self):
        logging.getLogger("Launch").getChild("Tools.Pin").debug(
            "Pin {} ist jetzt {} und wird {}".format(self._pin, self.input(),
                                                     not self.input()))
        self._underlying.toggle()

    def set_pulse_width(self, delay):
        self._pulse_width = delay

    def pulse(self, delay_ms=250):
        logging.getLogger("Launch").getChild("Tools.Pin").debug(
            "pulse({}, {}ms)".format(self._pin, delay_ms))
        self._underlying.blink(on_time=delay_ms / 1000,
                               off_time=delay_ms / 1000,
                               n=1,
                               background=False)

    def input(self) -> bool:
        if self._direction == PinDirection.OUT:
            return self._underlying.value
        return self._underlying.value

    def output(self, val: bool):
        self._out = val
        if self._direction == PinDirection.OUT:
            self._underlying.value = val

    def get_direction(self):
        return self._direction

    def set_detect(self, callback, level: PinEventEdge):
        if level == PinEventEdge.RISING:
            self._underlying.when_pressed = callback
        elif level == PinEventEdge.FALLING:
            self._underlying.when_released = callback
        elif level == PinEventEdge.BOTH:
            self._underlying.when_released = callback
            self._underlying.when_pressed = callback
Exemplo n.º 2
0
def temp_setting_state(): #edited
	next_state = "temp_setting_state"
	time.sleep(0.5)
	global start_temp, remote_input, remote_control, user_selection, start_time_met
	if not (remote_control == "yes" and remote_input != "NULL"):
		ON_OFF = Button(4) # pin 7
		PROGRAM_R = Button(27) # pin 13
		MANUAL_R = Button(18) # pin 12
		PROBE_R = Button(24) # pin 18
		UP_R = Button(5) # pin 29
		DOWN_R = Button(13) # pin 33
		ENTER_R = Button(16) # pin 36
		# start the start timer
		start_timer = threading.Timer(20.0, startMet)
		start_timer.start()
		print("TEMP SETTING STATE")
		while next_state == "temp_setting_state":
			#control the next state
			if ON_OFF.is_pressed:
				next_state = "on_off_state"
			elif ENTER_R.is_pressed or start_time_met == 1:
				next_state = "display_state"
			elif MANUAL_R.is_pressed:
				user_selection = "manual"
				next_state = "heat_setting_state"
			elif PROGRAM_R.is_pressed:
				user_selection = "program"
				next_state = "cook_time_state"
			elif PROBE_R.is_pressed: ######################### TAKE NOTES HERE, NOT SURE IF THIS IS WHAT HAPPENS #############################
				start_temp = 160
			elif UP_R.is_pressed:
				if start_temp < 180:
					start_temp = start_temp + 5
				time.sleep(0.25)
			elif DOWN_R.is_pressed:
				if start_temp > 140:
					start_temp = start_temp - 5
				time.sleep(0.25)
			else:
				next_state = "temp_setting_state"
			
	else:
		UP_R = LED(5) # pin 29
		UP_W = LED(6) # pin 31
		DOWN_R = LED(13) # pin 33
		DOWN_W = LED(19) # pin 35
		ENTER_R = LED(16) # pin 36
		ENTER_W = LED(20) # pin 38
		#control the outputs of this state
		# takes up, down, enter, manual, program
		if remote_input != "NULL": 
			UP_R.on()
			DOWN_R.on()
			ENTER_R.on()
			while start_temp < in_temp["temperature"]:
				UP_W.on()
				pause(0.25)
				UP_W.off()
				start_temp = start_temp + 5
					
			while start_temp > in_temp["temperature"]:
				DOWN_W.on()
				pause(0.25)
				DOWN_W.off()
				start_temp = start_temp - 5
				
			# got to next state
				ENTER_W.on()
				pause(0.25)
				ENTER_W.off()
				next_state = "display_state"

	print(start_temp)
	start_timer.cancel()
	start_time_met = 0
	return (next_state)
Exemplo n.º 3
0
def heat_setting_state(): #edited
	next_state = "heat_setting_state"
	time.sleep(0.5)
	global user_selection, heat_selection, remote_control, remote_input, inactivity_time_met, start_time_met
	if not (remote_control == "yes" and remote_input != "NULL"):
		ON_OFF = Button(4) # pin 7
		PROGRAM_R = Button(27) # pin 13
		MANUAL_R = Button(18) # pin 12
		PROBE_R = Button(24) # pin 18
		UP_R = Button(5) # pin 29
		DOWN_R = Button(13) # pin 33
		ENTER_R = Button(16) # pin 36
		# start inactivity timer
		inact_timer = threading.Timer(30.0, inactivityMet)
		inact_timer.start()
		# start the start timer
		start_timer = threading.Timer(20.0, startMet)
		start_timer.start()
		print("HEAT SETTING STATE")
		while next_state == "heat_setting_state":
			#control the next state
			if ON_OFF.is_pressed:
				next_state = "on_off_state"
			elif inactivity_time_met == 1 and user_selection == "probe":
				next_state = "sel_state"
			elif start_time_met == 1 and user_selection != "probe":
				next_state = "display_state"
			elif ENTER_R.is_pressed:
				if user_selection != "probe":
					next_state = "display_state"
				elif heat_selection == "warm":
					next_state = "display_state"
				else:
					next_state = "temp_setting_state"
			elif PROGRAM_R.is_pressed:
				user_selection = "program"
				next_state = "cook_time_state"
			else:
				next_state = "heat_setting_state"
	
			#control the outputs of this state
			# takes up, down, enter, manual, probe, program
			if MANUAL_R.is_pressed:
				user_selection = "manual"
				heat_selection = "high"
			if PROBE_R.is_pressed:
				user_selection = "probe"
				heat_selection = "high"
			if UP_R.is_pressed:
			# change heat_selection
				if heat_selection == "high":
					heat_selection = "low"
				elif heat_selection == "low":
					heat_selection = "warm"
				else:
					heat_selection = "high"
				time.sleep(0.25)
			if DOWN_R.is_pressed:
			# change heat_selection
				if heat_selection == "high":
					heat_selection = "low"
				elif heat_selection == "low":
					heat_selection = "warm"
				else:
					heat_selection = "high"
				time.sleep(0.25)
		
	else:
		UP_R = LED(5) # pin 29
		UP_W = LED(6) # pin 31	
		DOWN_R = LED(13) # pin 33
		DOWN_W = LED(19) # pin 35
		ENTER_R = LED(16) # pin 36
		ENTER_W = LED(20) # pin 38
		if remote_control == "yes" and remote_input != "NULL":
			UP_R.on()
			DOWN_R.on()
			ENTER_R.on()
			# change heat_selection
			if in_temp["type"] == "probe":
				heat_selection = "high"
			else:
				heat_selection = in_temp["temperature"]
				if heat_selection == "low":
					UP_W.on()
					pause(0.25)
					UP_W.off()
					pause(0.75)
				elif heat_selection == "warm":
					UP_W.on()
					pause(0.25)
					UP_W.off()
					pause(0.50)
					UP_W.on()
					pause(0.25)
					UP_W.off()
					pause(0.75)
					
			# go to next state
				ENTER_W.on()
				pause(0.25)
				ENTER_W.off()
				if user_selection != "probe":
					next_state = "display_state"
				elif heat_selection == "warm":
					next_state = "display_state"
				else:
					next_state = "temp_setting_state"

	print(heat_selection)
	inact_timer.cancel()
	inactivity_time_met = 0
	start_timer.cancel()
	start_time_met = 0
	return (next_state)
Exemplo n.º 4
0
def cook_time_state(): #edited
	next_state = "cook_time_state"
	time.sleep(0.5)
	global start_time, remote_control, remote_input, user_selection, inactivity_time_met
	if not (remote_control == "yes" and remote_input != "NULL"):
		ON_OFF = Button(4) # pin 7
		MANUAL_R = Button(18) # pin 12
		PROBE_R = Button(24) # pin 18
		UP_R = Button(5) # pin 29
		DOWN_R = Button(13) # pin 33
		ENTER_R = Button(16) # pin 36
		# start inactivity timer
		inact_timer = threading.Timer(30.0, inactivityMet)
		inact_timer.start()
		start_time = 7
		print("COOK TIME STATE")
		while next_state == "cook_time_state":
			#control the next state
			if ON_OFF.is_pressed:
				next_state = "on_off_state"
			elif inactivity_time_met == 1:
				next_state = "sel_state"
			elif ENTER_R.is_pressed:
				next_state = "heat_setting_state"
			elif MANUAL_R.is_pressed:
				user_selection = "manual"
				next_state = "heat_setting_state"
			elif PROBE_R.is_pressed:
				user_selection = "probe"
				next_state = "heat_setting_state"
			elif UP_R.is_pressed:
				if start_time < 23:
					start_time = start_time + 1
				time.sleep(0.20)
			elif DOWN_R.is_pressed:
				if start_time > 0:
					start_time = start_time - 1
				time.sleep(0.20)
			else:
				next_state = "cook_time_state"
			
		# remote control: set time
	else:
		UP_R = LED(5) # pin 29
		UP_W = LED(6) # pin 31
		DOWN_R = LED(13) # pin 33
		DOWN_W = LED(19) # pin 35
		ENTER_R = LED(16) # pin 36
		ENTER_W = LED(20) # pin 38
		if remote_input != "NULL":
			UP_R.on()
			DOWN_R.on()
			ENTER_R.on()
			# get the hour and minute selection as integers
			[hour, min] = in_cook_time["length"].split(":")
			hour = int(hour)
			min = int(min)
			# get the hour and minute current option as integers
			[opt_hour, opt_min] = cook_time_options[start_time].split(":")
			opt_hour = int(opt_hour)
			opt_min = int(opt_min)
			while hour > opt_hour:
				UP_W.on()
				pause(0.25)
				UP_W.off()
				start_time = start_time + 2
				# update current hour and minute option
				[opt_hour, opt_min] = cook_time_options[start_time].split(":")
				opt_hour = int(opt_hour)
				opt_min = int(opt_min)
				pause(0.75)
			
			if min == 30:
				start_time = start_time + 1
				# update current hour and minute option
				[opt_hour, opt_min] = cook_time_options[start_time].split(":")
				opt_hour = int(opt_hour)
				opt_min = int(opt_min)
					
			while hour < opt_hour:
				DOWN_W.on()
				pause(0.25)
				DOWN_W.off()
				start_time = start_time - 2
				# update current hour and minute option
				[opt_hour, opt_min] = cook_time_options[start_time].split(":")
				opt_hour = int(opt_hour)
				opt_min = int(opt_min)
				pause(0.75)
					
			# go to the next state
				ENTER_W.on()
				pause(0.25)
				ENTER_W.off()
				next_state = "heat_setting_state"

	print(cook_time_options[start_time])
	inact_timer.cancel()
	inactivity_time_met = 0
	return (next_state)
Exemplo n.º 5
0
def sel_state(): #edited
	next_state = "sel_state"
	time.sleep(0.5)
	global user_selection, remote_control, remote_input, inactivity_time_met
	if not (remote_control == "yes" and remote_input != "NULL"):
		ON_OFF = Button(4) # pin 7
		PROGRAM_R = Button(27) # pin 13
		MANUAL_R = Button(18) # pin 12
		PROBE_R = Button(24) # pin 18
		# start inactivity timer
		inact_timer = threading.Timer(30.0, inactivityMet)
		inact_timer.start()
		print("SELECT STATE")
		while next_state == "sel_state":
			#control the next state
			if ON_OFF.is_pressed or inactivity_time_met == 1:
				next_state = "on_off_state"
			elif PROGRAM_R.is_pressed:
				user_selection = "program"
				next_state = "cook_time_state"
			elif PROBE_R.is_pressed:
				user_selection = "probe"
				next_state = "heat_setting_state"
			elif MANUAL_R.is_pressed:
				user_selection = "manual"
				next_state = "heat_setting_state"
			else:
				next_state = "sel_state"
			
	else:
		#control the outputs of this state
		# takes probe, manual, program
		PROGRAM_R = LED(27) # pin 13
		PROGRAM_W = LED(22) # pin 15
		MANUAL_R = LED(18) # pin 12
		MANUAL_W = LED(23) # pin 16
		PROBE_R = LED(24) # pin 18
		PROBE_W = LED(25) # pin 22
		if remote_input != "NULL":
			if in_temp["type"] == "probe":
				PROBE_R.on()
				PROBE_W.on()
				pause(0.25)
				PROBE_W.off()
				user_selection = "probe"
				next_state = "heat_setting_state"
			elif in_temp["type"] == "program":
				PROGRAM_R.on()
				PROGRAM_W.on()
				pause(0.25)
				PROGRAM_W.off()
				user_selection = "program"
				next_state = "cook_time_state"
			elif in_temp["type"] == "manual":
				MANUAL_R.on()
				MANUAL_W.on()
				pause(0.25)
				MANUAL_W.off()
				user_selection = "manual"
				next_state = "heat_setting_state"

	print(user_selection)
	inact_timer.cancel()
	inactivity_time_met = 0
	return (next_state)
Exemplo n.º 6
0
import RPi.GPIO as GPIO
import time
from gpiozero import LED, Button
led1 = Button(21)
for i in range(200):
    print("a")
    led1.on()
    time.sleep(.20)
    print("b")
    led1.off()
    time.sleep(.20)