Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

robotois-distance-sensor

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

robotois-distance-sensor - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

docs/_sidebar.md

43

index.js

@@ -33,28 +33,24 @@ const DSensor = require('bindings')('DistanceSensor');

DistanceSensor.prototype.enableEvents = function enableEvents() {
let dist;
if (!this.eventInterval) {
this.eventInterval = setInterval(() => { // Mediciones cada 100ms
dist = this.getBasicValue();
// console.log('Distancia: ' + dist);
this.emit('value', dist);
}, 200);
}
DistanceSensor.prototype.publishNow = function publishNow() {
this.mqttClient.publish(this.myTopic, this.getBasicValue().toString());
};
DistanceSensor.prototype.distToString = function distToString(dist) {
return (` ${dist.toFixed(1).toString()}`).slice(-5);
};
DistanceSensor.prototype.when = function when(value, callback) {
let dist;
if (!this.interval) {
setInterval(() => { // Tomar mediciones cada 200ms
dist = this.distance.getBasicValue();
/* eslint-disable no-console */
console.log(`Distancia: ${dist}`);
if (dist === value) {
callback();
DistanceSensor.prototype.enableEvents = function enableEvents(mqttConfig) {
let prevValue = this.getBasicValue();
if (mqttConfig) {
this.mqttClient = mqttConfig.mqttClient;
this.myTopic = `sensors/distance${mqttConfig.instance}`;
this.mqttClient.publish('registerTopic', this.myTopic);
}
if (!this.eventInterval) {
this.eventInterval = setInterval(() => {
const currentValue = this.getBasicValue();
if (currentValue !== prevValue) {
this.emit('medicion', currentValue);
if (this.mqttClient) {
this.mqttClient.publish(this.myTopic, currentValue.toString());
}
prevValue = currentValue;
}
}, 500);
}, 250);
}

@@ -64,3 +60,2 @@ };

DistanceSensor.prototype.release = function release() {
clearInterval(this.interval);
clearInterval(this.eventInterval);

@@ -67,0 +62,0 @@ this.distance.release();

{
"name": "robotois-distance-sensor",
"version": "1.0.1",
"version": "1.0.2",
"description": "Node library for reading the distance sensor",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,5 +6,5 @@ const DSensor = require('../index.js');

distance.on('value', (dist) => {
distance.on('medicion', (dist) => {
/* eslint-disable no-console */
console.log(`La distancia es: ${dist}`);
console.log(`La distancia es: ${dist} cm`);
});

@@ -11,0 +11,0 @@

@@ -7,3 +7,3 @@ const DSensor = require('../index.js');

/* eslint-disable no-console */
console.log('lol la distancia es 15cm!!');
console.log('Wow la distancia es 15cm!!');
});

@@ -10,0 +10,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc