mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 10:42:49 +00:00
Fix VEML7700Sensor readings and update protobuf and MQTT JSON
This commit is contained in:
@@ -24,11 +24,38 @@ int32_t VEML7700Sensor::runOnce()
|
||||
|
||||
void VEML7700Sensor::setup() {}
|
||||
|
||||
/*!
|
||||
* @brief Copmute lux from ALS reading.
|
||||
* @param rawALS raw ALS register value
|
||||
* @param corrected if true, apply non-linear correction
|
||||
* @return lux value
|
||||
*/
|
||||
float VEML7700Sensor::computeLux(uint16_t rawALS, bool corrected) {
|
||||
float lux = getResolution() * rawALS;
|
||||
if (corrected)
|
||||
lux = (((6.0135e-13 * lux - 9.3924e-9) * lux + 8.1488e-5) * lux + 1.0023) *
|
||||
lux;
|
||||
return lux;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Determines resolution for current gain and integration time
|
||||
* settings.
|
||||
*/
|
||||
float VEML7700Sensor::getResolution(void) {
|
||||
return MAX_RES * (IT_MAX / veml7700.getIntegrationTimeValue()) *
|
||||
(GAIN_MAX / veml7700.getGainValue());
|
||||
}
|
||||
|
||||
bool VEML7700Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
{
|
||||
int16_t white;
|
||||
measurement->variant.environment_metrics.lux = veml7700.readLux(VEML_LUX_AUTO);
|
||||
measurement->variant.environment_metrics.white = veml7700.readWhite();
|
||||
measurement->variant.environment_metrics.ALS = veml7700.readALS();
|
||||
white = veml7700.readWhite(true);
|
||||
measurement->variant.environment_metrics.white_lux = computeLux(white, white > 100);
|
||||
LOG_INFO("white lux %f, als lux %f\n",
|
||||
measurement->variant.environment_metrics.white_lux,
|
||||
measurement->variant.environment_metrics.lux);
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
class VEML7700Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
const float MAX_RES = 0.0036;
|
||||
const float GAIN_MAX = 2;
|
||||
const float IT_MAX = 800;
|
||||
Adafruit_VEML7700 veml7700;
|
||||
float computeLux(uint16_t rawALS, bool corrected);
|
||||
float getResolution(void);
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
|
||||
Reference in New Issue
Block a user