<commit_before>var POWERMATE_VENDOR_ID = 1917; //0x077d;
var POWERMATE_PRODUCT_ID = 1040; //0x0410;
var DEVICE_INFO = {"vendorId": POWERMATE_VENDOR_ID, "productId": POWERMATE_PRODUCT_ID};

var powerMateDevice;
var knob = document.getElementById('knob');
var requestButton = document.getElementById("requestPermission");

var amount = 0;
var ROTATE_DEGREE = 4;

var transfer = {
  direction: 'in',
  endpoint: 1,
  length: 6
};

var onEvent = function(usbEvent) {
    
    if (usbEvent.resultCode) {
      console.log("Error: " + usbEvent.error);
      return;
    }

    var dv = new DataView(usbEvent.data);
    var knobState = {
      _ledStatus: dv.getUint8(4),
      buttonState: dv.getUint8(0),
      knobDisplacement: dv.getInt8(1),
      ledBrightness: dv.getUint8(3),
      pulseEnabled: (dv.getUint8(4) & 1) == 1,
      pulseWhileAsleep: (dv.getUint8(4) & 4) == 4,
      pulseSpeed: null,
      pulseStyle: null,
      ledMultiplier: dv.getUint8(5)
    };

    knobState.pulseSpeed = pulseDescriptionFromStatusByte(
      knobState, ["slower", "normal", "faster"], 4);

    knobState.pulseStyle = pulseDescriptionFromStatusByte(
      knobState, ["style1", "style2", "style3"], 6);

    var transform = '';
    if (knobState.buttonState == 1) {
      transform = 'scale(0.5) ';
    }

    amount += (knobState.knobDisplacement * ROTATE_DEGREE);
    transform += 'rotate(' + amount + 'deg)';
    knob.style.webkitTransform = transform;
    
    console.log("RotateEvent", knobState);

    chrome.usb.interruptTransfer(powerMateDevice, transfer, onEvent);
};

var pulseDescriptionFromStatusByte = function(knobState, descriptions, offset)
{
  if(descriptions && offset >= 0 && offset < 8)
  {
    var index = (knobState._ledStatus >> offset) & 3;
    if(descriptions.length > index)
    {
      return descriptions[index];
    }
  }

  return "";
};

var gotPermission = function(result) {
    requestButton.style.display = 'none';
    knob.style.display = 'block';
    console.log('App was granted the "usbDevices" permission.');<commit_msg>Match coding style. Return 'unknown' for unmatched input<commit_after>var POWERMATE_VENDOR_ID = 1917; //0x077d;
var POWERMATE_PRODUCT_ID = 1040; //0x0410;
var DEVICE_INFO = {"vendorId": POWERMATE_VENDOR_ID, "productId": POWERMATE_PRODUCT_ID};

var powerMateDevice;
var knob = document.getElementById('knob');
var requestButton = document.getElementById("requestPermission");

var amount = 0;
var ROTATE_DEGREE = 4;

var transfer = {
  direction: 'in',
  endpoint: 1,
  length: 6
};

var onEvent = function(usbEvent) {
    
    if (usbEvent.resultCode) {
      console.log("Error: " + usbEvent.error);
      return;
    }

    var dv = new DataView(usbEvent.data);
    var knobState = {
      _ledStatus: dv.getUint8(4),
      buttonState: dv.getUint8(0),
      knobDisplacement: dv.getInt8(1),
      ledBrightness: dv.getUint8(3),
      pulseEnabled: (dv.getUint8(4) & 1) == 1,
      pulseWhileAsleep: (dv.getUint8(4) & 4) == 4,
      pulseSpeed: null,
      pulseStyle: null,
      ledMultiplier: dv.getUint8(5)
    };

    knobState.pulseSpeed = pulseDescriptionFromStatusByte(
      knobState, ["slower", "normal", "faster"], 4);

    knobState.pulseStyle = pulseDescriptionFromStatusByte(
      knobState, ["style1", "style2", "style3"], 6);

    var transform = '';
    if (knobState.buttonState == 1) {
      transform = 'scale(0.5) ';
    }

    amount += (knobState.knobDisplacement * ROTATE_DEGREE);
    transform += 'rotate(' + amount + 'deg)';
    knob.style.webkitTransform = transform;
    
    console.log("RotateEvent", knobState);

    chrome.usb.interruptTransfer(powerMateDevice, transfer, onEvent);
  };

var pulseDescriptionFromStatusByte = function(knobState, descriptions, offset) {
    if(descriptions && offset >= 0 && offset < 8) {
      var index = (knobState._ledStatus >> offset) & 3;
      if(descriptions.length > index) {
        return descriptions[index];
      }
    }

    return "unknown";
  };

var gotPermission = function(result) {
    requestButton.style.display = 'none';
    knob.style.display = 'block';
    console.log('App was granted the "usbDevices" permission.');
{'fraction_non_alphanumeric': 0.1372596153846154, 'fraction_numerical': 0.02403846153846154, 'mean_word_length': 3.5277475516866157, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 11, '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': '1408334', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1392, 'n_words': 287}