Skip to content

Commit 7e4a1ac

Browse files
committed
plaform: Refactor ADC module as class
There was a bug when using multiple instances. It was tested on ARTIK1020 Relate-to: WebThingsIO#46 Forwarded: WebThingsIO#104 Change-Id: Idbb9d0f53fc1534407657c9b63a29db50297ae88 Signed-off-by: Philippe Coval <[email protected]>
1 parent 697f67d commit 7e4a1ac

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

example/platform/adc/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@
99

1010
const fs = require('fs');
1111

12-
function Adc() {
13-
this.open = function(config, callback) {
12+
class Adc {
13+
constructor(config, callback) {
1414
this.config = config;
1515
fs.access(config.device, fs.R_OK, callback);
16-
return this;
17-
};
16+
}
1817

19-
this.readSync = function() {
18+
readSync() {
2019
const contents = fs.readFileSync(this.config.device, 'ascii');
2120
return contents;
22-
};
21+
}
22+
23+
closeSync() {
24+
}
2325

24-
this.closeSync = function() {
25-
};
2626
}
2727

28-
module.exports = new Adc();
28+
29+
module.exports.open = function(config, callback) {
30+
return new Adc(config, callback);
31+
};

0 commit comments

Comments
 (0)