esp-idf-lib/components/apds9930/apds9930.c

Sun, 10 Sep 2023 17:29:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 10 Sep 2023 17:29:15 +0200
changeset 37
50dbb626fbab
parent 21
df8564c9701e
permissions
-rw-r--r--

Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.

11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file APDS-9930.cpp
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief Library for the SparkFun APDS-9930 breakout board
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * @author Shawn Hymel (SparkFun Electronics)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * @copyright This code is public domain but you buy me a beer if you use
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * this and we meet someday (Beerware license). Davide Depau Arduino version.
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * This library interfaces the Avago APDS-9930 to ESP-IDf over I2C.
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 *
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * APDS-9930 current draw tests (default parameters):
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * Off: 1mA
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * Waiting for gesture: 14mA
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * Gesture in progress: 35mA
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "apds9930.h"
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include <inttypes.h>
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include <esp_log.h>
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include <esp_idf_lib_helpers.h>
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
22 #define I2C_FREQ_HZ 100000 // Max 400 KHz
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 static const char *TAG = "apds9930";
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 /* Error code for returned values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #define APDS9930_ERROR 0xFF
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 /* Command register modes */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 #define APDS9930_REPEATED_BYTE 0x80
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 #define APDS9930_AUTO_INCREMENT 0xA0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 #define APDS9930_SPECIAL_FN 0xE0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 /* APDS-9930 register addresses */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #define APDS9930_ENABLE 0x00
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 #define APDS9930_ATIME 0x01
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #define APDS9930_PTIME 0x02
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 #define APDS9930_WTIME 0x03
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 #define APDS9930_AILTL 0x04
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 #define APDS9930_AILTH 0x05
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 #define APDS9930_AIHTL 0x06
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 #define APDS9930_AIHTH 0x07
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 #define APDS9930_PILTL 0x08
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 #define APDS9930_PILTH 0x09
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 #define APDS9930_PIHTL 0x0A
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 #define APDS9930_PIHTH 0x0B
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 #define APDS9930_PERS 0x0C
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 #define APDS9930_CONFIG 0x0D
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 #define APDS9930_PPULSE 0x0E
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 #define APDS9930_CONTROL 0x0F
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 #define APDS9930_ID 0x12
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 #define APDS9930_STATUS 0x13
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 #define APDS9930_Ch0DATAL 0x14
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 #define APDS9930_Ch0DATAH 0x15
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 #define APDS9930_Ch1DATAL 0x16
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 #define APDS9930_Ch1DATAH 0x17
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 #define APDS9930_PDATAL 0x18
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 #define APDS9930_PDATAH 0x19
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 #define APDS9930_POFFSET 0x1E
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 /* Bit fields */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 #define APDS9930_PON 0b00000001
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 #define APDS9930_AEN 0b00000010
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 #define APDS9930_PEN 0b00000100
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 #define APDS9930_WEN 0b00001000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 #define APSD9930_AIEN 0b00010000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 #define APDS9930_PIEN 0b00100000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 #define APDS9930_SAI 0b01000000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 /* On/Off definitions */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 #define APDS9930_OFF 0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 #define APDS9930_ON 1
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 /* Acceptable parameters for setMode */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 #define APDS9930_MODE_POWER 0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 #define APDS9930_MODE_AMBIENT_LIGHT 1
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 #define APDS9930_MODE_PROXIMITY 2
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 #define APDS9930_MODE_WAIT 3
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 #define APDS9930_MODE_AMBIENT_LIGHT_INT 4
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 #define APDS9930_MODE_PROXIMITY_INT 5
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 #define APDS9930_MODE_SLEEP_AFTER_INT 6
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 #define APDS9930_MODE_ALL 7
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 /* Interrupt clear values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 #define APDS9930_CLEAR_PROX_INT 0xE5
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 #define APDS9930_CLEAR_ALS_INT 0xE6
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 #define APDS9930_CLEAR_ALL_INTS 0xE7
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 /* ALS coefficients */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 #define APDS9930_DF 52
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 #define APDS9930_GA 0.49
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 #define APDS9930_ALS_B 1.862
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 #define APDS9930_ALS_C 0.746
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 #define APDS9930_ALS_D 1.291
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 #define CHECK(x) do { esp_err_t __; if ((__ = x) != ESP_OK) return __; } while (0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 #define CHECK_ARG(VAL) do { if (!(VAL)) return ESP_ERR_INVALID_ARG; } while (0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 #define CHECK_LOGE(dev, x, msg, ...) do { \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 esp_err_t __; \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 if ((__ = x) != ESP_OK) { \
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
103 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev); \
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 ESP_LOGE(TAG, msg, ## __VA_ARGS__); \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 return __; \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 } \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 } while (0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
110
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
111 static inline esp_err_t read_reg_8_nolock(apds9930_t *dev, uint8_t reg, uint8_t *data)
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
112 {
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
113 return i2c_dev_read_reg(&dev->i2c_dev, reg, data, 1);
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
114 }
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
115
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
116 static inline esp_err_t write_reg_8_nolock(apds9930_t *dev, uint8_t reg, uint8_t data)
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
117 {
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
118 return i2c_dev_write_reg(&dev->i2c_dev, reg, &data, 1);
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
119 }
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
120
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
121
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 inline static esp_err_t write_register8(i2c_dev_t *dev, uint8_t addr, uint8_t value)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 return i2c_dev_write_reg(dev, addr, &value, 1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
128 esp_err_t apds9930_init_desc(apds9930_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 CHECK_ARG(dev);
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
131
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
132 if (addr != 0x39) {
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
133 ESP_LOGE(TAG, "Invalid I2C address");
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
134 return ESP_ERR_INVALID_ARG;
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
135 }
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
137 dev->i2c_dev.port = port;
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
138 dev->i2c_dev.addr = addr;
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
139 dev->i2c_dev.cfg.sda_io_num = sda_gpio;
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
140 dev->i2c_dev.cfg.scl_io_num = scl_gpio;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 #if HELPER_TARGET_IS_ESP32
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
142 dev->i2c_dev.cfg.master.clk_speed = I2C_FREQ_HZ;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 #endif
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
145 return i2c_dev_create_mutex(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
149 esp_err_t apds9930_free_desc(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
153 return i2c_dev_delete_mutex(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
157 esp_err_t apds9930_init(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 esp_err_t err = ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 CHECK_ARG(dev);
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
162 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
164 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_ID, &dev->id, 1), "Sensor not found");
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
165 if (dev->id != APDS9930_ID_1 && dev->id != APDS9930_ID_2 && dev->id != APDS9930_ID_3) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 CHECK_LOGE(dev, ESP_ERR_INVALID_VERSION,
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 "Invalid chip ID: expected: 0x%x or 0x%x or 0x%x got: 0x%x",
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
168 APDS9930_ID_1, APDS9930_ID_2, APDS9930_ID_3, dev->id);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 }
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
170 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 /* Set ENABLE register to 0 (disable all features) */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
173 if (apds9930_setMode(dev, APDS9930_MODE_ALL | APDS9930_AUTO_INCREMENT, APDS9930_OFF) != ESP_OK) {
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
174 ESP_LOGE(TAG, "apds9930_init() error 'Regs off'");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 err = ESP_ERR_INVALID_ARG;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 /* Set default values for ambient light and proximity registers */
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
179 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
180 CHECK_LOGE(dev, write_register8(&dev->i2c_dev, APDS9930_ATIME | APDS9930_AUTO_INCREMENT, APDS9930_DEFAULT_ATIME), "Default atime");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
181 CHECK_LOGE(dev, write_register8(&dev->i2c_dev, APDS9930_WTIME | APDS9930_AUTO_INCREMENT, APDS9930_DEFAULT_WTIME), "Default wtime");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
182 CHECK_LOGE(dev, write_register8(&dev->i2c_dev, APDS9930_PPULSE | APDS9930_AUTO_INCREMENT, APDS9930_DEFAULT_PPULSE), "Default ppulse");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
183 CHECK_LOGE(dev, write_register8(&dev->i2c_dev, APDS9930_POFFSET | APDS9930_AUTO_INCREMENT, APDS9930_DEFAULT_POFFSET), "Default poffset");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
184 CHECK_LOGE(dev, write_register8(&dev->i2c_dev, APDS9930_CONFIG | APDS9930_AUTO_INCREMENT, APDS9930_DEFAULT_CONFIG), "Default config");
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
185 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
186
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 CHECK_LOGE(dev, apds9930_setLEDDrive(dev, APDS9930_DEFAULT_PDRIVE), "Default pdrive");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 CHECK_LOGE(dev, apds9930_setProximityGain(dev, APDS9930_DEFAULT_PGAIN), "Default pgain");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 CHECK_LOGE(dev, apds9930_setAmbientLightGain(dev, APDS9930_DEFAULT_AGAIN), "Default again");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 CHECK_LOGE(dev, apds9930_setProximityDiode(dev, APDS9930_DEFAULT_PDIODE), "Default pdiode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 CHECK_LOGE(dev, apds9930_setProximityIntLowThreshold(dev, APDS9930_DEFAULT_PILT), "Default PILT");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 CHECK_LOGE(dev, apds9930_setProximityIntHighThreshold(dev, APDS9930_DEFAULT_PIHT), "Default PIHT");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 CHECK_LOGE(dev, apds9930_setLightIntLowThreshold(dev, APDS9930_DEFAULT_AILT), "Default ailt");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 CHECK_LOGE(dev, apds9930_setLightIntHighThreshold(dev, APDS9930_DEFAULT_AIHT), "Default aiht");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
196 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
197 CHECK_LOGE(dev, write_register8(&dev->i2c_dev, APDS9930_PERS | APDS9930_AUTO_INCREMENT, APDS9930_DEFAULT_PERS), "Default pers");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
198 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
199
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 return err;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 * Public methods for controlling the APDS-9930
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
207 uint8_t apds9930_getMode(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 uint8_t enable_value;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
211 /* Read current ENABLE register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
212 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
213 if (read_reg_8_nolock(dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, &enable_value) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
214 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 return APDS9930_ERROR;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
218 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 return enable_value;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
223 esp_err_t apds9930_setMode(apds9930_t *dev, uint8_t mode, uint8_t enable)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 uint8_t reg_val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226
21
df8564c9701e The esp-idf-lib apds9930 component is now working. In nvsio stop logging not updated values. Store gain and aglbit values in nvs.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
227 CHECK_ARG(dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 /* Read current ENABLE register */
21
df8564c9701e The esp-idf-lib apds9930 component is now working. In nvsio stop logging not updated values. Store gain and aglbit values in nvs.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
229 reg_val = apds9930_getMode(dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 /* Change bit(s) in ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 enable = enable & 0x01;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 if (mode <= 6) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 if (enable) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 reg_val |= (1 << mode);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 reg_val &= ~(1 << mode);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 } else if (mode == APDS9930_MODE_ALL) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 if (enable) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 reg_val = 0x7F;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 reg_val = 0x00;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 /* Write value back to ENABLE register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
248 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
249 I2C_DEV_CHECK(&dev->i2c_dev, write_reg_8_nolock(dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, reg_val));
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
250 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
256 esp_err_t apds9930_enableLightSensor(apds9930_t *dev, bool interrupts)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 /* Set default gain, interrupts, enable power, and enable sensor */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 CHECK_LOGE(dev, apds9930_setAmbientLightGain(dev, APDS9930_DEFAULT_AGAIN), "setAmbientLightGain");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 if ( interrupts ) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 CHECK_LOGE(dev, apds9930_setAmbientLightIntEnable(dev, 1), "setAmbientLightIntEnable(1)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 CHECK_LOGE(dev, apds9930_setAmbientLightIntEnable(dev, 0), "setAmbientLightIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 CHECK_LOGE(dev, apds9930_enablePower(dev), "enablePower");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_AMBIENT_LIGHT, 1), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
274 esp_err_t apds9930_disableLightSensor(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 CHECK_LOGE(dev, apds9930_setAmbientLightIntEnable(dev, 0), "setAmbientLightIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_AMBIENT_LIGHT, 0), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
285 esp_err_t apds9930_enableProximitySensor(apds9930_t *dev, bool interrupts)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 /* Set default gain, LED, interrupts, enable power, and enable sensor */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 CHECK_LOGE(dev, apds9930_setProximityGain(dev, APDS9930_DEFAULT_PGAIN), "setProximityGain");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 CHECK_LOGE(dev, apds9930_setLEDDrive(dev, APDS9930_DEFAULT_PDRIVE), "setLEDDrive");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 if( interrupts ) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 CHECK_LOGE(dev, apds9930_setProximityIntEnable(dev, 1), "setProximityIntEnable(1)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 CHECK_LOGE(dev, apds9930_setProximityIntEnable(dev, 0), "setProximityIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 CHECK_LOGE(dev, apds9930_enablePower(dev), "enablePower");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_PROXIMITY, 1), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
304 esp_err_t apds9930_disableProximitySensor(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 CHECK_LOGE(dev, apds9930_setProximityIntEnable(dev, 0), "setProximityIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_PROXIMITY, 0), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
315 esp_err_t apds9930_enablePower(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 return apds9930_setMode(dev, APDS9930_MODE_POWER, 1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
321 esp_err_t apds9930_disablePower(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 return apds9930_setMode(dev, APDS9930_MODE_POWER, 0);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 * Ambient light sensor controls
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
331 esp_err_t apds9930_readAmbientLightLux(apds9930_t *dev, float *val)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 uint16_t Ch0, Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 /* Read value from channels */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 CHECK_LOGE(dev, apds9930_readCh0Light(dev, &Ch0), "read ch0");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 CHECK_LOGE(dev, apds9930_readCh1Light(dev, &Ch1), "read ch1");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 *val = apds9930_floatAmbientToLux(dev, Ch0, Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
344 esp_err_t apds9930_readulAmbientLightLux(apds9930_t *dev, unsigned long *val)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 uint16_t Ch0, Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 /* Read value from channels */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 CHECK_LOGE(dev, apds9930_readCh0Light(dev, &Ch0), "read ch0");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 CHECK_LOGE(dev, apds9930_readCh1Light(dev, &Ch1), "read ch1");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 *val = apds9930_ulongAmbientToLux(dev, Ch0, Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
357 float apds9930_floatAmbientToLux(apds9930_t *dev, uint16_t Ch0, uint16_t Ch1)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 uint8_t x[4] = {1,8,16,120};
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 float iac;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 float ALSIT = 2.73 * (256 - APDS9930_DEFAULT_ATIME);
37
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
363 float iac0 = Ch0 - APDS9930_ALS_B * Ch1;
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
364 float iac1 = APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1;
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
365
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
366 if ((iac0 < 0) && (iac1 < 0)) {
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
367 /* Overflow, too much light */
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
368 return 32767.0;
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
369 }
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
370
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
371 if (iac0 > iac1)
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
372 iac = iac0;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373 else
37
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
374 iac = iac1;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375 //float iac = fmax(Ch0 - APDS9930_ALS_B * Ch1, APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 if (iac < 0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 iac = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 float lpc = APDS9930_GA * APDS9930_DF / (ALSIT * x[apds9930_getAmbientLightGain(dev)]);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 return iac * lpc;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
383 unsigned long apds9930_ulongAmbientToLux(apds9930_t *dev, uint16_t Ch0, uint16_t Ch1)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 uint8_t x[4] = {1,8,16,120};
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 unsigned long iac;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 unsigned long ALSIT = 2.73 * (256 - APDS9930_DEFAULT_ATIME);
37
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
389 long iac0 = Ch0 - APDS9930_ALS_B * Ch1;
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
390 long iac1 = APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1;
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
391
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
392 if ((iac0 < 0) && (iac1 < 0)) {
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
393 /* Overflow, too much light */
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
394 return 32767;
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
395 }
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
396
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
397 if (iac0 > iac1)
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
398 iac = iac0;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 else
37
50dbb626fbab Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
400 iac = iac1;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 //unsigned long iac = max(Ch0 - APDS9930_ALS_B * Ch1, APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 // if (iac < 0) iac = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 unsigned long lpc = APDS9930_GA * APDS9930_DF / (ALSIT * x[apds9930_getAmbientLightGain(dev)]);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 return iac * lpc;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
408 esp_err_t apds9930_readCh0Light(apds9930_t *dev, uint16_t *val)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 {
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
410 uint16_t val_word;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 *val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
415 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 /* Read value from channel 0 */
21
df8564c9701e The esp-idf-lib apds9930 component is now working. In nvsio stop logging not updated values. Store gain and aglbit values in nvs.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
417 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, (uint8_t)APDS9930_Ch0DATAL | APDS9930_AUTO_INCREMENT, &val_word, 2), "Read ch0");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
418 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
21
df8564c9701e The esp-idf-lib apds9930 component is now working. In nvsio stop logging not updated values. Store gain and aglbit values in nvs.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
419 *val = val_word;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
425 esp_err_t apds9930_readCh1Light(apds9930_t *dev, uint16_t *val)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 {
21
df8564c9701e The esp-idf-lib apds9930 component is now working. In nvsio stop logging not updated values. Store gain and aglbit values in nvs.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
427 uint16_t val_word;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 *val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
430 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 /* Read value from channel 1 */
21
df8564c9701e The esp-idf-lib apds9930 component is now working. In nvsio stop logging not updated values. Store gain and aglbit values in nvs.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
432 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, (uint8_t)APDS9930_Ch1DATAL | APDS9930_AUTO_INCREMENT, &val_word, 2), "Read ch1");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
433 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
21
df8564c9701e The esp-idf-lib apds9930 component is now working. In nvsio stop logging not updated values. Store gain and aglbit values in nvs.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
434 *val = val_word;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440 * Proximity sensor controls
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
443 esp_err_t apds9930_readProximity(apds9930_t *dev, uint16_t *val)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 *val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
448 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 /* Read value from proximity data register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
450 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_PDATAL | APDS9930_AUTO_INCREMENT, &val_byte, 1), "Read proximity low");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451 *val = val_byte;
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
452 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_PDATAH | APDS9930_AUTO_INCREMENT, &val_byte, 1), "Read proximity high");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 *val += ((uint16_t)val_byte << 8);
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
454 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
457 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 * Getters and setters for register values
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
463 uint16_t apds9930_getProximityIntLowThreshold(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465 uint16_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 /* Read value from PILT register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
469 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
470 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_PILTL | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473 val = val_byte;
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
474 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_PILTH | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
477 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 val |= ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
484 esp_err_t apds9930_setProximityIntLowThreshold(apds9930_t *dev, uint16_t threshold)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 uint8_t lo;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 uint8_t hi;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 hi = threshold >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 lo = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
491 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
492 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_PILTL | APDS9930_AUTO_INCREMENT, &lo, 1), "Write PILTL");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
493 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_PILTH | APDS9930_AUTO_INCREMENT, &hi, 1), "Write PILTH");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
494 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
495
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
500 uint16_t apds9930_getProximityIntHighThreshold(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 uint16_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505 /* Read value from PIHT register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
506 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
507 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_PIHTL | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510 val = val_byte;
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
511 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_PIHTH | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
514 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515 val |= ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
521 esp_err_t apds9930_setProximityIntHighThreshold(apds9930_t *dev, uint16_t threshold)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
522 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523 uint8_t lo;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524 uint8_t hi;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 hi = threshold >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
526 lo = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
528 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
529 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_PIHTL | APDS9930_AUTO_INCREMENT, &lo, 1), "Write PIHTL");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
530 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_PIHTH | APDS9930_AUTO_INCREMENT, &hi, 1), "Write PIHTH");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
531 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
537 uint8_t apds9930_getLEDDrive(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
542 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
543 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
544 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
547 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 /* Shift and mask out LED drive bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550 val = (val >> 6) & 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
556 esp_err_t apds9930_setLEDDrive(apds9930_t *dev, uint8_t drive)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
561 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
562 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Read control");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 drive = drive << 6;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 val &= 0b00111111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 /* Write register value back into CONTROL register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
571 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Write control");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
572 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
578 uint8_t apds9930_getProximityGain(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
583 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
584 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
585 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
588 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 /* Shift and mask out PDRIVE bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591 val = (val >> 2) & 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
597 esp_err_t apds9930_setProximityGain(apds9930_t *dev, uint8_t drive)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
602 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
603 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Read control");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
605 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 drive = drive << 2;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608 val &= 0b11110011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
609 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611 /* Write register value back into CONTROL register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
612 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Write control");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
613 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
614
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
615 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
619 uint8_t apds9930_getProximityDiode(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
621 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
622
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
623 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
624 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
625 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
626 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
627 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
628 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
629 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
630
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
631 /* Shift and mask out PDRIVE bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632 val = (val >> 4) & 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
634 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
635 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
636
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
638 esp_err_t apds9930_setProximityDiode(apds9930_t *dev, uint8_t drive)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
639 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
643 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
644 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Read control");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
646 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
647 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648 drive = drive << 4;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649 val &= 0b11001111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
650 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
651
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
652 /* Write register value back into CONTROL register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
653 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Write control");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
654 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
656 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
657 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
660 uint8_t apds9930_getAmbientLightGain(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
661 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
662 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
663
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
664 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
665 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
666 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
667 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
668 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
669 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
670 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
671
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
672 /* Shift and mask out ADRIVE bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
673 val &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
674
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
675 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
676 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
677
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
678
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
679 esp_err_t apds9930_setAmbientLightGain(apds9930_t *dev, uint8_t drive)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
680 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
681 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
682
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
683 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
684 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
685 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Read control");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
686
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
687 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
688 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
689 val &= 0b11111100;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
690 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
691
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
692 /* Write register value back into CONTROL register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
693 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Write control");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
694 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
695
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
696 return ESP_OK;
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
697 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
698
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
699
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
700 uint8_t apds9930_getAmbientGainLevel(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
701 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
702 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
703
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
704 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
705 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
706 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
707 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
710 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
712 /* Shift and mask out AGL bit */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 val = (val >> 2) & 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
716 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
717
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
719 esp_err_t apds9930_setAmbientGainLevel(apds9930_t *dev, uint8_t enable)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
720 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 /* Read value from CONTROL register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
724 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
725 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Read control");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
726
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
728 enable &= 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
729 enable = enable << 2;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
730 val &= 0b11111011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
731 val |= enable;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
732
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
733 /* Write register value back into CONTROL register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
734 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_CONTROL | APDS9930_AUTO_INCREMENT, &val, 1), "Write control");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
735 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
736
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
737 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
738 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
740
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
741 esp_err_t apds9930_getLightIntLowThreshold(apds9930_t *dev, uint16_t *threshold)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
742 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 /* Read value from ambient light low threshold, low byte register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
747 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
748 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_AILTL | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
749 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 *threshold = val_byte;
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
752 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_AILTH | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
753 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
754 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
755 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756 *threshold = *threshold + ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
759 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
762 esp_err_t apds9930_setLightIntLowThreshold(apds9930_t *dev, uint16_t threshold)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
763 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
764 uint8_t val_low;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
765 uint8_t val_high;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767 /* Break 16-bit threshold into 2 8-bit values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 val_low = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
769 val_high = (threshold & 0xFF00) >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
771 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
772 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_AILTL | APDS9930_AUTO_INCREMENT, &val_low, 1), "Write AILTL");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
773 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_AILTH | APDS9930_AUTO_INCREMENT, &val_high, 1), "Write AILTH");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
774 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
778
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
780 esp_err_t apds9930_getLightIntHighThreshold(apds9930_t *dev, uint16_t *threshold)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
784
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 /* Read value from ambient light high threshold, low byte register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
786 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
787 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_AIHTL | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
789 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790 *threshold = val_byte;
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
791 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_AIHTH | APDS9930_AUTO_INCREMENT, &val_byte, 1) != ESP_OK) {
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
792 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
794 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795 *threshold = *threshold + ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
796
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
797 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
801 esp_err_t apds9930_setLightIntHighThreshold(apds9930_t *dev, uint16_t threshold)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 uint8_t val_low;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
804 uint8_t val_high;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806 /* Break 16-bit threshold into 2 8-bit values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807 val_low = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 val_high = (threshold & 0xFF00) >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
810 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
811 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_AIHTL | APDS9930_AUTO_INCREMENT, &val_low, 1), "Write AIHTL");
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
812 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_AIHTH | APDS9930_AUTO_INCREMENT, &val_high, 1), "Write AIHTH");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
813 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
818
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
819 uint8_t apds9930_getAmbientLightIntEnable(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
821 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
823 /* Read value from ENABLE register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
824 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
825 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, &val, 1) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
826 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
829 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
830
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
831 /* Shift and mask out AIEN bit */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
832 val = (val >> 4) & 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
833
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
834 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
835 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
836
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
837
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
838 esp_err_t apds9930_setAmbientLightIntEnable(apds9930_t *dev, uint8_t enable)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
841
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
842 /* Read value from ENABLE register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
843 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
844 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, &val, 1), "Read enable");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847 enable &= 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
848 enable = enable << 4;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
849 val &= 0b11101111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
850 val |= enable;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
851
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852 /* Write register value back into ENABLE register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
853 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, &val, 1), "Write enable");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
854 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
856 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
857 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
858
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
859
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
860 uint8_t apds9930_getProximityIntEnable(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
861 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
862 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
863
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
864 /* Read value from ENABLE register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
865 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
866 if (i2c_dev_read_reg(&dev->i2c_dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, &val, 1) != ESP_OK) {
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
867 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
868 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
869 }
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
870 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
871
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
872 /* Shift and mask out PIEN bit */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873 val = (val >> 5) & 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
874
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
875 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
877
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
878
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
879 esp_err_t apds9930_setProximityIntEnable(apds9930_t *dev, uint8_t enable)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
880 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
882
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
883 /* Read value from ENABLE register */
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
884 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
885 CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, &val, 1), "Read enable");
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
886
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
887 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
888 enable &= 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
889 enable = enable << 5;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
890 val &= 0b11011111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
891 val |= enable;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
892
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
893 /* Write register value back into ENABLE register */
17
1599e696d947 Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
894 CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, &val, 1), "Write enable");
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
895 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
896
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
897 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
898 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
899
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
900
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
901 esp_err_t apds9930_clearAmbientLightInt(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
902 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
903 uint8_t val = APDS9930_CLEAR_ALS_INT;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
904
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
905 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
906 I2C_DEV_CHECK(&dev->i2c_dev, i2c_dev_write(&dev->i2c_dev, NULL, 0, &val, 1));
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
907 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
908
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
909 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
911
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
912
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
913 esp_err_t apds9930_clearProximityInt(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
914 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
915 uint8_t val = APDS9930_CLEAR_PROX_INT;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
916
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
917 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
918 I2C_DEV_CHECK(&dev->i2c_dev, i2c_dev_write(&dev->i2c_dev, NULL, 0, &val, 1));
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
919 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
920
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
921 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
922 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
923
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
925 esp_err_t apds9930_clearAllInts(apds9930_t *dev)
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
926 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
927 uint8_t val = APDS9930_CLEAR_ALL_INTS;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
928
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
929 I2C_DEV_TAKE_MUTEX(&dev->i2c_dev);
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
930 I2C_DEV_CHECK(&dev->i2c_dev, i2c_dev_write(&dev->i2c_dev, NULL, 0, &val, 1));
12
bb72d448e282 In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
931 I2C_DEV_GIVE_MUTEX(&dev->i2c_dev);
11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
932
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
933 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
934 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
935

mercurial