UNPKG

di-sensors

Version:

Drivers and examples for using DI_Sensors in Node.js

80 lines (69 loc) 3.12 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 Sensor = require('./base/sensor'); var RgbLcd = function () { function RgbLcd() { _classCallCheck(this, RgbLcd); this.rgbDevice = new Sensor('RPI_1', 0x62); this.txtDevice = new Sensor('RPI_1', 0x3e); } _createClass(RgbLcd, [{ key: 'setRGB', value: function setRGB(r, g, b) { this.rgbDevice.i2c.writeReg8(0, 0); this.rgbDevice.i2c.writeReg8(1, 0); this.rgbDevice.i2c.writeReg8(0x08, 0xaa); this.rgbDevice.i2c.writeReg8(4, r); this.rgbDevice.i2c.writeReg8(3, g); this.rgbDevice.i2c.writeReg8(2, b); } }, { key: 'textCommand', value: function textCommand(cmd) { this.txtDevice.i2c.writeReg8(0x80, cmd); } }, { key: 'setText', value: function setText(text) { var noRefresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var refreshCmd = !noRefresh ? 0x01 : 0x02; this.textCommand(refreshCmd); // clear or no-refresh this.txtDevice.i2c.mwait(5); this.textCommand(0x08 | 0x04); // display on, no cursor this.textCommand(0x28); // 2 lines this.txtDevice.mwait(5); var count = 0; var row = 0; for (var i = 0, len = text.length; i < len; i++) { var c = text[i]; if (c === '\n' || count === 16) { count = 0; row += 1; if (row === 2) { break; } this.textCommand(0xc0); if (c === '\n') { break; } } count++; this.txtDevice.i2c.writeReg8(0x40, c.charCodeAt()); } } }, { key: 'setTextNoRefresh', value: function setTextNoRefresh(text) { this.setText(text, true); } }]); return RgbLcd; }(); module.exports = RgbLcd;