<commit_before>'use strict';
var __ = require('underscore'), usb = require('usb');
var DCDriver = {};

DCDriver.DEVICE_CONSTANTS = require('./device_constants.js');

DCDriver.turnOnDebugMode = function(){ 
  usb.setDebugLevel(4);
};

DCDriver.turnOffDebugMode = function(){
  usb.setDebugLevel(0);
}


var launcher = usb.findByIds(DCDriver.DEVICE_CONSTANTS.ID.VENDOR, DCDriver.DEVICE_CONSTANTS.ID.PRODUCT);

if (!launcher) {
  throw 'Launcher not found - make sure your Thunder Missile Launcher is plugged in to a USB port';
}

launcher.open();

var launcherInterface = launcher.interface(0);
if (launcherInterface.isKernelDriverActive()) {
  launcherInterface.detachKernelDriver();
}
// comment out the claim function since it's problematic in mac OS
// launcherInterface.claim();

process.on('exit', function(){
  launcherInterface.release();
  console.log("Released usb interface");
  // launcher.close();
  // console.log("Close usb");
});

// duration in ms
function signal(cmd, duration, callback) {
  launcher.controlTransfer(0x21, 0x09, 0x0, 0x0, new Buffer([0x02, cmd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
      function (data) {
        if (__.isNumber(duration)) {
          __.delay(__.isFunction(callback) ? callback : function(){ DCDriver.stop() }, duration);
        }
      }
  );
}

function trigger(callback, p1, p2) {
  return function () {
    callback(p1, p2);
  };
}


DCDriver.moveUp = function (duration, callback) {
  signal(DCDriver.DEVICE_CONSTANTS.CMD.UP, duration, callback);<commit_msg>fixed unexpected behaviour of movement api, will call stop given positive duration<commit_after>'use strict';
var __ = require('underscore'), usb = require('usb');
var DCDriver = {};

DCDriver.DEVICE_CONSTANTS = require('./device_constants.js');

DCDriver.turnOnDebugMode = function(){ 
  usb.setDebugLevel(4);
};

DCDriver.turnOffDebugMode = function(){
  usb.setDebugLevel(0);
}


var launcher = usb.findByIds(DCDriver.DEVICE_CONSTANTS.ID.VENDOR, DCDriver.DEVICE_CONSTANTS.ID.PRODUCT);

if (!launcher) {
  throw 'Launcher not found - make sure your Thunder Missile Launcher is plugged in to a USB port';
}

launcher.open();

var launcherInterface = launcher.interface(0);
if (launcherInterface.isKernelDriverActive()) {
  launcherInterface.detachKernelDriver();
}
// comment out the claim function since it's problematic in mac OS
// launcherInterface.claim();

process.on('exit', function(){
  launcherInterface.release();
  console.log("Released usb interface");
  // launcher.close();
  // console.log("Close usb");
});

// duration in ms
function signal(cmd, duration, callback) {
  launcher.controlTransfer(0x21, 0x09, 0x0, 0x0, new Buffer([0x02, cmd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
      function (data) {
        if (!__.isNumber(duration)) return;
        if (duration <= 0) {
          if (__.isFunction(callback)) callback();
          return;
        }

        __.delay(function(){ 
          if(__.isFunction(callback)) callback();
          DCDriver.stop();
        }, duration);
      }
  );
}

function trigger(callback, p1, p2) {
  return function () {
    callback(p1, p2);
  };
}


DCDriver.moveUp = function (duration, callback) {
  signal(DCDriver.DEVICE_CONSTANTS.CMD.UP, duration, callback);
{'fraction_non_alphanumeric': 0.14382716049382716, 'fraction_numerical': 0.023765432098765433, 'mean_word_length': 4.144444444444445, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '5458714', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1047, 'n_words': 240}