示例#1
0
    def on_menu_down(self, sender: IDevice):
        sender.stop()

        # Hover the plate and deactivate the servos
        pymoab.hoverPlate()
        pymoab.sync()
        sleep(0.5)
        pymoab.disableServoPower()
        pymoab.sync()
        sleep(0.5)
示例#2
0
def signal_handler(sig, frame) -> int:
    log.info(f"Signal {sig} received, shutting down...")

    # Lower the plate and deactivate the servos
    # lowerPlate is 155º; testing a lower position of 160º
    pymoab.setServoPositions(155, 155, 155)
    pymoab.sync()
    time.sleep(0.2)

    pymoab.disableServoPower()
    pymoab.sync()
    time.sleep(0.1)

    # Clear the screen
    pymoab.setIcon(pymoab.Icon.BLANK)
    pymoab.setText(pymoab.Text.BLANK)
    pymoab.sync()
    time.sleep(0.1)

    sys.exit(0)
示例#3
0
def main():
    args = parse_args()

    # load configs
    config = load_config(args.config)

    # Load calibration.json file which contains the ball hue (22 default)
    calibration = load_calibration(args.calibration)

    # Now that log is configured, we can say we're starting up
    log.info("Moab starting.")

    # onetime init of pymoab library
    # side effect of setting OLED to Initalizing... which is ok
    pymoab.init()
    pymoab.sync()
    time.sleep(0.1)

    # put plate in "ready" mode, then cut power until needed
    pymoab.setServoPositions(150, 150, 150)
    pymoab.sync()
    time.sleep(0.1)
    pymoab.disableServoPower()
    pymoab.sync()
    time.sleep(0.1)

    # optional perf timing
    global perf_timer
    if args.perf_interval_sec > 0:
        perf_timer = ThreadedTimer()
        perf_timer.start(args.perf_interval_sec, printPerformanceCounters)

    try:
        devices = config["devices"]
    except Exception as e:
        log.exception(f"Error reading devices from {args.config}\n{e}")
        sys.exit(-1)

    device_stack = deque()
    device_stack.append(args.device)

    previous_menu: int = 0

    # Register the signal handler
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    while True:

        curr_device = device_stack.pop() if len(device_stack) > 0 else None
        if curr_device is None:
            break

        try:
            config = from_dict(IDevice.Config, devices.get(curr_device))
            config.menu_idx = previous_menu
            device = Device.createFromConfig(config, calibration)

            log.info("{} §".format(curr_device.upper()))
            device.run()
            previous_menu = device.previous_menu

            # Did our current device ask us to activate another one?
            next_device = device.get_next_device()
            if next_device is not None:
                # Save this device so we can go back to it
                device_stack.append(curr_device)

                # Will be the one popped off next iteration
                device_stack.append(next_device)
        except Exception as e:
            log.exception(f"Error instantiating {args.device}\n{e}")
            curr_device = None
            continue

        # Reload configs
        config = load_config(args.config)
        calibration = load_calibration(args.calibration)