<commit_before>
/****************************************************************************
 LICENSE: CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
 This is an original driver by <NAME> <<EMAIL>>
 It is free to use in other projects for non-commercial purposes.  For a
 commercial license and consulting, please contact <EMAIL>
*****************************************************************************/

var util = require('util');
var async = require('async');
var EventEmitter = require('events').EventEmitter;

var trafficLog = true;

function Ronin(id) {
    this.btServiceIds = ['fff0'];

    this._id = id;
    this._cmdCh = null;
    this._notifyCh = null;
    this._dev = null;
    this._buf = null;
    this._moving = false;
    this._angle = null;
    this._expectedLength = 0;
    this._posTimer = null;
    this.pan = 0;
    this.tilt = 0;
    this.roll = 0;
    this.reportedPan = null;
    this.reportedTilt = null;
    this.reportedRoll = null;
    this._stepsPerDegree = 1;
    this._backlash = 0;
    this._lastDirection = 0;
    this._commandIndex = 0;
}

util.inherits(Ronin, EventEmitter);


Ronin.prototype._connectBt = function(btPeripheral, callback) {
    var self = this;
    btPeripheral.connect(function(err1) {
        if (err1) {
            if (callback) callback(false);
            return;
        }
        console.log('Ronin(' + self._id + '): connecting via BLE');
        setTimeout(function(){
            btPeripheral.discoverServices(['fff0'], function(err2, services) {
                if (services && services[0]) {
                    services[0].discoverCharacteristics([], function(err, characteristics) {
                        self._notifyCh = null;
                        self._cmdCh = null;
                        self._dev = null;
                        for(var i = 0; i < characteristics.length; i++) {
                            var ch = characteristics[i];
                            if(ch.uuid == 'fff4') {
                                self._notifyCh = ch;
                            }

                            if(ch.uuid == 'fff5') {
                                self._cmdCh = ch;
                            }
                        }
                        if (self._notifyCh && self._cmdCh) {
                            try {
                                self._notifyCh.subscribe(function(){
                                    console.log('Ronin(' + self._id + "):subscribed...");
                                    self._expectedLength = 0;
                                    self._buf = null;
                                    self._dev = btPeripheral;
                                    self._dev.connected = true;
                                    self.connected = true;
                                    self._dev.type = "bt";
                                    self._posTimer = null;
                                    self._commandIndex = 0;
                                    self._notifyCh.on('data', function(data, isNotification) {
                                        self._parseIncoming(data);
                                    });
                                    console.log("Ronin(" + self._id + "): connected!");
                                    self._init();
                                    if (callback) callback(true);
                                });
                            } catch(err3) {
                                btPeripheral.disconnect();
                                console.log("Ronin(" + self._id + "): exception while connecting: ", err3);
                                if (callback) callback(false);
                            }
                        } else {
                            console.log("Ronin(" + self._id + "): couldn't locate characteristics, disconnecting... ", err);
                            btPeripheral.disconnect();
                            if (callback) callback(false);
                        }
                        //console.log("characteristics:", characteristics);
                    });
                }
            });
        }, 1000);

        btPeripheral.once('disconnect', function() {
            console.log("Ronin(" + self._id + "): disconnected");
            self._dev = null;
            self.connected = false;
            self._moving = false;
            clearTimeout(self._posTimer);
            clearTimeout(self._pollTimer);
            self.emit("status", self.getStatus());
        });

    });
}

