<commit_before>'use strict'

let Gpio = require('onoff').Gpio
let NanoTimer = require('nanotimer')
let _ = require('underscore')
let EventEmitter = require('events').EventEmitter

class RfidReader extends EventEmitter {
  constructor(options) {
    super()
    console.log("RfidReader: Starting...")
    this.setupReader(options.pins)
    console.log("RfidReader: Started")
  }
  get type() {
    return 'RFID'
  }
  setupReader(pins) {
    this.timer = new NanoTimer()
    this.resetData()
    this.setupDataPin(pins.data_0, 0)
    // this.setupDataPin(pins.data_1, 1)
    console.log("Setup reader: ", pins)
  }
  setupDataPin(pinNumber, pinValue) {
    let pin = new Gpio(pinNumber, 'in', 'falling')
    pin.watch((err, value) => {
      this.data[this.index] = pinValue
      this.index++
      this.timer.clearTimeout()
      this.timer.setTimeout(this.check, [this], '50m')
    })
  }
  check(context) {
    let data = context.data
    let index = context.index
    context.resetData()

    // var valid = true
    // var facility = null
    // var card = null
    // if (index != 26) {
    //   valid = false // incorrect size for expected 26bit format
    // } else {
    //   facility = parseInt(data.slice(1, 9).join(''), 2)
    //   card = parseInt(data.slice(9, 25).join(''), 2)
    //   if (data[0] != (facility % 2)) valid = false // bad facility parity
    //   else if (data[25] != (card % 2)) valid = false // bad card parity
    // }
console.warn("READDDD", data.join(''))
    context.emit('read', context.type, data.join(''))
  }
  resetData() {
    this.index = 0
    this.data = new Array(100)
  }
}<commit_msg>Add support for leds/buzzer that expect to be high by default<commit_after>'use strict'

let Gpio = require('onoff').Gpio
let NanoTimer = require('nanotimer')
let _ = require('underscore')
let EventEmitter = require('events').EventEmitter

class RfidReader extends EventEmitter {
  constructor(options) {
    super()
    console.log("RfidReader: Starting...")
    this.setupReader(options.pins)
    this.setupOutputPins(options.pins)
    console.log("RfidReader: Started")
  }
  get type() {
    return 'RFID'
  }
  setupReader(pins) {
    this.timer = new NanoTimer()
    this.resetData()
    this.setupDataPin(pins.data_0, 0)
    // this.setupDataPin(pins.data_1, 1)
    console.log("Setup reader: ", pins)
  }
  setupDataPin(pinNumber, pinValue) {
    let pin = new Gpio(pinNumber, 'in', 'falling')
    pin.watch((err, value) => {
      this.data[this.index] = pinValue
      this.index++
      this.timer.clearTimeout()
      this.timer.setTimeout(this.check, [this], '50m')
    })
  }
  setupOutputPins(pins) {
    this.greenLed = this.setupOutputPin(pins.greenLed)
    this.redLed = this.setupOutputPin(pins.redLed)
    this.buzzer = this.setupOutputPin(pins.buzzer)
    this.greenLed.writeSync(1)
    this.redLed.writeSync(1)
    this.buzzer.writeSync(1)
  }
  setupOutputPin(pin) {
    return new Gpio(pin, 'out')
  }
  check(context) {
    let data = context.data
    let index = context.index
    context.resetData()

    // var valid = true
    // var facility = null
    // var card = null
    // if (index != 26) {
    //   valid = false // incorrect size for expected 26bit format
    // } else {
    //   facility = parseInt(data.slice(1, 9).join(''), 2)
    //   card = parseInt(data.slice(9, 25).join(''), 2)
    //   if (data[0] != (facility % 2)) valid = false // bad facility parity
    //   else if (data[25] != (card % 2)) valid = false // bad card parity
    // }
console.warn("READDDD", data.join(''))
    context.emit('read', context.type, data.join(''))
  }
  resetData() {
    this.index = 0
    this.data = new Array(100)
  }
}
{'fraction_non_alphanumeric': 0.1583943585570925, 'fraction_numerical': 0.014917276918904258, 'mean_word_length': 2.8336798336798337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5787493', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1272, 'n_words': 274}