Exemple #1
0
def wifi():
    """Configure Spark Wifi settings.

    This requires the Spark to be connected over USB.

    \b
    Steps:
        - Stop running services.
        - Look for valid USB device.
        - Spark 2 / Spark 3:
            - Trigger listening mode.
            - Connect to device serial to set up Wifi.
        - Spark 4:
            - Print provisioning instructions.
    """
    utils.confirm_mode()

    while True:
        particle_dev = usb.core.find(idVendor=const.VID_PARTICLE)
        if particle_dev:
            particle_wifi(particle_dev)
            break

        esp_dev = usb.core.find(idVendor=const.VID_ESPRESSIF,
                                idProduct=const.PID_ESP32)
        if esp_dev:
            esp_wifi()
            break

        utils.confirm_usb()
Exemple #2
0
def particle(release, pull, command):
    """Start a Docker container with access to the Particle CLI.

    This requires the Spark to be connected over USB.

    \b
    Steps:
        - Stop running services.
        - Pull flasher image.
        - Start flasher image.
    """
    utils.confirm_mode()
    utils.confirm_usb()
    prepare_flasher(release, pull)

    utils.info('Starting Particle image...')
    utils.info("Type 'exit' and press enter to exit the shell")
    run_flasher(release, command)
Exemple #3
0
def flash(release, pull):
    """Flash firmware on Spark.

    This requires the Spark to be connected over USB.

    After the first install, firmware updates can also be installed using the UI.

    \b
    Steps:
        - Stop running services.
        - Pull flasher image.
        - Run flash command.
    """
    utils.confirm_mode()
    utils.confirm_usb()
    prepare_flasher(release, pull)

    utils.info('Flashing Spark...')
    run_flasher(release, 'flash')
Exemple #4
0
def find_usb_spark() -> usb.core.Device:
    while True:
        devices = [
            *usb.core.find(find_all=True,
                           idVendor=const.VID_PARTICLE,
                           idProduct=const.PID_PHOTON),
            *usb.core.find(find_all=True,
                           idVendor=const.VID_PARTICLE,
                           idProduct=const.PID_P1),
            *usb.core.find(find_all=True,
                           idVendor=const.VID_ESPRESSIF,
                           idProduct=const.PID_ESP32),
        ]
        num_devices = len(devices)
        if num_devices == 0:
            utils.warn('No USB-connected Spark detected')
            utils.confirm_usb()
        elif num_devices == 1:
            return devices[0]
        else:
            utils.warn(f'{len(devices)} USB-connected Sparks detected.')
            utils.confirm_usb()
Exemple #5
0
def test_confirm_usb(mocked_ext):
    utils.confirm_usb()
    assert mocked_ext['input'].call_count == 1