summaryrefslogtreecommitdiffstats
path: root/watch-library
diff options
context:
space:
mode:
authorChristian Chapman <1360262+enthdegree@users.noreply.github.com>2023-04-16 10:05:55 -0400
committerGitHub <noreply@github.com>2023-04-16 10:05:55 -0400
commit462f24b31321107834d00016d0b07aa044be5d7e (patch)
tree53937086ab72d3b9bf05001e5e39ae7bb84dcc66 /watch-library
parentbfde33c946ee7f49a2f8bf9f253b2801bd169638 (diff)
downloadSensor-Watch-462f24b31321107834d00016d0b07aa044be5d7e.tar.gz
Sensor-Watch-462f24b31321107834d00016d0b07aa044be5d7e.tar.bz2
Sensor-Watch-462f24b31321107834d00016d0b07aa044be5d7e.zip
Aperture priority light meter face (#230)
* initial commit, added opt3001 light meter test app * tested working light meter board, i2c communication still has issues * fixed i2c; rudimentary lightmeter works! * added aperture priority ui * added aperture priority ui * added README * adjusted cal * fixed bugs (HI shutter speed, lux mode toggle) * made it possible to advance to the next face * initialized lux variable * lowered tolerance for HI and LO * Changed EV display from always showing EV100 to showing EV[iso setting] * dont display old ev when ISO changes * changed mode and light behavior * updated readme * fixed indentation * made lightmeter display logic more consistent * made lightmeter display logic more consistent * reverted rules.mk (for merge into upstream) * reverted rules.mk (for merge into upstream) * removed OPT3001 PCB model * made lux mode default, corrected timeout behavior --------- Co-authored-by: Christian Chapman <user@debian>
Diffstat (limited to 'watch-library')
-rw-r--r--watch-library/shared/driver/opt3001.c91
-rw-r--r--watch-library/shared/driver/opt3001.h87
2 files changed, 178 insertions, 0 deletions
diff --git a/watch-library/shared/driver/opt3001.c b/watch-library/shared/driver/opt3001.c
new file mode 100644
index 00000000..d2f4e8ce
--- /dev/null
+++ b/watch-library/shared/driver/opt3001.c
@@ -0,0 +1,91 @@
+/*
+
+Arduino library for Texas Instruments opt3001_t Digital Ambient Light Sensor
+Written by AA for ClosedCube
+Adapted to Sensor-Watch interface by CC
+---
+
+The MIT License (MIT)
+
+Copyright (c) 2015 ClosedCube Limited
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
+#include <math.h>
+
+#include "opt3001.h"
+#include "watch_utility.h"
+
+uint16_t opt3001_readManufacturerID(uint8_t devaddr) {
+ uint8_t buf[2];
+ buf[0] = (uint8_t) OPT3001_MANUFACTURER_ID;
+ watch_i2c_send(devaddr, buf, 1);
+ watch_i2c_receive(devaddr, buf, 2);
+ return ((uint16_t) buf[0] << 8) | ((uint16_t) buf[1]);
+}
+
+uint16_t opt3001_readDeviceID(uint8_t devaddr) {
+ uint8_t buf[2];
+ buf[0] = (uint8_t) OPT3001_DEVICE_ID;
+ watch_i2c_send(devaddr, buf, 1);
+ watch_i2c_receive(devaddr, buf, 2);
+ return ((uint16_t) buf[0] << 8) | ((uint16_t) buf[1]);
+}
+
+opt3001_Config_t opt3001_readConfig(uint8_t devaddr) {
+ opt3001_Config_t config;
+ uint8_t buf[2];
+ buf[0] = (uint8_t) OPT3001_CONFIG;
+ watch_i2c_send(devaddr, buf, 1);
+ watch_i2c_receive(devaddr, buf, 2);
+ config.rawData = ((uint16_t) buf[0] << 8) | ((uint16_t) buf[1]);
+ return config;
+}
+
+void opt3001_writeConfig(uint8_t devaddr, opt3001_Config_t config) {
+ uint8_t buf[3] = {OPT3001_CONFIG, (uint8_t)(config.rawData >> 8), (uint8_t)(config.rawData & 0x00FF)};
+ watch_i2c_send(devaddr, buf, 3);
+ return;
+}
+
+opt3001_t opt3001_readResult(uint8_t devaddr) {
+ return opt3001_readRegister(devaddr, OPT3001_RESULT);
+}
+
+opt3001_t opt3001_readHighLimit(uint8_t devaddr) {
+ return opt3001_readRegister(devaddr, OPT3001_HIGH_LIMIT);
+}
+
+opt3001_t opt3001_readLowLimit(uint8_t devaddr) {
+ return opt3001_readRegister(devaddr, OPT3001_LOW_LIMIT);
+}
+
+opt3001_t opt3001_readRegister(uint8_t devaddr, opt3001_Command_t command) {
+ opt3001_t result;
+ opt3001_ER_t er;
+ uint8_t buf[2];
+ buf[0] = (uint8_t) command;
+ watch_i2c_send(devaddr, buf, 1);
+ watch_i2c_receive(devaddr, buf, 2);
+ er.rawData = ((uint16_t) buf[0] << 8) | ((uint16_t) buf[1]);
+ result.raw = er;
+ result.lux = 0.01*pow(2, er.Exponent)*er.Result;
+ return result;
+}
diff --git a/watch-library/shared/driver/opt3001.h b/watch-library/shared/driver/opt3001.h
new file mode 100644
index 00000000..1ed8eea9
--- /dev/null
+++ b/watch-library/shared/driver/opt3001.h
@@ -0,0 +1,87 @@
+/*
+
+Arduino library for Texas Instruments OPT3001 Digital Ambient Light Sensor
+Adapted to Sensor-Watch interface by CC
+---
+
+The MIT License (MIT)
+
+Copyright (c) 2015 ClosedCube Limited
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
+
+#ifndef OPT3001_
+#define OPT3001_
+#include <stdint.h>
+
+typedef enum {
+ OPT3001_RESULT = 0x00,
+ OPT3001_CONFIG = 0x01,
+ OPT3001_LOW_LIMIT = 0x02,
+ OPT3001_HIGH_LIMIT = 0x03,
+
+ OPT3001_MANUFACTURER_ID = 0x7E,
+ OPT3001_DEVICE_ID = 0x7F,
+} opt3001_Command_t;
+
+typedef union {
+ uint16_t rawData;
+ struct {
+ uint16_t Result : 12;
+ uint8_t Exponent : 4;
+ };
+} opt3001_ER_t;
+
+
+typedef union {
+ struct {
+ uint8_t FaultCount : 2;
+ uint8_t MaskExponent : 1;
+ uint8_t Polarity : 1;
+ uint8_t Latch : 1;
+ uint8_t FlagLow : 1;
+ uint8_t FlagHigh : 1;
+ uint8_t ConversionReady : 1;
+ uint8_t OverflowFlag : 1;
+ uint8_t ModeOfConversionOperation : 2;
+ uint8_t ConversionTime : 1;
+ uint8_t RangeNumber : 4;
+ };
+ uint16_t rawData;
+} opt3001_Config_t;
+
+typedef struct {
+ float lux;
+ opt3001_ER_t raw;
+} opt3001_t;
+
+uint16_t opt3001_readManufacturerID(uint8_t devaddr);
+uint16_t opt3001_readDeviceID(uint8_t devaddr);
+
+opt3001_t opt3001_readResult(uint8_t devaddr);
+opt3001_t opt3001_readHighLimit(uint8_t devaddr);
+opt3001_t opt3001_readLowLimit(uint8_t devaddr);
+
+opt3001_Config_t opt3001_readConfig(uint8_t devaddr);
+void opt3001_writeConfig(uint8_t devaddr, opt3001_Config_t config);
+opt3001_t opt3001_readRegister(uint8_t devaddr, opt3001_Command_t command);
+
+#endif // OPT3001_