def checkarguments(): global lval if len(sys.argv) != 2: return if sys.argv[1] == "debug": run_test() time.sleep(2) sensors.stop() webserver.stop() log.info("main", "exit (debug)") GPIO.cleanup() exit() if sys.argv[1] == "fakeval": analyze( "$1;1;;10,1;20,2;30,3;40,4;50,5;60,6;70,7;80,8;90,9;10,1;11,2;12,3;13,4;14,5;15,6;16,7" ) lval = list(values) lval[0] = "8.8" lval[1] = "22.5" once_a_hour() once_a_day(0) analyze( "$1;1;;10,1;20,2;30,3;40,4;50,5;60,6;70,7;80,8;90,9;10,1;11,2;12,3;13,4;14,5;15,6;16,7" ) return
def main(): try: run_control_sequence(setpoint_record_sequence, control_loop_interval, 'thermal_lysis', preflight_record=preflight_record, postflight_record=postflight_record) except KeyboardInterrupt: print('Quitting early...') gpio.cleanup()
def unlock(locker): print('unlocked ' + str(locker)) # pin = locker_to_gpio[locker] pin = str(locker) gpio.setup(pin, gpio.OUT) gpio.output(pin, 1) time.sleep(1) gpio.output(pin, 0) time.sleep(1) gpio.cleanup(pin) return 0
def poll_sensor_loop(): while poll_sensors: try: if (config.getboolean('application_status', 'MAT')): run_probe(probe) socketio.emit('sensor_update', { 'sensors': get_sensors_object(), 'appliances': get_appliances_object() }, namespace='/live') eventlet.sleep(1) if (config.getboolean('application_status', 'LIGHT')): run_dht_temp(dht1_temp) socketio.emit('sensor_update', { 'sensors': get_sensors_object(), 'appliances': get_appliances_object() }, namespace='/live') eventlet.sleep(1) if (config.getboolean('application_status', 'FOGGER')): run_dht_humidity(dht2_humidity) socketio.emit('sensor_update', { 'sensors': get_sensors_object(), 'appliances': get_appliances_object() }, namespace='/live') eventlet.sleep(1) except (KeyboardInterrupt, SystemExit) as exit: # if we catch stop signal here instead of in the parent process print("Stopping background process...") gpio.cleanup() display.off() print("Stopping server") socketio.stop() return False except Exception as error: send_alert( "Exception occurred", "Uncaught exception occurred. Stack trace to follow (hopefully)" ) send_alert("Exception:", str(error)) pass gpio.cleanup() display.off()
def get_image(self, angle_idx): if self.is_test: self.angles_imgs_counter[angle_idx] += 1 img = self.angles_imgs_lst[angle_idx][ self.angles_imgs_counter[angle_idx]] # img = cv2.resize(img,(RESIZE_SIZE,RESIZE_SIZE)) if (IS_PI): self.socket.send_image(img) # asynchronus send, w/ timeout gui_img_manager.add_img(img) return img else: if (IS_PI): gpio.setmode(gpio.BOARD) gpio.setup(btn, gpio.IN, pull_up_down=gpio.PUD_DOWN) should_enter = True try: print("plz press me honz") while True: if (gpio.input(btn) == 1): should_enter = True elif (should_enter): img = self.one_still() #img = cv2.resize(img,(RESIZE_SIZE,RESIZE_SIZE)) self.socket.send_image(img) should_enter = False gpio.cleanup() return img except KeyboardInterrupt: print('cam err!') else: # gui img = self.socket.get_image() gui_img_manager.add_img(img) return img
def exit_program(game: Game, shutdown: bool = True) -> None: """ :param game: Game :param shutdown: bool, Exit program and shutdown the raspberry pi as well """ LOG.info("Exit program") button_panel.update_buttons([]) # turn off btn led # Save if necessary try: game.board.peek() if not game.engine.ping(): game.engine.close() game.engine.quit() save_pgn(game) except IndexError: LOG.debug("Board.moves_stack is empty") except NameError: LOG.debug("No active game so no need to save anything") # frame goodbye frame = epaper.Frame( name='exit', items=[epaper.FrameImage('images/calvin/sleeping.png')]) epaper_screen.update_frame(button_panel, frame) # Wait for possible screen thread to finish while epaper_screen.busy(): sleep(0.05) epaper_screen.sleep() gpio.cleanup() LOG.debug('GPIO cleaned') if shutdown: LOG.info('exit_program: shutdown pi') run(['sudo', 'poweroff'], check=True) else: LOG.debug('exit program') raise SystemExit(0)
def cleanup(bit): print("Cleaning bit setup:") for i in range(0, len(bit)): gpio.cleanup(bit[i]) print("Cleanup done")
engine.rootContext().setContextProperty('app', ctrl) engine.load(appQmlFile()) # safety timeout, must go away! # QTimer.singleShot(minutes(10), lambda : app.quit()) # enable Ctrl-C to quit from cli signal.signal(signal.SIGINT, signal.SIG_DFL) # timer = QTimer() # timer.start(500) # You may change this if you wish. # timer.timeout.connect(lambda: None) # Let the interpreter run each 500 ms. # if not isRasperry: # def reload(): # print('files changed!') # win = engine.rootObjects()[0] # win.close() # # win.setSource(QUrl()) # engine.clearComponentCache() # engine.load(appQmlFile()) # QTimer.singleShot(200, lambda : engine.rootObjects()[0].show()) # # win.setSource(appQmlFile()) # # engine.rootObjects()[0].show() # watcher = QFileSystemWatcher(app) # watcher.addPath(os.path.abspath(os.path.dirname(__file__))) # watcher.directoryChanged.connect(reload) app.aboutToQuit.connect(lambda: cleanup()) sys.exit(app.exec_())
#!/usr/bin/python import gpio as testGPIO import time, sys testGPIO.initGPIO() while True: try: testGPIO.waitingForClient("on") testGPIO.waitingForClient("off") testGPIO.recieveFromClient("on") testGPIO.recieveFromClient("off") testGPIO.wolfSend("on") testGPIO.wolfSend("off") testGPIO.wolfRecieve("on") testGPIO.wolfRecieve("off") testGPIO.sendToClient("on") testGPIO.sendToClient("off") except KeyboardInterrupt: testGPIO.cleanup() sys.exit()
raise Exception("Test exception requested") @app.route('/status') def status(): return "Ok" if __name__ == "__main__": try: process = eventlet.spawn(poll_sensor_loop) socketio.run(app, host='0.0.0.0', port=80, use_reloader=False) except (KeyboardInterrupt, SystemExit): pass except Exception as error: send_alert( "Exception occurred", "Uncaught exception occurred. Stack trace to follow (hopefully)") send_alert("Exception:", str(error)) gpio.cleanup() raise error if process: print("Stopping background process...") poll_sensors = False process.wait() print("Saving state...") save_state() print("Done")
def RunEnd(): for i in LEDS: IO.output(i, 0) time.sleep(0.001) IO.cleanup(i)
def cleanup(): for pin in pin_no: gpio.cleanup(pin)
time.sleep(2) #gstproc.wait(5) ### when gstproc fails with returncode == 255, it has indicated the video source ### may be incorrect; instead of /dev/video0 (default) it could be /dev/video1, etc. print "gst process finished, rc=", gstproc.returncode #gstproc.kill() #terminate() os.kill(gstproc.pid, signal.SIGINT) print 'signal.SIGINT:', signal.SIGINT if __name__ == "__main__": print "starting josh.py..." pill2kill = threading.Event() ioThread = threading.Thread(target=updateIndicators, args=(pill2kill, )) ioThread.start() while True: try: josh() except KeyboardInterrupt: pass break restarts = restarts + 1 print "...restarting({0}) gst recorder...".format(restarts) pill2kill.set() cleanup(led_red) cleanup(button_switch) print "Gst Recording script has terminated."
def cleanup(pin, assert_exists): if pin in pinMap : return gpio.cleanup(pinMap[pin], assert_exists) else : logger.info("pinname " + pin + "is not supported!")
#----------------------------[main] def main(): array = ["?", "?", "?", "?"] GPIO.setmode(GPIO.BOARD) GPIO.setup(status_led, GPIO.OUT) GPIO.output(status_led, GPIO.HIGH) while True: humidity, temperature = DHT.read_retry(DHT.DHT22, 10) array[0] = str(temperature) array[1] = str(humidity) array[2], array[3] = ds1820() print(array) senddata(array) for i in range(12): time.sleep(5) GPIO.output(status_led, GPIO.LOW) time.sleep(0.5) GPIO.output(status_led, GPIO.HIGH) #----------------------------[] if __name__ == '__main__': global hsvr try: log.info("dht", "starting") main() except: GPIO.cleanup() log.info("dht", "exit") pass
def player_indication(self, move): if (not ENABLE_VIBRATIONS): return self.init_vib() if move == "again": self.givevibrationagain() gpio.cleanup() return for string in move: if (string == "a1"): self.givevibration(dl) self.givevibration(dl) self.givevibration(dl) elif (string == "a2"): self.givevibration(dl) self.givevibration(dl) self.givevibration(ul) elif (string == "a3"): self.givevibration(dl) self.givevibration(ul) self.givevibration(dl) elif (string == "a4"): self.givevibration(dl) self.givevibration(ul) self.givevibration(ul) elif (string == "a5"): self.givevibration(ul) self.givevibration(dl) self.givevibration(dl) elif (string == "a6"): self.givevibration(ul) self.givevibration(dl) self.givevibration(ul) elif (string == "a7"): self.givevibration(ul) self.givevibration(ul) self.givevibration(dl) elif (string == "a8"): self.givevibration(ul) self.givevibration(ul) self.givevibration(ul) elif (string == "b1"): self.givevibration(dl) self.givevibration(dl) self.givevibration(dr) elif (string == "b2"): self.givevibration(dl) self.givevibration(dl) self.givevibration(ur) elif (string == "b3"): self.givevibration(dl) self.givevibration(ul) self.givevibration(dr) elif (string == "b4"): self.givevibration(dl) self.givevibration(ul) self.givevibration(ur) elif (string == "b5"): self.givevibration(ul) self.givevibration(dl) self.givevibration(dr) elif (string == "b6"): self.givevibration(ul) self.givevibration(dl) self.givevibration(ur) elif (string == "b7"): self.givevibration(ul) self.givevibration(ul) self.givevibration(dr) elif (string == "b8"): self.givevibration(ul) self.givevibration(ul) self.givevibration(ur) elif (string == "c1"): self.givevibration(dl) self.givevibration(dr) self.givevibration(dl) elif (string == "c2"): self.givevibration(dl) self.givevibration(dr) self.givevibration(ul) elif (string == "c3"): self.givevibration(dl) self.givevibration(ur) self.givevibration(dl) elif (string == "c4"): self.givevibration(dl) self.givevibration(ur) self.givevibration(ul) elif (string == "c5"): self.givevibration(ul) self.givevibration(dr) self.givevibration(dl) elif (string == "c6"): self.givevibration(ul) self.givevibration(dr) self.givevibration(ul) elif (string == "c7"): self.givevibration(ul) self.givevibration(ur) self.givevibration(dl) elif (string == "c8"): self.givevibration(ul) self.givevibration(ur) self.givevibration(ul) elif (string == "d1"): self.givevibration(dl) self.givevibration(dr) self.givevibration(dr) elif (string == "d2"): self.givevibration(dl) self.givevibration(dr) self.givevibration(ur) elif (string == "d3"): self.givevibration(dl) self.givevibration(ur) self.givevibration(dr) elif (string == "d4"): self.givevibration(dl) self.givevibration(ur) self.givevibration(ur) elif (string == "d5"): self.givevibration(ul) self.givevibration(dr) self.givevibration(dr) elif (string == "d6"): self.givevibration(ul) self.givevibration(dr) self.givevibration(ur) elif (string == "d7"): self.givevibration(ul) self.givevibration(ur) self.givevibration(dr) elif (string == "d8"): self.givevibration(ul) self.givevibration(ur) self.givevibration(ur) elif (string == "e1"): self.givevibration(dr) self.givevibration(dl) self.givevibration(dl) elif (string == "e2"): self.givevibration(dr) self.givevibration(dl) self.givevibration(ul) elif (string == "e3"): self.givevibration(dr) self.givevibration(ul) self.givevibration(dl) elif (string == "e4"): self.givevibration(dr) self.givevibration(ul) self.givevibration(ul) elif (string == "e5"): self.givevibration(ur) self.givevibration(dl) self.givevibration(dl) elif (string == "e6"): self.givevibration(ur) self.givevibration(dl) self.givevibration(ul) elif (string == "e7"): self.givevibration(ur) self.givevibration(ul) self.givevibration(dl) elif (string == "e8"): self.givevibration(ur) self.givevibration(ul) self.givevibration(ul) elif (string == "f1"): self.givevibration(dr) self.givevibration(dl) self.givevibration(dr) elif (string == "f2"): self.givevibration(dr) self.givevibration(dl) self.givevibration(ur) elif (string == "f3"): self.givevibration(dr) self.givevibration(ul) self.givevibration(dr) elif (string == "f4"): self.givevibration(dr) self.givevibration(ul) self.givevibration(ur) elif (string == "f5"): self.givevibration(ur) self.givevibration(dl) self.givevibration(dr) elif (string == "f6"): self.givevibration(ur) self.givevibration(dl) self.givevibration(ur) elif (string == "f7"): self.givevibration(ur) self.givevibration(ul) self.givevibration(dr) elif (string == "f8"): self.givevibration(ur) self.givevibration(ul) self.givevibration(ur) elif (string == "g1"): self.givevibration(dr) self.givevibration(dr) self.givevibration(dl) elif (string == "g2"): self.givevibration(dr) self.givevibration(dr) self.givevibration(ul) elif (string == "g3"): self.givevibration(dr) self.givevibration(ur) self.givevibration(dl) elif (string == "g4"): self.givevibration(dr) self.givevibration(ur) self.givevibration(ul) elif (string == "g5"): self.givevibration(ur) self.givevibration(dr) self.givevibration(dl) elif (string == "g6"): self.givevibration(ur) self.givevibration(dr) self.givevibration(ul) elif (string == "g7"): self.givevibration(ur) self.givevibration(ur) self.givevibration(dl) elif (string == "g8"): self.givevibration(ur) self.givevibration(ur) self.givevibration(ul) elif (string == "h1"): self.givevibration(dr) self.givevibration(dr) self.givevibration(dr) elif (string == "h2"): self.givevibration(dr) self.givevibration(dr) self.givevibration(ur) elif (string == "h3"): self.givevibration(dr) self.givevibration(ur) self.givevibration(dr) elif (string == "h4"): self.givevibration(dr) self.givevibration(ur) self.givevibration(ur) elif (string == "h5"): self.givevibration(ur) self.givevibration(dr) self.givevibration(dr) elif (string == "h6"): self.givevibration(ur) self.givevibration(dr) self.givevibration(ur) elif (string == "h7"): self.givevibration(ur) self.givevibration(ur) self.givevibration(dr) elif (string == "h8"): self.givevibration(ur) self.givevibration(ur) self.givevibration(ur) if string == move[0]: time.sleep(1.5) gpio.cleanup()
def cleanUp(self): gpio.cleanup(self.__pin)
import gpio locker_to_gpio = { 'L1': 395, 'L2': 389, 'L3': 398, 'L4': 393, 'L5': 394, 'L6': 297, 'L7': 396, 'L8': 397, 'L9': 255, 'L10': 392, 'L11': 481, 'L12': 430 } if __name__ == "__main__": for locker, pin in locker_to_gpio.iteritems(): gpio.setup(pin, gpio.OUT) gpio.output(pin, 0) gpio.cleanup(pin) return 0
def rotate(self, GPIO): Direction = 0 Step = 0 for Step in range(130, 0, -1): if Direction == 0: GPIO.output(out1, GPIO.HIGH) GPIO.output(out2, GPIO.LOW) GPIO.output(out3, GPIO.LOW) GPIO.output(out4, GPIO.LOW) time.sleep(0.008) #time.sleep(1) elif Direction == 1: GPIO.output(out1, GPIO.HIGH) GPIO.output(out2, GPIO.HIGH) GPIO.output(out3, GPIO.LOW) GPIO.output(out4, GPIO.LOW) time.sleep(0.008) #time.sleep(1) elif Direction == 2: GPIO.output(out1, GPIO.LOW) GPIO.output(out2, GPIO.HIGH) GPIO.output(out3, GPIO.LOW) GPIO.output(out4, GPIO.LOW) time.sleep(0.008) #time.sleep(1) elif Direction == 3: GPIO.output(out1, GPIO.LOW) GPIO.output(out2, GPIO.HIGH) GPIO.output(out3, GPIO.HIGH) GPIO.output(out4, GPIO.LOW) time.sleep(0.008) #time.sleep(1) elif Direction == 4: GPIO.output(out1, GPIO.LOW) GPIO.output(out2, GPIO.LOW) GPIO.output(out3, GPIO.HIGH) GPIO.output(out4, GPIO.LOW) time.sleep(0.008) #time.sleep(1) elif Direction == 5: GPIO.output(out1, GPIO.LOW) GPIO.output(out2, GPIO.LOW) GPIO.output(out3, GPIO.HIGH) GPIO.output(out4, GPIO.HIGH) time.sleep(0.008) #time.sleep(1) elif Direction == 6: GPIO.output(out1, GPIO.LOW) GPIO.output(out2, GPIO.LOW) GPIO.output(out3, GPIO.LOW) GPIO.output(out4, GPIO.HIGH) time.sleep(0.008) #time.sleep(1) elif Direction == 7: GPIO.output(out1, GPIO.HIGH) GPIO.output(out2, GPIO.LOW) GPIO.output(out3, GPIO.LOW) GPIO.output(out4, GPIO.HIGH) time.sleep(0.008) if Direction == 0: Direction = 7 continue Direction = Direction - 1 GPIO.cleanup()
def cleanup(): for pin in [10, 22, 27]: gpio.cleanup(pin)
def initPins(self): GPIO.cleanup() # GPIO.setmode(GPIO.BCM) for pin in self.gpioDict.values(): GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, 0)
gpio.blink() data = {"title": "StripRevolution Control"} return bottle.template('www/index', data=data) @bottle.route("/engine/<filename>") def engine(filename): gpio.blink() data = {"title": filename} return bottle.template('www/engine', data=data) @bottle.route("/engine/edit/<filename>") def engine(filename): gpio.blink() data = {"title": filename} return bottle.template('www/edit', data=data) @bottle.post("/request") def request(): gpio.blink() data = {} for d in bottle.request.json: data[d["name"]] = float(d["value"]) / 100.0 droplets.set(data) bottle.response.content_type = "application/json" return json.dumps("success") # bottle.debug(True) bottle.run(host=HOST, port=PORT)#, reloader=True) gpio.cleanup()
def clean(self): GPIO.cleanup()
def clean_up_gpio(self, num, stack): print("Clean up GPIO...") gpio.cleanup(cf.GPIO_BUTTON_1) gpio.cleanup(cf.GPIO_BUTTON_2) gpio.cleanup(cf.GPIO_BUTTON_3) gpio.cleanup(cf.GPIO_BUTTON_4) gpio.cleanup(cf.GPIO_BUTTON_SS1) gpio.cleanup(cf.GPIO_BUTTON_SS2) exit(0)