From ba778ead40ddf8f1282e78cc8b5dd42e6c4fe1c5 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 26 Dec 2021 11:39:12 +0100 Subject: max44009: handle overrange condition --- include/driver/max44009.h | 3 +++ src/driver/max44009.cc | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/include/driver/max44009.h b/include/driver/max44009.h index cca142f..da64712 100644 --- a/include/driver/max44009.h +++ b/include/driver/max44009.h @@ -2,6 +2,9 @@ * Copyright 2020 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause + * + * Driver for MAX44009 Ambient Light Sensor. + * Does not support interrupts. */ #ifndef MAX44009_H #define MAX44009_H diff --git a/src/driver/max44009.cc b/src/driver/max44009.cc index bab4da5..8a8ff3e 100644 --- a/src/driver/max44009.cc +++ b/src/driver/max44009.cc @@ -2,6 +2,9 @@ * Copyright 2020 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause + * + * Driver for MAX44009 Ambient Light Sensor. + * Does not support interrupts. */ #include "driver/max44009.h" #if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(CONFIG_driver_softi2c) @@ -37,6 +40,11 @@ float MAX44009::getLux() */ exponent = (luxHigh & 0xF0) >> 4; + if (exponent == 0x0f) { + // overrange condition + return -1; + } + /* * Cast base and mantissa to float to avoid calculation errors * because of 16bit integer overflows. -- cgit v1.2.3