<commit_before>var Board = require("../lib/board.js"),
  events = require("events"),
  util = require("util"),
  Sensor = require("../lib/sensor.js");

var priv = new Map();

function nanosleep(ns) {
  var start = process.hrtime();
  while (process.hrtime() < start + ns) {}
}

var Controllers = {
  PCA9685: {
    COMMANDS: {
      value: {
        PCA9685_MODE1: 0x0,
        PCA9685_PRESCALE: 0xFE,
        LED0_ON_L: 0x6
      }
    },
    address: {
      get: function() {
        return this.opts.address;
      }
    },
    setPWM: {
      value: function(pin, off, on) {
        if (typeof on === "undefined") {
          on = 0;
        }
        on *= 16;
        off *= 16;
        this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.LED0_ON_L + 4 * (pin), on, on >> 8, off, off >> 8]);
      }
    },
    setPin: {
      value: function(pin, value, duty, phaseShift) {
        var on = 0;

        if (value !== 0) {
          value = 255;
        }

        if (typeof duty !== "undefined") {
          value = duty;
        }

        if (typeof phaseShift !== "undefined") {
          on = phaseShift;
          value = value + on;
        }

        this.setPWM(pin, value, on);

      }
    },
    initialize: {
      value: function(opts) {

        if (!Board.Drivers) {
          Board.Drivers = {};
        }

        if (!Board.Drivers[this.opts.address]) {
          this.io.sendI2CConfig();
          Board.Drivers[this.opts.address] = {
            initialized: false
          };

          // Reset
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0x0]);
          // Sleep
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0x10]);
          // Set prescalar
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_PRESCALE, 0x3]);
          // Wake up
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0x0]);
          // Wait 5 nanoseconds for restart
          nanosleep(5);
          // Auto-increment
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0xa1]);

          // Reset all PWM values
          for (var i = 0; i < 16; i++) {
            this.setPWM(i, 0, 0);
          }

          Board.Drivers[this.opts.address] = {
            initialized: true
          };
        }
      }
    }
  }
};

var Devices = {
  NONDIRECTIONAL: {
    pins: {
      get: function() {
        return {
          pwm: this.opts.pin
        };
      }
    },
    dir: {
      value: function(speed, dir) {
        speed = speed || this.speed();
        return this;
      }
    },
    resume: {
      value: function() {
        var speed = this.speed();
        this.speed({
          speed: speed<commit_msg>Don't assign a new object to Board.Drivers[this.opts.address]<commit_after>var Board = require("../lib/board.js"),
  events = require("events"),
  util = require("util"),
  Sensor = require("../lib/sensor.js");

var priv = new Map();

function nanosleep(ns) {
  var start = process.hrtime();
  while (process.hrtime() < start + ns) {}
}

var Controllers = {
  PCA9685: {
    COMMANDS: {
      value: {
        PCA9685_MODE1: 0x0,
        PCA9685_PRESCALE: 0xFE,
        LED0_ON_L: 0x6
      }
    },
    address: {
      get: function() {
        return this.opts.address;
      }
    },
    setPWM: {
      value: function(pin, off, on) {
        if (typeof on === "undefined") {
          on = 0;
        }
        on *= 16;
        off *= 16;
        this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.LED0_ON_L + 4 * (pin), on, on >> 8, off, off >> 8]);
      }
    },
    setPin: {
      value: function(pin, value, duty, phaseShift) {
        var on = 0;

        if (value !== 0) {
          value = 255;
        }

        if (typeof duty !== "undefined") {
          value = duty;
        }

        if (typeof phaseShift !== "undefined") {
          on = phaseShift;
          value = value + on;
        }

        this.setPWM(pin, value, on);

      }
    },
    initialize: {
      value: function(opts) {

        if (!Board.Drivers) {
          Board.Drivers = {};
        }

        if (!Board.Drivers[this.opts.address]) {
          this.io.sendI2CConfig();
          Board.Drivers[this.opts.address] = {
            initialized: false
          };

          // Reset
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0x0]);
          // Sleep
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0x10]);
          // Set prescalar
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_PRESCALE, 0x3]);
          // Wake up
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0x0]);
          // Wait 5 nanoseconds for restart
          nanosleep(5);
          // Auto-increment
          this.io.sendI2CWriteRequest(this.opts.address, [this.COMMANDS.PCA9685_MODE1, 0xa1]);

          // Reset all PWM values
          for (var i = 0; i < 16; i++) {
            this.setPWM(i, 0, 0);
          }

          Board.Drivers[this.opts.address].initialized = true;
        }
      }
    }
  }
};

var Devices = {
  NONDIRECTIONAL: {
    pins: {
      get: function() {
        return {
          pwm: this.opts.pin
        };
      }
    },
    dir: {
      value: function(speed, dir) {
        speed = speed || this.speed();
        return this;
      }
    },
    resume: {
      value: function() {
        var speed = this.speed();
        this.speed({
          speed: speed
{'fraction_non_alphanumeric': 0.14262962307556185, 'fraction_numerical': 0.029021412139444345, 'mean_word_length': 1.6411214953271027, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1244023', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1902, 'n_words': 362}