From 85581e519422110a6d142cf3a2ab0af503f17e06 Mon Sep 17 00:00:00 2001
From: Philippe Coval
Date: Thu, 4 Jul 2019 21:38:19 +0200
Subject: [PATCH] platform: Refactor ADC module as class (#104)
There was a bug when using multiple instances.
It was tested on ARTIK1020
Relate-to: https://github.com/mozilla-iot/webthing-node/pull/46
Forwarded: https://github.com/mozilla-iot/webthing-node/pull/104
Change-Id: Idbb9d0f53fc1534407657c9b63a29db50297ae88
Signed-off-by: Philippe Coval
---
example/platform/adc/index.js | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/example/platform/adc/index.js b/example/platform/adc/index.js
index 3c70ed9..2eaf5c9 100644
--- a/example/platform/adc/index.js
+++ b/example/platform/adc/index.js
@@ -9,20 +9,23 @@
const fs = require('fs');
-function Adc() {
- this.open = function(config, callback) {
+class Adc {
+ constructor(config, callback) {
this.config = config;
fs.access(config.device, fs.R_OK, callback);
- return this;
- };
+ }
- this.readSync = function() {
+ readSync() {
const contents = fs.readFileSync(this.config.device, 'ascii');
return contents;
- };
+ }
+
+ closeSync() {
+ }
- this.closeSync = function() {
- };
}
-module.exports = new Adc();
+
+module.exports.open = function(config, callback) {
+ return new Adc(config, callback);
+};