Пример #1
0
 def cli_args():
     return setup_cli_args(
         cli.bgr, cli.usb, cli.usb_port, cli.width, cli.middle_percent,
         cli.minimum_pixels, cli.hsv_range, cli.grpc_port, cli.leds,
         cli.flip_x, cli.flip_y, cli.mask_x, cli.mask_y, cli.vertical_lines,
         cli.horizontal_lines, cli.camera_name_optional, cli.display,
         cli.draw_contour, cli.draw_box, cli.http_host, cli.http_file,
         cli.http_delay_secs, cli.http_verbose, cli.verbose)
#!/usr/bin/env python

import logging

import cli_args as cli
from cli_args import LOG_LEVEL, GRPC_HOST
from cli_args import setup_cli_args
from location_client import LocationClient
from utils import setup_logging

logger = logging.getLogger(__name__)

if __name__ == "__main__":
    # Parse CLI args
    args = setup_cli_args(cli.grpc_host, cli.verbose)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    with LocationClient(args[GRPC_HOST]) as client:
        try:
            while True:
                print("Got location: {0}".format(client.get_xy()))
        except KeyboardInterrupt:
            pass

    logger.info("Exiting...")
Пример #3
0
import cli_args as cli
from cli_args import setup_cli_args
from constants import MQTT_HOST, LOG_LEVEL, GRPC_HOST, TOPIC, MQTT_TOPIC
from location_client import LocationClient
from mqtt_connection import MqttConnection
from utils import setup_logging, waitForKeyboardInterrupt

import frc_utils
from frc_utils import COMMAND, ENABLED

logger = logging.getLogger(__name__)

if __name__ == "__main__":
    # Parse CLI args
    args = setup_cli_args(cli.grpc_host, cli.mqtt_host, cli.mqtt_topic, cli.verbose)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    # Start location reader
    with LocationClient(args[GRPC_HOST]) as loc_client:

        # Define MQTT callbacks
        def on_connect(mqtt_client, userdata, flags, rc):
            logger.info("Connected to MQTT broker with result code: %s", rc)
            Thread(target=publish_locations, args=(mqtt_client, userdata)).start()
            mqtt_client.subscribe(userdata[COMMAND])


        def publish_locations(mqtt_client, userdata):
Пример #4
0
            for i in range(4, 8):
                set_pixel(i,
                          right_color[2],
                          right_color[1],
                          right_color[0],
                          brightness=self._brightness)
            show()

    def clear_leds(self):
        for i in range(8):
            set_pixel(i, 0, 0, 0, brightness=self._brightness)


if __name__ == "__main__":
    # Parse CLI args
    args = setup_cli_args(cli.grpc_host, cli.mqtt_host, cli.led_name,
                          cli.led_brightness, cli.verbose)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    blinkt = BlinktSubscriber(args[LED_BRIGHTNESS])

    # Define MQTT callbacks
    def on_connect(mqtt_client, userdata, flags, rc):
        logger.info("Connected with result code: {0}".format(rc))
        mqtt_client.subscribe("leds/{0}".format(userdata[TOPIC]))

    def on_message(mqtt_client, userdata, msg):
        logger.info("{0} {1}".format(msg.topic, msg.payload))

    # Setup MQTT client
Пример #5
0
@nav.on(nav.UP)
def handle_up_button(ch, evt):
    item_deque.rotate(1)
    assign_selected_sensor()


@nav.on(nav.DOWN)
def handle_down_button(ch, evt):
    item_deque.rotate(-1)
    assign_selected_sensor()


if __name__ == "__main__":
    # Parse CLI args
    args = cli.setup_cli_args(cli.mqtt_host, cli.verbose)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    Thread(target=lcd_display, args=(item_dict, 0.1)).start()

    # Setup MQTT client
    with MqttConnection(args[MQTT_HOST],
                        userdata={ITEM_DICT: item_dict},
                        on_connect=on_connect,
                        on_message=on_message):
        waitForKeyboardInterrupt()

    logger.info("Exiting...")
Пример #6
0
from threading import Thread

import calibrate_servo
import cli_args  as cli
import pantilthat as pth
from cli_args import LOG_LEVEL, GRPC_HOST
from cli_args import setup_cli_args
from hat_servo import HatServo
from location_client import LocationClient
from utils import setup_logging

logger = logging.getLogger(__name__)

if __name__ == "__main__":
    # Setuo CLI args
    args = setup_cli_args(cli.grpc_host, cli.alternate, cli.calib, cli.verbose)

    alternate = args["alternate"]
    calib = args["calib"]

    setup_logging(level=args[LOG_LEVEL])

    with LocationClient(args[GRPC_HOST]) as client:

        # Create servos
        servo_x = HatServo("Pan", pth.pan, alternate, 1.0, 8)
        servo_y = HatServo("Tilt", pth.tilt, alternate, 1.0, 8)

        if calib:
            calib_t = Thread(target=calibrate_servo.calibrate, args=(client, servo_x, servo_y))
            calib_t.start()
Пример #7
0
import logging
from threading import Thread

import cli_args  as cli
from cli_args import CAMERA_NAME, LOG_LEVEL, MQTT_HOST, GRPC_HOST
from cli_args import setup_cli_args
from location_client import LocationClient
from mqtt_connection import MqttConnection
from utils import setup_logging, waitForKeyboardInterrupt

logger = logging.getLogger(__name__)

if __name__ == "__main__":
    # Parse CLI args
    args = setup_cli_args(cli.grpc_host, cli.mqtt_host, cli.camera_name, cli.verbose)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    # Start location reader
    with LocationClient(args[GRPC_HOST]) as loc_client:

        # Define MQTT callbacks
        def on_connect(mqtt_client, userdata, flags, rc):
            logger.info("Connected with result code: {0}".format(rc))
            Thread(target=publish_locations, args=(mqtt_client, userdata)).start()


        def publish_locations(mqtt_client, userdata):
            while True:
Пример #8
0
                elif key == ord("q"):
                    self.__cam.close()
                    break

    def stop(self):
        self.__image_server.stop()


if __name__ == "__main__":
    # Parse CLI args
    args = setup_cli_args(cli.width,
                          cli.usb,
                          cli.usb_port,
                          cli.display,
                          cli.flip_x,
                          cli.flip_y,
                          cli.http_host,
                          cli.http_file,
                          cli.http_delay_secs,
                          cli.http_verbose,
                          cli.verbose)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    color_picker = ColorPicker(**strip_loglevel(args))
    try:
        color_picker.start()
    except KeyboardInterrupt:
        pass
    finally: