<commit_before>var oFS = require("fs");
var oGPIO = require("pi-gpio");
var oPWM = require("pi-blaster.js");
var oExec = require("child_process").exec;


module.exports = {

  // ATTRIBUTES -----------------------------------------------------------------
  bReady: false,
  sPIGPIOD: "/dev/pigpio",
  oESC: {}, // contains object -> pin_id: {...}
  
  // CONSTANTS -----------------------------------------------------------------
  

  // FUNCTION -----------------------------------------------------------------
  // initialize ESC
  init: function(aESC){
    // build ESC object
    for(var lIndex in aESC){
      this.oESC[aESC[lIndex]] = {lValue: 1000};
    }
    this.setAllESC(1000);
  },
  
  // FUNCTION
  // check for faulty values
  checkFaultyValue: function(lValue){
    if(lValue < 1000)
      return 1000;
    else if(lValue > 2000)
      return 2000;
    else
      return lValue;
  },
  
  // FUNCTION
  // set PWM of all initialized ESC's
  setAllESC: function(lValue){
    if(typeof lValue != "undefined")
      lValue = this.checkFaultyValue(lValue);
    var sValue = "";
    for(var lIndex in this.oESC){
      if(typeof lValue == "undefined")
        lValue = this.oESC[lIndex].lValue;
      else
        this.oESC[lIndex].lValue = lValue;
      sValue += "s " + lIndex + " " + lValue + " ";
    }
    this.writePIGPIOD(sValue, function(oErr){ if(!oErr) return; console.log("[ESC] -> "); console.log(oErr); });
  },
  
  // FUNCTION
  // set PWM of multiple ESC's
  setMultipleESC: function(aESC, lValue){
    lValue = this.checkFaultyValue(lValue);
    var sValue = "";
    for(var lIndex in aESC){
      this.oESC[aESC[lIndex]].lValue = lValue;
      sValue += "s " + aESC[lIndex] + " " + lValue;
    }
    this.writePIGPIOD(sValue, function(oErr){ if(!oErr) return; console.log("[ESC] -> "); console.log(oErr); });
  },
  
  // FUNCTION
  // set PWM of ESC
  setESC: function(lPin, lValue){
    lValue = this.checkFaultyValue(lValue);
    this.oESC[lPin].lValue = lValue;
    this.writePIGPIOD("s " + lPin + " " + lValue, function(oErr){ if(!oErr) return; console.log("[ESC] -> "); console.log(oErr); });
  },
  
  // FUNCTION
  // stop ESC
  stopESC: function(lPin){
    this.setESC(lPin, 1000);
  },
  
  // FUNCTION
  // stop all ESC's
  stopAllESC: function(){<commit_msg>transfer push<commit_after>var oFS = require("fs");
var oGPIO = require("pi-gpio");
var oPWM = require("pi-blaster.js");
var oExec = require("child_process").exec;


module.exports = {

  // ATTRIBUTES -----------------------------------------------------------------
  bReady: false,
  sPIGPIOD: "/dev/pigpio",
  oESC: {}, // contains object -> pin_id: {...}
  
  // CONSTANTS -----------------------------------------------------------------
  

  // FUNCTION -----------------------------------------------------------------
  // initialize ESC
  init: function(aESC){
    // build ESC object
    for(var lIndex in aESC){
      this.oESC[aESC[lIndex]] = {lValue: 1000};
    }
    this.setAllESC(1000);
  },
  
  // FUNCTION
  // check for faulty values
  checkFaultyValue: function(lValue){
    if(lValue < 1000)
      return 1000;
    else if(lValue > 2000)
      return 2000;
    else
      return lValue;
  },
  
  // FUNCTION
  // set PWM of all initialized ESC's
  setAllESC: function(lValue){
    console.log(lValue);
    if(typeof lValue != "undefined")
      lValue = this.checkFaultyValue(lValue);
    console.log(lValue);
    var sValue = "";
    for(var lIndex in this.oESC){
      console.log(lValue);
      if(typeof lValue == "undefined")
        lValue = this.oESC[lIndex].lValue;
      else
        this.oESC[lIndex].lValue = lValue;
      console.log(lValue);
      sValue += "s " + lIndex + " " + lValue + " ";
    }
    this.writePIGPIOD(sValue, function(oErr){ if(!oErr) return; console.log("[ESC] -> "); console.log(oErr); });
  },
  
  // FUNCTION
  // set PWM of multiple ESC's
  setMultipleESC: function(aESC, lValue){
    lValue = this.checkFaultyValue(lValue);
    var sValue = "";
    for(var lIndex in aESC){
      this.oESC[aESC[lIndex]].lValue = lValue;
      sValue += "s " + aESC[lIndex] + " " + lValue + " ";
    }
    this.writePIGPIOD(sValue, function(oErr){ if(!oErr) return; console.log("[ESC] -> "); console.log(oErr); });
  },
  
  // FUNCTION
  // set PWM of ESC
  setESC: function(lPin, lValue){
    lValue = this.checkFaultyValue(lValue);
    this.oESC[lPin].lValue = lValue;
    this.writePIGPIOD("s " + lPin + " " + lValue, function(oErr){ if(!oErr) return; console.log("[ESC] -> "); console.log(oErr); });
  },
  
  // FUNCTION
  // stop ESC
  stopESC: function(lPin){
    this.setESC(lPin, 1000);
  },
  
  // FUNCTION
  // stop all ESC's
  stopAllESC: function(){
{'fraction_non_alphanumeric': 0.23515691263782867, 'fraction_numerical': 0.011874469889737066, 'mean_word_length': 2.017914267434421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1909375', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1649, 'n_words': 320}