<commit_before>var events = require("events"),
    child = require("child_process"),
    util = require("util"),
    colors = require("colors"),
    Firmata = require("firmata").Board,
    _ = require("lodash"),
    __ = require("../lib/fn.js"),
    Repl = require("../lib/repl.js"),
    board,
    boards,
    grep,
    Serial;


boards = [];

grep = "ls /dev | grep -iE 'usb|acm'";


/**
 * Process Codes
 * SIGHUP        1       Term    Hangup detected on controlling terminal
                              or death of controlling process
 * SIGINT        2       Term    Interrupt from keyboard
 * SIGQUIT       3       Core    Quit from keyboard
 * SIGILL        4       Core    Illegal Instruction
 * SIGABRT       6       Core    Abort signal from abort(3)
 * SIGFPE        8       Core    Floating point exception
 * SIGKILL       9       Term    Kill signal
 * SIGSEGV      11       Core    Invalid memory reference
 * SIGPIPE      13       Term    Broken pipe: write to pipe with no readers
 * SIGALRM      14       Term    Timer signal from alarm(2)
 * SIGTERM      15       Term    Termination signal
 *
 *
 *
 * http://www.slac.stanford.edu/BFROOT/www/Computing/Environment/Tools/Batch/exitcode.html
 *
 */

Serial = {
  used: [],

  detect: function( callback ) {
    var instance = this;

    this.info( "Board", "Connecting..." );
    // TODO:
    // Confirm bluetooth serial connections
    // eg. /dev/tty.RN42-1203-SPP-
    // http://www.rioleo.org/setting-up-the-arduino-pro-mini-and-bluetooth-mate-on-mac.php
    child.exec( grep, function( err, stdout, stderr ) {
      var connected, eventType, found, length, ports, usb;

      ports = stdout.slice( 0, -1 ).split("\n").filter(function( val ) {
        var available = true;

        // Originally, we filtered for "tty"
        // As it turns out, using the cu.* device path saves the program
        // from the dreaded dead-stop
        if ( !(/cu/i).test(val) ) {
          available = false;
        }

        // Don't allow already used/encountered usb device paths
        if ( Serial.used.indexOf(val) > -1 ) {
          available = false;
        }

        return available;
      });

      length = ports.length;

      // If no ports are detected when scanning /dev/, then there is
      // nothing left to do and we can safely exit the program
      if ( !length ) {
        // Alert user that no devices were detected
        this.error( "Board", "No USB devices detected" );

        // Exit the program by sending SIGABRT
        process.exit(3);

        // Return (not that it matters, but this is a good way<commit_msg>Connect to CU or TTY by platform. Fixes #19<commit_after>var os = require("os"),
    child = require("child_process"),
    events = require("events"),
    util = require("util"),
    colors = require("colors"),
    Firmata = require("firmata").Board,
    _ = require("lodash"),
    __ = require("../lib/fn.js"),
    Repl = require("../lib/repl.js"),
    board,
    boards,
    grep,
    rport,
    Serial;


boards = [];

grep = "ls /dev | grep -iE 'usb|acm'";
rport = new RegExp( os.platform() === "darwin" ? "cu" :  "tty", "i" );

/**
 * Process Codes
 * SIGHUP        1       Term    Hangup detected on controlling terminal
                              or death of controlling process
 * SIGINT        2       Term    Interrupt from keyboard
 * SIGQUIT       3       Core    Quit from keyboard
 * SIGILL        4       Core    Illegal Instruction
 * SIGABRT       6       Core    Abort signal from abort(3)
 * SIGFPE        8       Core    Floating point exception
 * SIGKILL       9       Term    Kill signal
 * SIGSEGV      11       Core    Invalid memory reference
 * SIGPIPE      13       Term    Broken pipe: write to pipe with no readers
 * SIGALRM      14       Term    Timer signal from alarm(2)
 * SIGTERM      15       Term    Termination signal
 *
 *
 *
 * http://www.slac.stanford.edu/BFROOT/www/Computing/Environment/Tools/Batch/exitcode.html
 *
 */

Serial = {
  used: [],

  detect: function( callback ) {
    var instance = this;

    this.info( "Board", "Connecting..." );
    // TODO:
    // Confirm bluetooth serial connections
    // eg. /dev/tty.RN42-1203-SPP-
    // http://www.rioleo.org/setting-up-the-arduino-pro-mini-and-bluetooth-mate-on-mac.php
    child.exec( grep, function( err, stdout, stderr ) {
      var connected, eventType, found, length, ports, usb;

      ports = stdout.slice( 0, -1 ).split("\n").filter(function( val ) {
        var available = true;

        // rport regex will test |val| string for either "cu" or "tty",
        // depending on system:
        //    darwin: cu
        //    linux: tty
        if ( !rport.test(val) ) {
          available = false;
        }

        // Don't allow already used/encountered usb device paths
        if ( Serial.used.indexOf(val) > -1 ) {
          available = false;
        }

        return available;
      });

      length = ports.length;

      // If no ports are detected when scanning /dev/, then there is
      // nothing left to do and we can safely exit the program
      if ( !length ) {
        // Alert user that no devices were detected
        this.error( "Board", "No USB devices detected" );

        // Exit the program by sending SIGABRT
        process.exit(3);

        // Return (not that it matters, but this is a good way
{'fraction_non_alphanumeric': 0.1151334204142564, 'fraction_numerical': 0.01044971076693413, 'mean_word_length': 1.8848223896663079, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7266270', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1567, 'n_words': 501}