UNPKG

jvsveml6070

Version:

Node.js package for the Vishay VEML6070 UVA Light Sensor, written in TypeScript.

49 lines (48 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UvIndex = void 0; const module_1 = require("./enums/module"); class UvIndex { /** * Creates a new `UvIndex` instance. * * @param value - The UV index. */ constructor(value) { this.value = value; } /** * The UV index risk level. */ get riskLevel() { let riskLevel = module_1.UvIndexRiskLevel.LOW; if (this.value >= 3 && this.value <= 5) { riskLevel = module_1.UvIndexRiskLevel.MODERATE; } else if (this.value >= 6 && this.value <= 7) { riskLevel = module_1.UvIndexRiskLevel.HIGH; } else if (this.value >= 8 && this.value <= 10) { riskLevel = module_1.UvIndexRiskLevel.VERY_HIGH; } else if (this.value >= 11) { riskLevel = module_1.UvIndexRiskLevel.EXTREME; } return riskLevel; } /** * Creates a new `UvIndex` instance from a sensor value. * * @param rSet - The RSET value (in kΩ). * @param normalizedValue - The normalized value. * This is the raw value divided by the integration time multiplier, resulting in the 1T * value. * * @returns The created `UvIndex` instance. */ static fromSensorValue(rSet, normalizedValue) { const uvIndex = Math.trunc(normalizedValue / (rSet * (186.67 / 270))); return new UvIndex(uvIndex); } } exports.UvIndex = UvIndex;