<commit_before>import {HID} from 'node-hid';

const NIL = 0x00;

/**
 * Luxafor
 * @type {object}
 */
export default class Luxafor {

  constructor(pid = 62322, vid = 1240) {
    this.pid = pid;
    this.vid = vid;

    // Modes to change color in
    this.commands = {
      color: 1,
      fade: 2,
      strobe: 3,
      wave: 4
    };

    // Sides color can be applied
    this.sides = {
      both: 0xff,
      back: 0x42,
      front: 0x41
    };

    this.patterns = {
      police: 5
    };

    // Grab device
    this.device = new HID(vid, pid);
  }

  /**
   * Get timing bytes for writing
   * @author <NAME> <<EMAIL>>
   * @param  {string} command Lighting command
   * @param  {number} speed Speed value 0-255
   * @param  {number} repeat Repeat value 0-255
   * @returns {array} Three timing bytes
   */
  getTiming(command, speed = 0, repeat = 0) {
    const timingBytes = {
      color: [NIL, NIL, NIL],
      fade: [speed, NIL, NIL],
      strobe: [speed, NIL, repeat],
      wave: [NIL, repeat, speed]
    };

    return timingBytes[command];
  }

  /**
   * Write to Luxafor
   * @author <NAME> <<EMAIL>>
   * @param   {string} command Lighting command
   * @param   {string} side Side to write to
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {number} [speed] How fast or slow to change 0-255
   * @param   {number} [repeat] value 0-255
   * @returns {object} Instance
   */
  write(command = 'color', side = 'both', r, g, b, speed, repeat) {
    const baseBytes = [this.commands[command], this.sides[side], r, g, b];
    const timingBytes = this.getTiming(command, speed, repeat);

    this.device.write([
      ...baseBytes,
      ...timingBytes
    ]);

    return this;
  }

  /**
   * Change the Luxafor's color
   * @author <NAME> <<EMAIL>>
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {string} side Side to change
   * @param   {string} command Lighting mode
   * @returns {object} Instance
   */
  setColor(r, g, b, side, command) {
    this.write(command, side, r, g, b, NIL, NIL);
    return this;
  }

  /**
   * Fade to color
   * @author <NAME> <<EMAIL>>
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {number} [speed] How fast or slow to change 0-255
   * @param   {string} [side] Side to change
   * @returns {object} Instance
   */
  fadeToColor(r, g, b, speed, side = 'both') {
    this.write('fade', side, r, g, b, speed, NIL);
    return this;
  }

  /**
   * Strobe a specified color
   * @author <NAME> <<EMAIL>>
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {number} [speed] How fast or slow to change 0-255
   * @param   {number} [repeat] How fast or slow to change 0-255
   * @param   {string} [side] Side to change
   * @returns {object} Instance
   */
  strobeColor(r, g, b, speed, repeat, side = 'both') {
    this.write('strobe', side, r, g, b, speed, repeat);
    return this;
  }
}<commit_msg>Added waveColor<commit_after>import {HID} from 'node-hid';

const NIL = 0x00;

/**
 * Luxafor
 * @type {object}
 */
export default class Luxafor {

  constructor(pid = 62322, vid = 1240) {
    this.pid = pid;
    this.vid = vid;

    // Modes to change color in
    this.commands = {
      color: 1,
      fade: 2,
      strobe: 3,
      wave: 4
    };

    // Sides color can be applied
    this.sides = {
      both: 0xff,
      back: 0x42,
      front: 0x41
    };

    this.patterns = {
      police: 5
    };

    // Grab device
    this.device = new HID(vid, pid);
  }

  /**
   * Get timing bytes for writing
   * @author <NAME> <<EMAIL>>
   * @param  {string} command Lighting command
   * @param  {number} speed Speed value 0-255
   * @param  {number} repeat Repeat value 0-255
   * @returns {array} Three timing bytes
   */
  getTiming(command, speed = 0, repeat = 0) {
    const timingBytes = {
      color: [NIL, NIL, NIL],
      fade: [speed, NIL, NIL],
      strobe: [speed, NIL, repeat],
      wave: [NIL, repeat, speed]
    };

    return timingBytes[command];
  }

  /**
   * Write to Luxafor
   * @author <NAME> <<EMAIL>>
   * @param   {string} command Lighting command
   * @param   {string} side Side to write to
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {number} [speed] How fast or slow to change 0-255
   * @param   {number} [repeat] value 0-255
   * @returns {object} Instance
   */
  write(command = 'color', side = 'both', r, g, b, speed, repeat) {
    const baseBytes = [this.commands[command], this.sides[side], r, g, b];
    const timingBytes = this.getTiming(command, speed, repeat);

    this.device.write([
      ...baseBytes,
      ...timingBytes
    ]);

    return this;
  }

  /**
   * Change the Luxafor's color
   * @author <NAME> <<EMAIL>>
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {string} side Side to change
   * @param   {string} command Lighting mode
   * @returns {object} Instance
   */
  setColor(r, g, b, side, command) {
    this.write(command, side, r, g, b, NIL, NIL);
    return this;
  }

  /**
   * Fade to color
   * @author <NAME> <<EMAIL>>
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {number} [speed] How fast or slow to change 0-255
   * @param   {string} [side] Side to change
   * @returns {object} Instance
   */
  fadeToColor(r, g, b, speed, side = 'both') {
    this.write('fade', side, r, g, b, speed, NIL);
    return this;
  }

  /**
   * Strobe a specified color
   * @author <NAME> <<EMAIL>>
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {number} [speed] How fast or slow to change 0-255
   * @param   {number} [repeat] How fast or slow to change 0-255
   * @param   {string} [side] Side to change
   * @returns {object} Instance
   */
  strobeColor(r, g, b, speed, repeat, side = 'both') {
    this.write('strobe', side, r, g, b, speed, repeat);
    return this;
  }

  /**
   * Wave a specified color
   * @author <NAME> <<EMAIL>>
   * @param   {number} r Red value 0-255
   * @param   {number} g Green value 0-255
   * @param   {number} b Blue value 0-255
   * @param   {number} [speed] How fast or slow to change 0-255
   * @param   {number} [repeat] How fast or slow to change 0-255
   * @param   {string} [side] Side to change
   * @returns {object} Instance
   */
  waveColor(r, g, b, speed, repeat, side = 'both') {
    this.write('wave', side, r, g, b, speed, repeat);
    return this;
  }

}
{'fraction_non_alphanumeric': 0.14363532110091742, 'fraction_numerical': 0.03211009174311927, 'mean_word_length': 2.380329457364341, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '7167672', 'n_tokens_mistral': 2654, 'n_tokens_neox': 2458, 'n_words': 817}