<commit_before>#include "Camera.h"

Camera::Camera(int _id, ServoCommand &_servoCommand) {
  id = _id;
  servoCommand = &_servoCommand;

  laserPin = 0;

  panMin = 0;
  panMax = 0;
  tiltMin = 0;
  tiltMax = 0;

  panStart = 0;
  panTarget = 0;

  tiltStart = 0;
  tiltTarget = 0;

  animationStart = 0;
  animationDuration = 0;
  oneLastFrame = false;

  isLaserOn = false;
  isPaused = false;

  nullSignalDelay = 500;
  nullSignalTime = 0;

  position.set(0, 0, 0);
  direction.set(0, 0, 0);

  shuttingDown = false;
}

int Camera::getId() {
  return id;
}

int Camera::getLaserPin() {
  return laserPin;
}

void Camera::setLaserPin(int v) {
  laserPin = v;
}

void Camera::update() {
  if (isAnimating()) {
    servoCommand->setServo(id * 2 + 0, ofMap(getPan(), 0, 1, panMin, panMax));
    servoCommand->setServo(id * 2 + 1, ofMap(getTilt(), 0, 1, tiltMin, tiltMax));
  }
  else if (nullSignalTime != 0 && ofGetSystemTime() > nullSignalTime) {
    sendNullSignal();
  }
}

void Camera::setPanExtent(int min, int max) {
  panMin = min;
  panMax = max;
}

void Camera::setTiltExtent(int min, int max) {
  tiltMin = min;
  tiltMax = max;
}

float Camera::getPan() {
  if (isAnimating()) {
    return easeInOut(
          ofGetSystemTime() - animationStart,
          panStart,
          panTarget - panStart,
          animationDuration);
  }
  else {
    return panTarget;
  }
}

void Camera::setPan(float pan) {
  setPanAndTilt(pan, getTilt());
}

float Camera::getTilt() {
  if (isAnimating()) {
    return easeInOut(
          ofGetSystemTime() - animationStart,
          tiltStart,
          tiltTarget - tiltStart,
          animationDuration);
  }
  else {
    return tiltTarget;
  }
}

void Camera::setTilt(float tilt) {
  setPanAndTilt(getPan(), tilt);
}

void Camera::setPanAndTilt(float pan, float tilt) {
  cout << "Camera(" << id << ")" << "::setPanAndTilt(" << pan << ", " << tilt << ")" << endl;
  panStart = panTarget = pan;
  tiltStart = tiltTarget = tilt;

  animationStart = 0;
  animationDuration = 0;
  oneLastFrame = false;

  nullSignalTime = ofGetSystemTime() + nullSignalDelay;

  servoCommand->setServo(id * 2 + 0, ofMap(getPan(), 0, 1, panMin, panMax));
  servoCommand->setServo(id * 2 + 1, ofMap(getTilt(), 0, 1, tiltMin, tiltMax));
}

void Camera::panAndTiltTo(float pan, float tilt) {
  panAndTiltTo(pan, tilt, calculateDuration(getPan(), getTilt(), pan, tilt));
}

void Camera::setPanAndTiltHome() {
  setPanAndTilt(0.5, 0.5);
}

void Camera::panAndTiltTo(float pan, float tilt, int duration) {
  cout << "Camera(" << id << ")"
    << "::panAndTiltTo(" << pan << ", " << tilt << ", " << duration << ")"
    << ", current=" << getPan() << ", " << getTilt()
    << endl;
  panStart = getPan();
  tiltStart = getTilt();

  panTarget = pan;
  tiltTarget = tilt;

  animationStart = ofGetSystemTime();
  animationDuration = duration;
  oneLastFrame = true;

  nullSignalTime = animationStart + animationDuration + nullSignalDelay;
}

bool Camera::isAnimating() {
  if (ofGetSystemTime() < animationStart + animationDuration) {
    return true;
  }
  if (oneLastFrame) {
    oneLastFrame = false;
    return true;
  }
  return false;
}

bool Camera::getLaser() {
  return isLaserOn;
}

void Camera::setLaser(bool on) {
  isLaserOn = on;
  servoCommand->setDigital(laserPin, on);
}

bool Camera::getPaused() {
  return isPaused;
}

void Camera::setPaused(bool v) {
  isPaused = v;

  if (v) {
    panStart = panTarget = getPan();
    tiltStart = tiltTarget = getTilt();

    animationStart = 0;
    animationDuration = 0;
    oneLastFrame = false;
  }
}

ofVec3f Camera::getPosition() {
  return position;
}
void Camera::setPosition(ofVec3f v) {
  position = v;
}

