class App(object): def __init__(self): #GPIO.setwarnings(False) self.board = pingo.detect.get_board() led_pin = self.board.pins[13] self.led = Led(led_pin) self.btn_pin = self.board.pins[7] self.switch = Switch(self.btn_pin) self.switch.set_callback_up(self.toggle) self.recording = False def loop(self): self.init_led_and_switch() try: while (True): time.sleep(1) except KeyboardInterrupt: print("User Cancelled (Ctrl C)") self.stop_at_exit() def toggle(self): print("press") self.recording = not self.recording if self.recording: self.led.blink(times=0, on_delay=0.8, off_delay=0.2) # blink foreever self.start_recording() else: self.led.stop() # stop blinking self.led.on() self.stop_recording() def init_led_and_switch(self): self.led.on() self.switch.start() def start_recording(self): print("start recording") def stop_recording(self): print("stop recording") def stop_at_exit(self): self.led.off() self.switch.stop() self.led.stop() self.board.cleanup()
class App(object): def __init__(self): #GPIO.setwarnings(False) self.board = pingo.detect.get_board() led_pin = self.board.pins[13] self.led = Led(led_pin) self.btn_pin = self.board.pins[7] self.switch = Switch(self.btn_pin) self.switch.set_callback_up(self.toggle) self.recording = False def loop(self): self.init_led_and_switch() try: while(True): time.sleep(1) except KeyboardInterrupt: print("User Cancelled (Ctrl C)") self.stop_at_exit() def toggle(self): print("press") self.recording = not self.recording if self.recording: self.led.blink(times=0, on_delay=0.8, off_delay=0.2) # blink foreever self.start_recording() else: self.led.stop() # stop blinking self.led.on() self.stop_recording() def init_led_and_switch(self): self.led.on() self.switch.start() def start_recording(self): print("start recording") def stop_recording(self): print("stop recording") def stop_at_exit(self): self.led.off() self.switch.stop() self.led.stop() self.board.cleanup()
class App(object): def __init__(self): #GPIO.setwarnings(False) self.board = pingo.detect.get_board() led_pin = self.board.pins[13] self.led = Led(led_pin) self.btn_pin = self.board.pins[7] self.switch = Switch(self.btn_pin) self.switch.set_callback_up(self.press) self.switch.set_callback_down(self.release) def loop(self): self.led.off() self.switch.start() #self.led.blink(times=0) # blink foreever try: while(True): time.sleep(1) except KeyboardInterrupt: print("User Cancelled (Ctrl C)") self.stop_at_exit() def press(self): print("press") self.toggle() def release(self): print("release") def toggle(self): self.led.toggle() def stop_at_exit(self): self.led.off() self.switch.stop() self.led.stop() self.board.cleanup()
class App(object): def __init__(self): #GPIO.setwarnings(False) self.board = pingo.detect.get_board() led_pin = self.board.pins[13] self.led = Led(led_pin) self.btn_pin = self.board.pins[7] self.switch = Switch(self.btn_pin) self.switch.set_callback_up(self.press) self.switch.set_callback_down(self.release) def loop(self): self.led.off() self.switch.start() #self.led.blink(times=0) # blink foreever try: while (True): time.sleep(1) except KeyboardInterrupt: print("User Cancelled (Ctrl C)") self.stop_at_exit() def press(self): print("press") self.toggle() def release(self): print("release") def toggle(self): self.led.toggle() def stop_at_exit(self): self.led.off() self.switch.stop() self.led.stop() self.board.cleanup()
class RecorderApp(object): def __init__( self, filename, vflip, hflip, video_stabilization, video_preview, device, baudrate, erase, fps, height, width, lag, ): self.filename = filename # filename factory (to create filenames) self.board = pingo.detect.get_board() led_pin = self.board.pins[13] self.led = Led(led_pin) btn_pin = self.board.pins[7] self.switch = Switch(btn_pin) self.switch.set_callback_down(self.switch_released) self.switch.set_callback_up(self.switch_pressed) self.camera_settings = Settings( resolution=(width, height), framerate=fps, vflip=vflip, hflip=hflip, video_stabilization=video_stabilization ) self.video_preview = video_preview self.device = device self.baudrate = baudrate self.erase = erase self.lag = lag self.time_to_sleep = 0.01 self.recording = False self.recording_task = None self.sensors = [] sensors_arduino = SensorsArduino(device=self.device, baudrate=self.baudrate, adc_channels_number=2) logger.info("capabilities: %s" % sensors_arduino.capabilities) sensors_arduino.connect() sensors_arduino.ADC[0].calibrate(lambda value: linear_function_with_limit(value, 520.0, 603.0, 0.0, 100.0)) self.sensors.append(sensors_arduino) def switch_pressed(self): logger.debug("switch pressed") def switch_released(self): logger.debug("switch released") if self.recording: self.stop_recording() else: self.start_recording() def start_recording(self): print("Start recording") self.recording = True self.recording_task = RecordingTask( self.camera_settings, self.sensors, self.led, self.filename, self.video_preview, self.erase, self.lag, self.time_to_sleep, ) self.recording_task.start() if self.lag > 0: raise NotImplementedError("Experimental - buggy! when stop recording before lag expired") self.led.blink( times=0, on_delay=0.8 / 8, off_delay=0.2 / 8 ) # blink (quickly) foreever (up to lag/delay expired) def stop_recording(self): print("Stop recording") self.recording = False self.recording_task.terminate() self.led.stop() # stop blinking while self.led.blinking: print("waiting led stop blinking") time.sleep(0.5) self.led.stop() self.led.on() # ToFix !!! def init_led_and_switch(self): self.led.on() self.led.blink(times=5, on_delay=0.1, off_delay=0.3) while self.led.blinking: print("waiting led stop blinking") time.sleep(0.5) self.switch.start() def loop(self): self.init_led_and_switch() try: while True: logger.info("mainloop") time.sleep(1) except KeyboardInterrupt: logger.info("User Cancelled (Ctrl C)") finally: self.close() def close(self): if self.recording: self.recording = False self.recording_task.terminate() self.led.off() self.led.blink(times=5, on_delay=0.3, off_delay=0.1) while self.led.blinking: time.sleep(1) self.led.off() self.switch.stop() self.board.cleanup() logger.info("closed RecorderApp")
class App(object): def __init__(self): #GPIO.setwarnings(False) self.board = pingo.detect.get_board() led_pin = self.board.pins[13] self.led = Led(led_pin) self.btn_pin = self.board.pins[7] self.switch = Switch(self.btn_pin) self.switch.set_callback_up(self.pushtype) self.recording = False self.GlobalState = False def loop(self): self.init_led_and_switch() try: while (True): time.sleep(1) except KeyboardInterrupt: print("User Cancelled (Ctrl C)") self.stop_at_exit() def pushtype(self): timer = 0 while (self.switch.pin.state == pingo.HIGH): timer += 1 time.sleep(0.1) if (timer <= 10): push_type = " short_push" if self.GlobalState: self.toggle() else: push_type = " long_push" self.GlobalState = not self.GlobalState if self.GlobalState: self.led.on() print("Power on") else: self.led.off() print("Power off") print(str(timer) + push_type) def toggle(self): print("press") self.recording = not self.recording if self.recording: self.led.blink(times=0, on_delay=0.2, off_delay=0.8) # blink forever self.start_recording() else: self.led.stop() # stop blinking self.stop_recording() def init_led_and_switch(self): self.led.off() self.switch.start() def start_recording(self): print("start recording") def stop_recording(self): print("stop recording") def stop_at_exit(self): print("stopping") self.led.stop() self.led.off() self.switch.stop() self.board.cleanup()
class App(object): def __init__(self): #GPIO.setwarnings(False) self.board = pingo.detect.get_board() led_pin = self.board.pins[13] self.led = Led(led_pin) self.btn_pin = self.board.pins[7] self.switch = Switch(self.btn_pin) self.switch.set_callback_up(self.pushtype) self.recording = False self.GlobalState = False def loop(self): self.init_led_and_switch() try: while(True): time.sleep(1) except KeyboardInterrupt: print("User Cancelled (Ctrl C)") self.stop_at_exit() def pushtype(self): timer = 0 while(self.switch.pin.state == pingo.HIGH): timer += 1 time.sleep(0.1) if(timer <= 10): push_type = " short_push" if self.GlobalState: self.toggle() else: push_type = " long_push" self.GlobalState = not self.GlobalState if self.GlobalState: self.led.on() print("Power on") else: self.led.off() print("Power off") print(str(timer) + push_type) def toggle(self): print("press") self.recording = not self.recording if self.recording: self.led.blink(times=0, on_delay=0.2, off_delay=0.8) # blink forever self.start_recording() else: self.led.stop() # stop blinking self.stop_recording() def init_led_and_switch(self): self.led.off() self.switch.start() def start_recording(self): print("start recording") def stop_recording(self): print("stop recording") def stop_at_exit(self): print("stopping") self.led.stop() self.led.off() self.switch.stop() self.board.cleanup()