summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-12-26 11:39:12 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-12-26 11:39:12 +0100
commitba778ead40ddf8f1282e78cc8b5dd42e6c4fe1c5 (patch)
treed68a9d003ed09ede30b653ac374e05ac67e45a58
parent05644dec7f2ecffa26dc04b9be8d6ad03a2e79ea (diff)
max44009: handle overrange condition
-rw-r--r--include/driver/max44009.h3
-rw-r--r--src/driver/max44009.cc8
2 files changed, 11 insertions, 0 deletions
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.