<commit_before>"use strict";

var fluid = require("infusion"),
    gpii = fluid.registerNamespace("gpii"),
    nodeimu = require("nodeimu");

fluid.defaults("gpii.nexus.rpiSenseHat", {
    gradeNames: "fluid.component",

    readIntervalMs: 1000,

    members: {
        imu: "@expand:gpii.nexus.rpiSenseHat.constructImu()"
    },

    invokers: {
        getReading: {
            funcName: "gpii.nexus.rpiSenseHat.getReading",
            args: [
                "{that}",
                "{that}.imu",
                "{that}.options.readIntervalMs",
                "{that}.events.onReading"
            ]
        }
    },

    events: {
        onReading: null
    },

    listeners: {
        "onCreate.startReading": "{that}.getReading"
    }
});

gpii.nexus.rpiSenseHat.constructImu = function () {
    return new nodeimu.IMU();
};

gpii.nexus.rpiSenseHat.getReading = function (that, imu, readIntervalMs, onReadingEvent) {
    imu.getValue(function (e, data) {
        onReadingEvent.fire(data);
        setTimeout(function () {
            that.getReading();
        }, readIntervalMs);
    });
};

fluid.defaults("gpii.nexus.rpiSenseHatDriver", {
    gradeNames: "fluid.modelComponent",

    nexusHost: "localhost",
    nexusPort: 9081,
    nexusPeerComponentPath: "rpiSenseHatTemp",
    nexusPeerComponentOptions: {
        type: "gpii.nexus.rpiSenseHatDriver.tempSensor"
    },
    sensorName: "Temperature",

    components: {
        sense: {
            type: "gpii.nexus.rpiSenseHat",
            options: {
                listeners: {
                    "onReading.log": function (data) {
                        console.log(JSON.stringify(data, null, 4));
                    }
                }
            }
        },
        tempNexusBinding: {
            type: "gpii.nexusWebSocketBoundComponent",
            options: {
                members: {
                    nexusHost: "{rpiSenseHatDriver}.options.nexusHost",
                    nexusPort: "{rpiSenseHatDriver}.options.nexusPort",
                    nexusPeerComponentPath:
                        "{rpiSenseHatDriver}.options.nexusPeerComponentPath",
                    nexusPeerComponentOptions:
                        "{rpiSenseHatDriver}.options.nexusPeerComponentOptions",
                    nexusBoundModelPath: "sensorData",
                    sendsChangesToNexus: true,
                    managesPeer: true
                },
                model: {
                    sensorData: {
                        name: "{rpiSenseHatDriver}.options.sensorName",
                        units: "C",
                        rangeMin: 0,
                        rangeMax: 100,
                        value: 0
                    }
                },<commit_msg>GPII-2185: Adjust temperature range to 10-40<commit_after>"use strict";

var fluid = require("infusion"),
    gpii = fluid.registerNamespace("gpii"),
    nodeimu = require("nodeimu");

fluid.defaults("gpii.nexus.rpiSenseHat", {
    gradeNames: "fluid.component",

    readIntervalMs: 1000,

    members: {
        imu: "@expand:gpii.nexus.rpiSenseHat.constructImu()"
    },

    invokers: {
        getReading: {
            funcName: "gpii.nexus.rpiSenseHat.getReading",
            args: [
                "{that}",
                "{that}.imu",
                "{that}.options.readIntervalMs",
                "{that}.events.onReading"
            ]
        }
    },

    events: {
        onReading: null
    },

    listeners: {
        "onCreate.startReading": "{that}.getReading"
    }
});

gpii.nexus.rpiSenseHat.constructImu = function () {
    return new nodeimu.IMU();
};

gpii.nexus.rpiSenseHat.getReading = function (that, imu, readIntervalMs, onReadingEvent) {
    imu.getValue(function (e, data) {
        onReadingEvent.fire(data);
        setTimeout(function () {
            that.getReading();
        }, readIntervalMs);
    });
};

fluid.defaults("gpii.nexus.rpiSenseHatDriver", {
    gradeNames: "fluid.modelComponent",

    nexusHost: "localhost",
    nexusPort: 9081,
    nexusPeerComponentPath: "rpiSenseHatTemp",
    nexusPeerComponentOptions: {
        type: "gpii.nexus.rpiSenseHatDriver.tempSensor"
    },
    sensorName: "Temperature",

    components: {
        sense: {
            type: "gpii.nexus.rpiSenseHat",
            options: {
                listeners: {
                    "onReading.log": function (data) {
                        console.log(JSON.stringify(data, null, 4));
                    }
                }
            }
        },
        tempNexusBinding: {
            type: "gpii.nexusWebSocketBoundComponent",
            options: {
                members: {
                    nexusHost: "{rpiSenseHatDriver}.options.nexusHost",
                    nexusPort: "{rpiSenseHatDriver}.options.nexusPort",
                    nexusPeerComponentPath:
                        "{rpiSenseHatDriver}.options.nexusPeerComponentPath",
                    nexusPeerComponentOptions:
                        "{rpiSenseHatDriver}.options.nexusPeerComponentOptions",
                    nexusBoundModelPath: "sensorData",
                    sendsChangesToNexus: true,
                    managesPeer: true
                },
                model: {
                    sensorData: {
                        name: "{rpiSenseHatDriver}.options.sensorName",
                        units: "C",
                        rangeMin: 10,
                        rangeMax: 40,
                        value: 25
                    }
                },
{'fraction_non_alphanumeric': 0.11345598845598845, 'fraction_numerical': 0.006673881673881674, 'mean_word_length': 1.5435779816513762, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '3517230', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1596, 'n_words': 219}