Ronin.prototype._pollPositions = function(self) {
    if(self._pollTimer) clearTimeout(self._pollTimer);
    self._write(new Buffer("048a02e500004004126624c01d00001c103e010300008c0e0050", 'hex'));
    self._write(new Buffer("046602e5000080000e00", 'hex'), function(err) {
        if(self.connected) self._pollTimer = setTimeout(function() {
            self._pollPositions(self);
        }, 2000);<commit_msg>ronin s testing<commit_after>
/****************************************************************************
 LICENSE: CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
 This is an original driver by <NAME> <<EMAIL>>
 It is free to use in other projects for non-commercial purposes.  For a
 commercial license and consulting, please contact <EMAIL>
*****************************************************************************/

var util = require('util');
var async = require('async');
var EventEmitter = require('events').EventEmitter;

var trafficLog = true;

function Ronin(id) {
    this.btServiceIds = ['fff0'];

    this._id = id;
    this._cmdCh = null;
    this._notifyCh = null;
    this._dev = null;
    this._buf = null;
    this._moving = false;
    this._angle = null;
    this._expectedLength = 0;
    this._posTimer = null;
    this.pan = 0;
    this.tilt = 0;
    this.roll = 0;
    this.reportedPan = null;
    this.reportedTilt = null;
    this.reportedRoll = null;
    this._stepsPerDegree = 1;
    this._backlash = 0;
    this._lastDirection = 0;
    this._commandIndex = 0;
}

util.inherits(Ronin, EventEmitter);


Ronin.prototype._connectBt = function(btPeripheral, callback) {
    var self = this;
    btPeripheral.connect(function(err1) {
        if (err1) {
            if (callback) callback(false);
            return;
        }
        console.log('Ronin(' + self._id + '): connecting via BLE');
        setTimeout(function(){
            btPeripheral.discoverServices(['fff0'], function(err2, services) {
                if (services && services[0]) {
                    services[0].discoverCharacteristics([], function(err, characteristics) {
                        self._notifyCh = null;
                        self._cmdCh = null;
                        self._dev = null;
                        for(var i = 0; i < characteristics.length; i++) {
                            var ch = characteristics[i];
                            if(ch.uuid == 'fff4') {
                                self._notifyCh = ch;
                            }

                            if(ch.uuid == 'fff5') {
                                self._cmdCh = ch;
                            }
                        }
                        if (self._notifyCh && self._cmdCh) {
                            try {
                                self._notifyCh.subscribe(function(){
                                    console.log('Ronin(' + self._id + "):subscribed...");
                                    self._expectedLength = 0;
                                    self._buf = null;
                                    self._dev = btPeripheral;
                                    self._dev.connected = true;
                                    self.connected = true;
                                    self._dev.type = "bt";
                                    self._posTimer = null;
                                    self._commandIndex = 0;
                                    self._notifyCh.on('data', function(data, isNotification) {
                                        self._parseIncoming(data);
                                    });
                                    console.log("Ronin(" + self._id + "): connected!");
                                    self._init();
                                    if (callback) callback(true);
                                });
                            } catch(err3) {
                                btPeripheral.disconnect();
                                console.log("Ronin(" + self._id + "): exception while connecting: ", err3);
                                if (callback) callback(false);
                            }
                        } else {
                            console.log("Ronin(" + self._id + "): couldn't locate characteristics, disconnecting... ", err);
                            btPeripheral.disconnect();
                            if (callback) callback(false);
                        }
                        //console.log("characteristics:", characteristics);
                    });
                }
            });
        }, 1000);

        btPeripheral.once('disconnect', function() {
            console.log("Ronin(" + self._id + "): disconnected");
            self._dev = null;
            self.connected = false;
            self._moving = false;
            clearTimeout(self._posTimer);
            clearTimeout(self._pollTimer);
            self.emit("status", self.getStatus());
        });

    });
}

Ronin.prototype._pollPositions = function(self) {
    if(self._pollTimer) clearTimeout(self._pollTimer);
    self._write(new Buffer("048a02e500004004126624c01d00001c103e010300008c0e0050", 'hex'));
    self._write(new Buffer("046602e5000080000e00", 'hex'), function(err) {
        if(self.connected) self._pollTimer = setTimeout(function() {
            self._pollPositions(self);
        }, 5000);
{'fraction_non_alphanumeric': 0.13988696003229714, 'fraction_numerical': 0.019378280177634235, 'mean_word_length': 1.3006733224982587, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '631171', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2347, 'n_words': 467}