<commit_before>var EventEmitter = require('events').EventEmitter;

var hardware = module.exports = new EventEmitter();
//var e = nobleEmitter.connect(peripheralUuid, serviceUuid, characteristicUuid);

var e = (process.env.DEVICE) ?
          require('./serialport')(process.env.DEVICE) :
          require('./stdin-mock');

var commands = {
  0: function () {
    emitScore('a');
  },
  1: function () {
    emitScore('b');
  },
  2: function () {
    emitUndo('a');
  },
  3: function () {
    emitUndo('b');
  },
  4: function () {
    hardware.emit('restart');
  }
};

e.on('connected', function () {
  console.log('ble connected');
  hardware.emit('connected');
});

e.on('data', function (data) {
  console.log('data: ', data);
  if(commands[data])
    commands[data]();
  else
    console.log('unknown command "' + data + '"');
});

e.on('disconnected', function () {
  console.log('ble disconnected');
  hardware.emit('disconnected');
});

function emitScore (side) {
  hardware.emit('score', { side: side });
}

function emitUndo (side) {
  hardware.emit('undo', { side: side });
}<commit_msg>Add command to allow reset with longpress on both a and b.<commit_after>var EventEmitter = require('events').EventEmitter;

var hardware = module.exports = new EventEmitter();
//var e = nobleEmitter.connect(peripheralUuid, serviceUuid, characteristicUuid);

var e = (process.env.DEVICE) ?
          require('./serialport')(process.env.DEVICE) :
          require('./stdin-mock');

var commands = {
  0: function () {
    emitScore('a'); // single click
  },
  1: function () {
    emitScore('b'); // single click
  },
  2: function () {
    emitUndo('a'); // double click
  },
  3: function () {
    emitUndo('b'); // double click
  },
  4: function () {
    hardware.emit('restart'); // long press
  },
  5: function () {
    hardware.emit('restart'); // long press
  }
};

e.on('connected', function () {
  console.log('ble connected');
  hardware.emit('connected');
});

e.on('data', function (data) {
  console.log('data: ', data);
  if(commands[data])
    commands[data]();
  else
    console.log('unknown command "' + data + '"');
});

e.on('disconnected', function () {
  console.log('ble disconnected');
  hardware.emit('disconnected');
});

function emitScore (side) {
  hardware.emit('score', { side: side });
}

function emitUndo (side) {
  hardware.emit('undo', { side: side });
}
{'fraction_non_alphanumeric': 0.1968240702047639, 'fraction_numerical': 0.00459674049310489, 'mean_word_length': 3.568702290076336, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1256170', 'n_tokens_mistral': 770, 'n_tokens_neox': 783, 'n_words': 162}