@robotical/ricjs
Version:
Javascript/TS library for Robotical RIC
82 lines • 2.99 kB
JavaScript
"use strict";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// RICJS
// Communications Library
//
// Rob Dobson & Chris Greening 2020-2022
// (C) 2020-2022
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const RICLog_1 = tslib_1.__importDefault(require("./RICLog"));
class RICLEDPatternChecker {
constructor() {
// Verification of correct device
this._ledColours = new Array();
this._lcdColours = new Array();
this._bleVerifActive = false;
}
isActive() {
return this._bleVerifActive;
}
clear() {
this._bleVerifActive = false;
}
setup(availableColors) {
// Check length of available colours
if (availableColors.length == 0) {
RICLog_1.default.warn('start no available colours');
}
// Random colour selection
const LED_1 = availableColors[Math.floor(Math.random() * availableColors.length)];
const LED_2 = availableColors[Math.floor(Math.random() * availableColors.length)];
const LED_3 = availableColors[Math.floor(Math.random() * availableColors.length)];
// LED and LCD colours are different to attempt to be visually similar
this._ledColours = [LED_1.led, LED_2.led, LED_3.led];
this._lcdColours = [LED_1.lcd, LED_2.lcd, LED_3.lcd];
// Set the colours to display on LEDs
this._bleVerifActive = true;
// Return LCD colours to display
return this._lcdColours;
}
async setRICColors(msgHandler, timeoutMs) {
// Set bonding colours
let colourSetStr = '';
for (let i = 0; i < this._ledColours.length; i++) {
if (i != 0) {
colourSetStr += '&';
}
let colr = this._ledColours[i];
if (colr.startsWith('#'))
colr = colr.slice(1);
colourSetStr += `c${i}=${colr}`;
}
try {
RICLog_1.default.debug('setRICColors setting colours');
if (msgHandler) {
await msgHandler.sendRICRESTURL(`indicator/set?${colourSetStr}&ms=${timeoutMs}`);
}
}
catch (error) {
RICLog_1.default.debug(`setRICColors failed to send ${error}`);
return false;
}
return true;
}
async clearRICColors(msgHandler) {
// Clear the LED colours
RICLog_1.default.debug('clearRICColors');
try {
if (msgHandler) {
await msgHandler.sendRICRESTURL(`indicator/resume`);
}
}
catch (error) {
RICLog_1.default.debug(`clearRICColors failed to send ${error}`);
}
}
}
exports.default = RICLEDPatternChecker;
//# sourceMappingURL=RICLEDPatternChecker.js.map