<commit_before>// Derived and adapted from
// https://github.com/rwldrn/duino/blob/development/lib/servo.js
var Board = require("../lib/board.js"),
    events = require("events"),
    util = require("util"),
    es6 = require("es6-collections"),
    WeakMap = es6.WeakMap;

// Sensor instance private data
var servos = [],
    states = [],
    priv = new WeakMap();

/**
 * Servo
 * @constructor
 *
 * @param {Object} opts Options: pin, type, id, range
 */
function Servo( opts ) {

  if ( !(this instanceof Servo) ) {
    return new Servo( opts );
  }

  opts = Board.options( opts );

  // Hardware instance properties
  this.board = Board.mount( opts );
  this.firmata = this.board.firmata;
  this.mode = this.firmata.MODES.SERVO;
  this.pin = opts.pin;

  // If pin is not a PWM pin, emit an error
  if ( !Board.Pin.isPWM(this.pin) ) {
    this.emit( "error", this.pin + "is not a valid PWM pin" );
  }

  // Servo instance properties
  this.range = opts.range || [ 0, 180 ];

  // Allow user defined ids, defaults to system ID
  this.id = opts.id || Board.uid();

  // The type of servo determines certain alternate
  // behaviours in the API
  this.type = opts.type || "standard";

  // Collect all movement history for this servo
  this.history = [/*
    {
      timestamp: Date.now(),
      degrees: degrees
    }
  */];

  // Interval/Sweep pointer
  this.interval = null;

  this.isMoving = false;

  // Set the pin to INPUT mode
  this.firmata.pinMode( this.pin, this.mode );

  // Create a non-writable "last" property
  // shortcut to access the last servo movement
  Object.defineProperty( this, "last", {
    get: function() {
      return this.history[ this.history.length - 1 ];
    }
  });

  // Allow "setup"instructions to come from
  // constructor options properties

  // If "startAt" true and center falsy
  // set servo to min or max degrees
  if ( opts.startAt && !opts.center  ) {
    this[ opts.startAt ]();
  }

  // If "center" true set servo to 90deg
  if ( opts.center ) {
   this.center();
  }

  // Create a "state" entry for privately
  // storing the state of the servos
  servos.push( this );
  states.push( {} );
}

util.inherits( Servo, events.EventEmitter );

/**
 * move Move the servo horn N degrees
 *       Optionally fire a move event
 *<commit_msg>Breaking change to the servo constructor options. opt.startAt is now a numeric value passed to move();<commit_after>// Derived and adapted from
// https://github.com/rwldrn/duino/blob/development/lib/servo.js
var Board = require("../lib/board.js"),
    events = require("events"),
    util = require("util"),
    es6 = require("es6-collections"),
    WeakMap = es6.WeakMap;

// Sensor instance private data
var servos = [],
    states = [],
    priv = new WeakMap();

/**
 * Servo
 * @constructor
 *
 * @param {Object} opts Options: pin, type, id, range
 */
function Servo( opts ) {

  if ( !(this instanceof Servo) ) {
    return new Servo( opts );
  }

  opts = Board.options( opts );

  // Hardware instance properties
  this.board = Board.mount( opts );
  this.firmata = this.board.firmata;
  this.mode = this.firmata.MODES.SERVO;
  this.pin = opts.pin;

  // If pin is not a PWM pin, emit an error
  if ( !Board.Pin.isPWM(this.pin) ) {
    this.emit( "error", this.pin + "is not a valid PWM pin" );
  }

  // Servo instance properties
  this.range = opts.range || [ 0, 180 ];

  // Allow user defined ids, defaults to system ID
  this.id = opts.id || Board.uid();

  // The type of servo determines certain alternate
  // behaviours in the API
  this.type = opts.type || "standard";

  // Collect all movement history for this servo
  this.history = [/*
    {
      timestamp: Date.now(),
      degrees: degrees
    }
  */];

  // Interval/Sweep pointer
  this.interval = null;

  this.isMoving = false;

  // Set the pin to INPUT mode
  this.firmata.pinMode( this.pin, this.mode );

  // Create a non-writable "last" property
  // shortcut to access the last servo movement
  Object.defineProperty( this, "last", {
    get: function() {
      return this.history[ this.history.length - 1 ];
    }
  });

  // Allow "setup"instructions to come from
  // constructor options properties

  // If "startAt" is defined and center is falsy
  // set servo to min or max degrees
  if ( opts.startAt !== undefined && !opts.center ) {
    this.move( opts.startAt );
  }

  // If "center" true set servo to 90deg
  if ( opts.center ) {
   this.center();
  }

  // Create a "state" entry for privately
  // storing the state of the servos
  servos.push( this );
  states.push( {} );
}

util.inherits( Servo, events.EventEmitter );

/**
 * move Move the servo horn N degrees
 *       Optionally fire a move event
 *
{'fraction_non_alphanumeric': 0.13675031901318588, 'fraction_numerical': 0.004253509145044662, 'mean_word_length': 2.657076205287714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1244041', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1489, 'n_words': 478}