robotois-light-sensor
Advanced tools
Comparing version 1.0.2 to 1.0.3
39
index.js
@@ -14,2 +14,3 @@ const LSensor = require('bindings')('LightSensor'); | ||
this.light = new LSensor(port, add); | ||
this.prevValue = -1; | ||
@@ -34,4 +35,3 @@ process.on('SIGINT', () => { | ||
LightSensor.prototype.getBasicValue = function getBasicValue() { // Rounded | ||
const value = Math.round(this.light.getValue() * 100) / 100; | ||
return value; | ||
return this.light.getBasicValue(); | ||
}; | ||
@@ -43,27 +43,21 @@ | ||
LightSensor.prototype.getBasicScaledValue = function getBasicScaledValue() { | ||
return this.light.getBasicScaledValue(); | ||
LightSensor.prototype.publishNow = function publishNow() { | ||
this.mqttClient.publish(this.myTopic, this.light.getScaledValue().toString()); | ||
}; | ||
LightSensor.prototype.enableEvents = function enableEvents() { | ||
const self = this; | ||
let scaledValue; | ||
LightSensor.prototype.enableEvents = function enableEvents(mqttConfig) { | ||
if (mqttConfig) { | ||
this.mqttClient = mqttConfig.mqttClient; | ||
this.myTopic = `sensors/light${mqttConfig.instance}`; | ||
this.mqttClient.publish('registerTopic', this.myTopic); | ||
} | ||
if (!this.eventInterval) { | ||
this.eventInterval = setInterval(() => { | ||
scaledValue = this.light.getBasicScaledValue(); | ||
self.emit('medicion', scaledValue); | ||
}, 500); // Tomar mediciones cada 500ms | ||
} | ||
}; | ||
LightSensor.prototype.when = function when(value, callback) { | ||
if (!this.interval) { | ||
this.interval = setInterval(() => { | ||
/* eslint-disable no-console */ | ||
console.log(`Luz:${this.light.getBasicScaledValue()}`); | ||
/* eslint-disable eqeqeq */ | ||
if (this.light.getBasicScaledValue() == value) { | ||
callback(); | ||
const currentValue = this.light.getScaledValue(); | ||
this.emit('medicion', currentValue); | ||
if (this.prevValue !== currentValue && this.mqttClient) { | ||
this.mqttClient.publish(this.myTopic, currentValue.toString()); | ||
this.prevValue = currentValue; | ||
} | ||
}, 500); // Tomar mediciones cada 500ms | ||
}, 250); | ||
} | ||
@@ -73,3 +67,2 @@ }; | ||
LightSensor.prototype.release = function release() { | ||
clearInterval(this.interval); | ||
clearInterval(this.eventInterval); | ||
@@ -76,0 +69,0 @@ this.light.release(); |
{ | ||
"name": "robotois-light-sensor", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Node library for the light sensor module", | ||
@@ -23,2 +23,7 @@ "main": "index.js", | ||
], | ||
"homepage": "https://github.com/Robotois/robotois-light-sensor", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Robotois/robotois-light-sensor.git" | ||
}, | ||
"license": "ISC", | ||
@@ -25,0 +30,0 @@ "dependencies": { |
@@ -5,10 +5,9 @@ const LightSensor = require('../index'); | ||
setInterval(() => { // Proceso en estado ocioso | ||
/* eslint-disable no-console */ | ||
console.log(`Luz: ${light.getValue()}`); | ||
// console.log(`Luz: ${light.getValue().toFixed(2)}`); | ||
console.log(`BasicValue: ${light.getBasicValue()}`); | ||
/* eslint-disable no-console */ | ||
console.log(`BasicScaledValue: ${light.getBasicScaledValue()}`); | ||
// console.log(`BasicValue: ${light.getBasicValue().toFixed(2)}`); | ||
console.log(`ScaledValue: ${light.getScaledValue()}\n`); | ||
}, 1000); | ||
setInterval(() => {}, 10000); | ||
process.on('SIGTERM', () => { | ||
@@ -15,0 +14,0 @@ process.exit(); |
@@ -9,3 +9,2 @@ const LightSensor = require('../index'); | ||
}); | ||
setInterval(() => {}, 10000); | ||
@@ -12,0 +11,0 @@ process.on('SIGTERM', () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
111701
29
1
0
101
2