ant-plus
Version:
A node module for ANT+
83 lines • 3.28 kB
JavaScript
;
/*
* Copyright (c) 2019 Tom Cosgrove
* Copyright (c) 2015 Alessandro Vergani
*
* This file is licensed under the MIT License (MIT):
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvironmentScanner = exports.EnvironmentSensor = void 0;
/*
* ANT+ profile: https://www.thisisant.com/developer/ant-plus/device-profiles/#524_tab
* Spec sheet: https://www.thisisant.com/resources/environment/
*/
const ant_1 = require("./ant");
class EnvironmentSensorState {
constructor(deviceId) {
this.DeviceID = deviceId;
}
}
class EnvironmentScanState extends EnvironmentSensorState {
}
class EnvironmentSensor extends ant_1.AntPlusSensor {
attach(channel, deviceID) {
super.attach(channel, 'receive', deviceID, EnvironmentSensor.deviceType, 0, 255, 8192);
this.state = new EnvironmentSensorState(deviceID);
}
updateState(deviceId, data) {
this.state.DeviceID = deviceId;
updateState(this, this.state, data);
}
}
exports.EnvironmentSensor = EnvironmentSensor;
EnvironmentSensor.deviceType = 25;
class EnvironmentScanner extends ant_1.AntPlusScanner {
constructor() {
super(...arguments);
this.states = {};
}
deviceType() {
return EnvironmentSensor.deviceType;
}
createStateIfNew(deviceId) {
if (!this.states[deviceId]) {
this.states[deviceId] = new EnvironmentScanState(deviceId);
}
}
updateRssiAndThreshold(deviceId, rssi, threshold) {
this.states[deviceId].Rssi = rssi;
this.states[deviceId].Threshold = threshold;
}
updateState(deviceId, data) {
updateState(this, this.states[deviceId], data);
}
}
exports.EnvironmentScanner = EnvironmentScanner;
function updateState(sensor, state, data) {
const page = data.readUInt8(ant_1.Messages.BUFFER_INDEX_MSG_DATA);
if (page === 1) {
state.EventCount = data.readUInt8(ant_1.Messages.BUFFER_INDEX_MSG_DATA + 2);
state.Temperature = data.readInt16LE(ant_1.Messages.BUFFER_INDEX_MSG_DATA + 6) / 100;
}
sensor.emit('envdata', state);
sensor.emit('envData', state);
}
//# sourceMappingURL=environment-sensors.js.map