1'use strict';
2
3class HW_ADC {
4    constructor(options) {
5        if (!options || !options.id) {
6            throw new Error('options is invalid');
7        }
8
9        this.options = {
10            id: options.id
11        };
12
13        this.success = options.success || function(){};
14        this.fail = options.fail || function(){};
15        this._open();
16    }
17
18    _open() {
19        this.adcInstance = __native.ADC.open(this.options.id);
20        if (!this.adcInstance) {
21            this.fail();
22            return;
23        }
24        this.success();
25    }
26
27    readValue() {
28        if (!this.adcInstance) {
29            throw new Error('adc not init');
30        }
31
32        return __native.ADC.read(this.adcInstance);
33    };
34
35    close() {
36        if (!this.adcInstance) {
37            throw new Error('adc not init');
38        }
39
40        __native.ADC.close(this.adcInstance);
41    };
42}
43
44function open(options) {
45    return new HW_ADC(options);
46}
47
48module.exports = {
49    open,
50}