UNPKG

di-sensors

Version:

Drivers and examples for using DI_Sensors in Node.js

68 lines (53 loc) 3.07 kB
'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } // https://www.dexterindustries.com/GoPiGo/ // https://github.com/DexterInd/DI_Sensors // // Copyright (c) 2017 Dexter Industries // Released under the MIT license (http://choosealicense.com/licenses/mit/). // For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md var TCS34725 = require('./TCS34725'); var PCA9570 = require('./PCA9570'); var LightColorSensor = function () { function LightColorSensor() { var sensorIntegrationTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0.0048; var sensorGain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TCS34725.GAIN_16X; var ledState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var bus = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'RPI_1'; var useLightColorSensorBoard = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; _classCallCheck(this, LightColorSensor); this.lightColorDevice = new TCS34725(sensorIntegrationTime, sensorGain, bus); this.useLightColorSensorBoard = useLightColorSensorBoard; if (useLightColorSensorBoard) { this.colorSensorBoard = new PCA9570(bus); } this.setLed(ledState); } _createClass(LightColorSensor, [{ key: 'setLed', value: function setLed(value) { var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; if (this.useLightColorSensorBoard) { if (value) { this.colorSensorBoard.setPins(0x00); } else { this.colorSensorBoard.setPins(0x01); } } else { this.lightColorDevice.setInterrupt(value); } if (delay) { this.lightColorDevice.i2c.mwait((256 - this.lightColorDevice.integrationTimeVal) * 24 * 2); } } }, { key: 'getRawColors', value: function getRawColors() { var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; return this.lightColorDevice.getRawData(delay); } }]); return LightColorSensor; }(); module.exports = LightColorSensor;