move method

Future<void> move(
  1. String profileToken, {
  2. required Vector2D direction,
  3. Vector1D? zoom,
})

Helper method

Implementation

Future<void> move(
  String profileToken, {
  required Vector2D direction,
  Vector1D? zoom,
}) async {
  loggy.debug('move');

  Vector1D zoomAdjust = zoom ?? Vector1D(x: 0);

  try {
    await relativeMove(
      profileToken,
      PtzVector(panTilt: direction, zoom: zoomAdjust),
      null,
    );
  } catch (err) {
    Vector2D? panTilt;

    loggy.error('Relative move failed');

    loggy.error(err);

    loggy.error('Attempting workaround with AbsoluteMove');

    final ptzStatus = await getStatus(profileToken);
    if (ptzStatus.position.panTilt != null) {
      panTilt = Vector2D(
          x: _limitValue(
            ptzStatus.position.panTilt!.x,
            direction.x,
            defaultPanTiltLimits?.range.xRange.min ?? -1,
            defaultPanTiltLimits?.range.xRange.max ?? 1,
          ),
          y: _limitValue(
            ptzStatus.position.panTilt!.y,
            direction.y,
            defaultPanTiltLimits?.range.yRange.min ?? -1,
            defaultPanTiltLimits?.range.yRange.max ?? 1,
          ));
    } else {
      panTilt = Vector2D(
        x: ptzStatus.position.panTilt!.x,
        y: ptzStatus.position.panTilt!.y,
      );
    }

    if (ptzStatus.position.zoom != null) {
      zoomAdjust = Vector1D(
          x: _limitValue(
        ptzStatus.position.zoom!.x,
        zoomAdjust.x,
        defaultZoomLimits?.range.xRange.min ?? 0,
        defaultZoomLimits?.range.xRange.max ?? 1,
      ));
    }

    await absoluteMove(profileToken,
        position: PtzVector(panTilt: panTilt, zoom: zoomAdjust));
  }
}