<commit_before>/**
 This Source Code is licensed under the MIT license. If a copy of the
 MIT-license was not distributed with this file, You can obtain one at:
 http://opensource.org/licenses/mit-license.html.
 @author: <NAME> (manueloverdijk)
 @license MIT
 @copyright <NAME>, 2015
 */

"use strict"

var Communicator = require('../communicator/communicator');
var EventEmitter = require("events").EventEmitter;

class Armband extends EventEmitter {

    get peripheral(){return this._peripheral}
    set peripheral(value){this._peripheral = value}

    get UUID(){return this.uuid;}
    set UUID(value){this.uuid = UUID}

    get communicator(){return this._communicator}
    set communicator(value){this._communicator = value}

    constructor(peripheral){
        this._peripheral = peripheral;
        this._communicator = new Communicator(peripheral);
    }

    /**
     *
     */
    connect(){
        if (this.peripheral.state === 'connected') {
            this.setConnected(true);
        } else {
            this.peripheral.connect();
            this.setConnected(false);

            this.peripheral.on('connect', function(){

                this.uuid = this.peripheral.uuid;

                console.log('advertisement', this.peripheral.advertisement);
                this.setConnected(true);

            }.bind(this));
        }

    }

    /**
     * Start the communication and handle EventData/IMUData
     */
    initStart(){
        if(this.isConnected()){
            this.communicator.initStart(function(eventData){

                //console.log('received Event:', eventData);
                if(eventData.ready != undefined){
                  this.setReady(eventData.ready);
                }

                if(eventData.emgData){
                    this.emit('emg', eventData);
                }

                // IMU data
                if(eventData.orientation){
                    // TODO: Sample EventData
                    this.emit('orientation',eventData.orientation);
                }
                if(eventData.accelerator){
                    // TODO: Sample EventData
                    this.emit('accelerator',eventData.accelerator)
                }
                if(eventData.gyroscope){
                    // TODO: Sample EventData
                    this.emit('gyroscope',eventData.gyroscope)
                }
                // Classifier data
                else if (eventData.type) {
                    if (eventData.type == 3) {
                        console.log('eventData.pose');
                        switch(eventData.pose){
                            case 0:
                                this.emit('pose',{type:'rest'});
                                break;
                            case 1:
                                this.emit('pose',{type:'fist'});
                                break;
                            case 2:
                                this.emit('pose', {type:'waveIn'});
                                break;
                            case 3:
                                this.emit('pose', {type:'waveOut'});
                                break;
                            case 4:
                                this.emit('pose', {type:'spread'});
                                break;
                            case 5:
                                this.emit('pose', {type:'tap'});
                                break;
                            case 255:
                                this.emit('pose',{type:'unkown'});
                        }
                    }
                    // TODO: SWitch case
                    else if (eventData.type == 1) {
                        console.log('arm synced!');
                        this.emit('sync', true);
                    }
                    // arm unsynced
                    else if (eventData.type == 2) {
                        console.log('arm unsynced');
                        this.emit('sync', false);
                    } else if(eventData.type == 6) {
                        console.log('arm sync failed');
                        this.emit('sync', eventData.sync_result);
                    } else if(eventData.type == 5) {
                        console.log('locked');
                        this.emit('unlocked', false);
                    } else if(eventData.type == 4) {
                        console.log('unlocked');
                        this.emit('unlocked', true);
                    }
                }
            }.bind(this));
        }
    }

    /**
     * readInfo
     */
    readInfo(){
        if(this.isConnected()){
            this.communicator.readInfo(function(data){
                console.log('in the function callback', data);
                this.emit('info',data);<commit_msg>Cleanup<commit_after>/**
 This Source Code is licensed under the MIT license. If a copy of the
 MIT-license was not distributed with this file, You can obtain one at:
 http://opensource.org/licenses/mit-license.html.
 @author: <NAME> (manueloverdijk)
 @license MIT
 @copyright <NAME>, 2015
 */

"use strict"

var Communicator = require('../communicator/communicator');
var EventEmitter = require("events").EventEmitter;

class Armband extends EventEmitter {

    get peripheral(){return this._peripheral}
    set peripheral(value){this._peripheral = value}

    get UUID(){return this.uuid;}
    set UUID(value){this.uuid = UUID}

    get communicator(){return this._communicator}
    set communicator(value){this._communicator = value}

    constructor(peripheral){
        this._peripheral = peripheral;
        this._communicator = new Communicator(peripheral);
    }

    /**
     *
     */
    connect(){
        if (this.peripheral.state === 'connected') {
            this.setConnected(true);
        } else {
            this.peripheral.connect();
            this.setConnected(false);

            this.peripheral.on('connect', function(){

                this.uuid = this.peripheral.uuid;
                this.setConnected(true);

            }.bind(this));
        }

    }

    /**
     * Start the communication and handle EventData/IMUData
     */
    initStart(){
        if(this.isConnected()){
            this.communicator.initStart(function(eventData){
                if(eventData.ready != undefined){
                  this.setReady(eventData.ready);
                }

                if(eventData.emgData){
                    this.emit('emg', eventData);
                }

                // IMU data
                if(eventData.orientation){
                    // TODO: Sample EventData
                    this.emit('orientation',eventData.orientation);
                }
                if(eventData.accelerator){
                    // TODO: Sample EventData
                    this.emit('accelerator',eventData.accelerator)
                }
                if(eventData.gyroscope){
                    // TODO: Sample EventData
                    this.emit('gyroscope',eventData.gyroscope)
                }
                // Classifier data
                else if (eventData.type) {
                    if (eventData.type == 3) {
                        switch(eventData.pose){
                            case 0:
                                this.emit('pose',{type:'rest'});
                                break;
                            case 1:
                                this.emit('pose',{type:'fist'});
                                break;
                            case 2:
                                this.emit('pose', {type:'waveIn'});
                                break;
                            case 3:
                                this.emit('pose', {type:'waveOut'});
                                break;
                            case 4:
                                this.emit('pose', {type:'spread'});
                                break;
                            case 5:
                                this.emit('pose', {type:'tap'});
                                break;
                            case 255:
                                this.emit('pose',{type:'unkown'});
                        }
                    }
                    // TODO: SWitch case
                    else if (eventData.type == 1) {
                        this.emit('sync', true);
                    }
                    // arm unsynced
                    else if (eventData.type == 2) {
                        this.emit('sync', false);
                    } else if(eventData.type == 6) {
                        this.emit('sync', eventData.sync_result);
                    } else if(eventData.type == 5) {
                        this.emit('unlocked', false);
                    } else if(eventData.type == 4) {
                        this.emit('unlocked', true);
                    }
                }
            }.bind(this));
        }
    }

    /**
     * readInfo
     */
    readInfo(){
        if(this.isConnected()){
            this.communicator.readInfo(function(data){
                this.emit('info',data);
{'fraction_non_alphanumeric': 0.11197375615090213, 'fraction_numerical': 0.004155276107162383, 'mean_word_length': 1.0972254070167393, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4189651', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2123, 'n_words': 411}