<commit_before>'use strict';
const log = require('./logger.js').create('DOOR SENSOR');
const EventEmitter = require('events').EventEmitter;

var Gpio;
if(process.env.NODE_ENV !== 'development'){
    Gpio = require('pigpio').Gpio;
}else{
    Gpio = 
        class DebugSensor { 
            constructor(pin){
                this.pin = pin;
            }
            
            on(){}
        };
}

class DoorSensor extends EventEmitter {
    constructor(pinNumber){
        super();
        this.sensor = new Gpio(pinNumber, {   
                mode: Gpio.INPUT, 
                pullUpDown: Gpio.PUD_UP, 
                edge: Gpio.EITHER_EDGE });
        this.sensor.on('interrupt', this.onInterrupt.bind(this));
        this.timeout = null;
    }
    
    onInterrupt(){
        console.log("interrupt!");
        if(this.timeout) { return; }
        
        this.timeout = setTimeout(() => {
            var level = this.sensor.digitalRead();
            if(level == 1){
                log.write('Opened');
                this.emit('open');
            }else{
                log.write('Closed');
                this.emit('close');
            }
            this.timeout = null;
        }, 500);
    }
}

module.exports = DoorSensor;<commit_msg>Less door spam<commit_after>'use strict';
const log = require('./logger.js').create('DOOR SENSOR');
const EventEmitter = require('events').EventEmitter;

var Gpio;
if(process.env.NODE_ENV !== 'development'){
    Gpio = require('pigpio').Gpio;
}else{
    Gpio = 
        class DebugSensor { 
            constructor(pin){
                this.pin = pin;
            }
            
            on(){}
        };
}

class DoorSensor extends EventEmitter {
    constructor(pinNumber){
        super();
        this.sensor = new Gpio(pinNumber, {   
                mode: Gpio.INPUT, 
                pullUpDown: Gpio.PUD_UP, 
                edge: Gpio.EITHER_EDGE });
        this.sensor.on('interrupt', this.onInterrupt.bind(this));
        this.timeout = null;
        this.state = this.sensor.digitalRead();
    }
    
    onInterrupt(){
        console.log("interrupt!");
        if(this.timeout) { return; }
        
        this.timeout = setTimeout(() => {
            var state = this.sensor.digitalRead();
            if(state === this.state) { return; }
            
            if(state == 1){
                log.write('Opened');
                this.emit('open');
            }else{
                log.write('Closed');
                this.emit('close');
            }
            this.state = state;
            this.timeout = null;
        }, 500);
    }
}

module.exports = DoorSensor;
{'fraction_non_alphanumeric': 0.13973634651600753, 'fraction_numerical': 0.0030131826741996233, 'mean_word_length': 1.566183574879227, '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': '89367', 'n_tokens_mistral': 782, 'n_tokens_neox': 772, 'n_words': 134}