ofVec3f Camera::getDirection() {
  return direction;
}
void Camera::setDirection(ofVec3f v) {
  direction = v;<commit_msg>Added ability to disable laser. Safety first! d-:<commit_after>#include "Camera.h"

Camera::Camera(int _id, ServoCommand &_servoCommand) {
  id = _id;
  servoCommand = &_servoCommand;

  laserPin = 0;

  panMin = 0;
  panMax = 0;
  tiltMin = 0;
  tiltMax = 0;

  panStart = 0;
  panTarget = 0;

  tiltStart = 0;
  tiltTarget = 0;

  animationStart = 0;
  animationDuration = 0;
  oneLastFrame = false;

  isLaserOn = false;
  isPaused = false;

  nullSignalDelay = 500;
  nullSignalTime = 0;

  position.set(0, 0, 0);
  direction.set(0, 0, 0);

  shuttingDown = false;
}

int Camera::getId() {
  return id;
}

int Camera::getLaserPin() {
  return laserPin;
}

void Camera::setLaserPin(int v) {
  laserPin = v;
}

void Camera::update() {
  if (isAnimating()) {
    servoCommand->setServo(id * 2 + 0, ofMap(getPan(), 0, 1, panMin, panMax));
    servoCommand->setServo(id * 2 + 1, ofMap(getTilt(), 0, 1, tiltMin, tiltMax));
  }
  else if (nullSignalTime != 0 && ofGetSystemTime() > nullSignalTime) {
    sendNullSignal();
  }
}

void Camera::setPanExtent(int min, int max) {
  panMin = min;
  panMax = max;
}

void Camera::setTiltExtent(int min, int max) {
  tiltMin = min;
  tiltMax = max;
}

float Camera::getPan() {
  if (isAnimating()) {
    return easeInOut(
          ofGetSystemTime() - animationStart,
          panStart,
          panTarget - panStart,
          animationDuration);
  }
  else {
    return panTarget;
  }
}

void Camera::setPan(float pan) {
  setPanAndTilt(pan, getTilt());
}

float Camera::getTilt() {
  if (isAnimating()) {
    return easeInOut(
          ofGetSystemTime() - animationStart,
          tiltStart,
          tiltTarget - tiltStart,
          animationDuration);
  }
  else {
    return tiltTarget;
  }
}

void Camera::setTilt(float tilt) {
  setPanAndTilt(getPan(), tilt);
}

void Camera::setPanAndTilt(float pan, float tilt) {
  cout << "Camera(" << id << ")" << "::setPanAndTilt(" << pan << ", " << tilt << ")" << endl;
  panStart = panTarget = pan;
  tiltStart = tiltTarget = tilt;

  animationStart = 0;
  animationDuration = 0;
  oneLastFrame = false;

  nullSignalTime = ofGetSystemTime() + nullSignalDelay;

  servoCommand->setServo(id * 2 + 0, ofMap(getPan(), 0, 1, panMin, panMax));
  servoCommand->setServo(id * 2 + 1, ofMap(getTilt(), 0, 1, tiltMin, tiltMax));
}

void Camera::panAndTiltTo(float pan, float tilt) {
  panAndTiltTo(pan, tilt, calculateDuration(getPan(), getTilt(), pan, tilt));
}

void Camera::setPanAndTiltHome() {
  setPanAndTilt(0.5, 0.5);
}

void Camera::panAndTiltTo(float pan, float tilt, int duration) {
  cout << "Camera(" << id << ")"
    << "::panAndTiltTo(" << pan << ", " << tilt << ", " << duration << ")"
    << ", current=" << getPan() << ", " << getTilt()
    << endl;
  panStart = getPan();
  tiltStart = getTilt();

  panTarget = pan;
  tiltTarget = tilt;

  animationStart = ofGetSystemTime();
  animationDuration = duration;
  oneLastFrame = true;

  nullSignalTime = animationStart + animationDuration + nullSignalDelay;
}

bool Camera::isAnimating() {
  if (ofGetSystemTime() < animationStart + animationDuration) {
    return true;
  }
  if (oneLastFrame) {
    oneLastFrame = false;
    return true;
  }
  return false;
}

bool Camera::getLaser() {
  return isLaserOn;
}

void Camera::setLaser(bool on) {
  isLaserOn = on;

  if (laserPin >= 0) {
    servoCommand->setDigital(laserPin, on);
  }
}

bool Camera::getPaused() {
  return isPaused;
}

void Camera::setPaused(bool v) {
  isPaused = v;

  if (v) {
    panStart = panTarget = getPan();
    tiltStart = tiltTarget = getTilt();

    animationStart = 0;
    animationDuration = 0;
    oneLastFrame = false;
  }
}

ofVec3f Camera::getPosition() {
  return position;
}
void Camera::setPosition(ofVec3f v) {
  position = v;
}

ofVec3f Camera::getDirection() {
  return direction;
}
void Camera::setDirection(ofVec3f v) {
  direction = v;
{'fraction_non_alphanumeric': 0.14920717442162723, 'fraction_numerical': 0.013127112035352223, 'mean_word_length': 3.4973699590882523, 'pattern_counts': {'":': 4, '<': 101, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5166414', 'n_tokens_mistral': 2880, 'n_tokens_neox': 2778, 'n_words': 629}