def dispense(): response.headers['Content-Type'] = 'application/json' response.headers['Cache-Control'] = 'no-cache' nuts_dispenser = dispenser.Dispenser() nuts_dispenser.enable_engine() nuts_dispenser.dispense_food() nuts_dispenser.disable_engine() return json.dumps({'status': 'OK'})
def do_steps(steps): """ TODO: Break this out into another module return success/failure """ # TODO: use abstraction of the Platform # to fetch Platform-specific components he_inst = heating_element.HeatingElement() stir_inst = stirrer.Stirrer() ts_inst = thermal_sensor.ThermalSensor() for step in steps: step_ing, action, wait_param, wait_val = step[MMK.KEY_STEP_ING], step[MMK.KEY_ACTION], \ step[MMK.KEY_WAIT_PARAM], step[MMK.KEY_WAIT_VALUE] logging.info("Step Action: {}".format(action)) if action == "dispense": for ing in step_ing: disp_id = ing_prop[ing][MMK.KEY_DISPENSER] disp = dispenser.Dispenser(disp_id) disp.dispense() logging.info('Dispensed {} from Dispenser {}'.format( ing, disp_id)) logging.info('Wait {} for {}: start'.format(wait_val, wait_param)) time.sleep(wait_val) logging.info('Wait {} for {}: stop'.format(wait_val, wait_param)) elif action == "heat": curr_temp = ts_inst.get_temp() logging.info("Current Temperature: {}".format(curr_temp)) logging.info('Wait {} for {}: start'.format(wait_val, wait_param)) if curr_temp < wait_val: he_inst.heat_on() while curr_temp < wait_val: # TODO exit strategy time.sleep(3) # curr_temp = ts_inst.get_temp() curr_temp = ts_inst.get_test_temp_high() else: he_inst.heat_off() while curr_temp > wait_val: # TODO exit strategy time.sleep(3) # curr_temp = ts_inst.get_temp() curr_temp = ts_inst.get_test_temp_low() logging.info("Current Temperature: {}".format(curr_temp)) return None
logfile.write(f"{timestamp}: Device started\n") sh = ft.Snapshot() logfile = open("testing/abenalog.txt", "a+") timestamp = dt.datetime.now() logfile.write(f"{timestamp}: Device started\n") if not largeScreen: subprocess.run(["xinput", "map-to-output", "8", "DSI-1"]) #else: # subprocess.run(["xinput", "map-to-output", "8", "HDMI-1"]) if isOnline and not checkInternet(): isOnline = False # Initialize dispenser disp = dispenser.Dispenser() disp.init_GPIO() # Initialize LEDs leds = LEDs.LEDinit() disp.gelUpdate() pygame.time.set_timer(BLINKEVENT, 10000, True) monsterblinks = [monsterblinkL, monsterblinkM, monsterblinkR] # Initialize interaction variables flow = threading.Thread(target=interaction) threadevent = threading.Event() #Used to terminate interaction thread trackID = 0 #ID of closest person altTrackID = 0 #ID of other random person gazeAtClosest = True pygame.time.set_timer(GAZEEVENT, 8000, True) #Start gaze event videoKeys = [] #IDs of people present at last video showing
import dispenser #dispenser.py import stattracker #stattracker.py import keyboard import csv import pygame pygame.init() if __name__ == '__main__': window = pygame.display.set_mode((800, 480), pygame.DOUBLEBUF) screen = pygame.display.get_surface() # Initialize dispenser dispenser = dispenser.Dispenser() dispenser.init_GPIO() # Initialize stats variables stats = stattracker.StatTracker() running = True while running: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: running = False print("Terminating program") if event.key == pygame.K_p: plot_data, plot_size = stats.get_plot() plot = pygame.image.fromstring(plot_data, plot_size, "RGB")