<commit_before>/* COLOR CHANGING NIGHT LIGHT
 * Remote control script
 *
 * <NAME>, 2016
 * <EMAIL>
 * https://github.com/somacdivad/puckjs-nightlight
 *
 * Control the color changing night light via a second Puck.js and UART
 */

const _NAME = 'Puck.js 9fb2';  // name of the puck to be controlled
const _SENSE_INTERVAL = 1000;  // time between light sensor readings
const _SENSE_TRIGGER = 0.1;    // light trigger intensity for toggling night light on/off

var uart = require('ble_simple_uart'),
    ambTimeout = false,
    on = false;

// function for sending toggleLights command to remote puck via UART
function sendToggle() {
  try {
    NRF.requestDevice({ filters: [{ name: _NAME }] }).then((dev) => {
      uart.write(dev, 'toggleLights()\r');
    }).then(() => {
      on = !on;
      ambientSense();
    }).catch((e) => {
      console.log('error', e);
      ambientSense();
    });
  } catch (e) {
    console.log('error', e);
    ambientSense();
  }
}

// function for starting ambient light sensor
// returns a reference to an interval set by setInterval
function ambientSense() {
  ambTimeout = setInterval(() => {
    var l = Puck.light(),
        turnOn = (l <= _SENSE_TRIGGER) && !on,
        turnOff = (l > _SENSE_TRIGGER) && on;
    if (turnOn || turnOff) {
      if (ambTimeout) clearInterval(ambTimeout);
      sendToggle();
    }
  }, _SENSE_INTERVAL);
}<commit_msg>Updated auto sense<commit_after>/* COLOR CHANGING NIGHT LIGHT
 * Auto sense script
 *
 * <NAME>, 2016
 * <EMAIL>
 * https://github.com/somacdivad/puckjs-nightlight
 *
 * Control the color changing night light via a second Puck.js and UART
 * utilizing the pucks light sensor to trigger the night light based on
 * ambient light intensity.
 */

const _NAME = 'Puck.js 9fb2';  // name of the puck to be controlled
const _SENSE_INTERVAL = 1000;  // time between light sensor readings
const _SENSE_TRIGGER = 0.1;    // light trigger intensity for toggling night light on/off

var uart = require('ble_simple_uart'),
    ambTimeout = false,
    on = false;

// function for sending toggleLights command to remote puck via UART
function sendToggle() {
  try {
    NRF.requestDevice({ filters: [{ name: _NAME }] }).then((dev) => {
      uart.write(dev, 'toggleLights()\r');
    }).then(() => {
      on = !on;
      ambientSense();
    }).catch((e) => {
      console.log('error', e);
      ambientSense();
    });
  } catch (e) {
    console.log('error', e);
    ambientSense();
  }
}

// function for starting ambient light sensor
function ambientSense() {
  ambTimeout = setInterval(() => {
    var l = Puck.light(),
        turnOn = (l <= _SENSE_TRIGGER) && !on,
        turnOff = (l > _SENSE_TRIGGER) && on;
    if (turnOn || turnOff) {
      if (ambTimeout) clearInterval(ambTimeout);
      sendToggle();
    }
  }, _SENSE_INTERVAL);
}
{'fraction_non_alphanumeric': 0.13855421686746988, 'fraction_numerical': 0.008504606661941885, 'mean_word_length': 3.0271041369472185, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '7450963', 'n_tokens_mistral': 947, 'n_tokens_neox': 914, 'n_words': 272}