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

Mon, 17 Apr 2023 16:20:58 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 17 Apr 2023 16:20:58 +0200
changeset 32
84e54b14e7db
parent 21
df8564c9701e
child 37
50dbb626fbab
permissions
-rw-r--r--

Version 0.4.1 Measure internal chip temperature, range -10 to 80. Result available in mqtt json payload.

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);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 if ((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
364 iac = Ch0 - APDS9930_ALS_B * 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
365 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
366 iac = 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
367 //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
368 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
369 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
370 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
371 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
372 }
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374
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
375 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
376 {
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 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
378 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
379
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 unsigned long ALSIT = 2.73 * (256 - APDS9930_DEFAULT_ATIME);
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 if ((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
382 iac = Ch0 - APDS9930_ALS_B * 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
383 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
384 iac = 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
385 //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
386 // 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
387 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
388 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
389 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391
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
392 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
393 {
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
394 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
395 *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
396
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 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
398
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
399 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
400 /* 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
401 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
402 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
403 *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
404
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408
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
409 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
410 {
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
411 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
412 *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
413
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
414 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
415 /* 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
416 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
417 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
418 *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
419
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 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
421 }
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 * 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
425 ******************************************************************************/
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
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
427 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
428 {
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 *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
430 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
431
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
432 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
433 /* 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
434 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
435 *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
436 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
437 *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
438 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
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443 /*******************************************************************************
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 * 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
445 ******************************************************************************/
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
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
447 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
448 {
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 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
450 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
451
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
452 /* 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
453 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
454 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
455 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
456 }
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 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
458 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
459 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
460 }
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
461 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
462 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
463
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 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
465 }
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
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
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
468 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
469 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 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
471 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
472 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
473 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
474
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
475 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
476 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
477 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
478 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
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 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
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 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
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 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
487 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
488
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 /* 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
490 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
491 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
492 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
493 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 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
495 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
496 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
497 }
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
498 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
499 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
500
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 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
502 }
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
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
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
505 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
506 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507 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
508 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
509 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
510 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
511
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
512 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
513 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
514 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
515 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
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 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
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 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
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 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
524
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 /* 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
526 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
527 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
528 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
529 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
530 }
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 /* 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
534 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
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 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
537 }
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
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
540 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
541 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
542 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
543
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544 /* 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
545 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
546 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
547
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 /* 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
549 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
550 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
551 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
552 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
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 /* 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
555 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
556 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
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561
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
562 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
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 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
565
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 /* 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
567 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
568 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
569 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
570 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
571 }
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 /* 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
575 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
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 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
578 }
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
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
581 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
582 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 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
584
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 /* 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
586 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
587 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
588
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 /* 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
590 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
591 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
592 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
593 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
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 /* 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
596 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
597 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
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602
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
603 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
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 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
606
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 /* 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
608 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
609 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
610 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
611 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
612 }
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 /* 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
616 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
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 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
619 }
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
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
622 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
623 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
624 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
625
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
626 /* 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
627 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
628 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
629
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 /* 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
631 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
632 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
633 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
634 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
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 /* 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
637 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
638 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
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643
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
644 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
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 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
647
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 /* 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
649 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
650 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
651 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
652 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
653 }
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 /* 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
657 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
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 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
660 }
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
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
663 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
664 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
665 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
666
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
667 /* 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
668 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
669 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
670
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 /* 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
672 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
673 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
674 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
675
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 /* 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
677 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
678 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
679
16
b3e96bbe4ce4 First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
680 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
681 }
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
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 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
685 {
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 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
687
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 /* 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
689 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
690 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
691 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
692 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
693 }
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
696 /* 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
697 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
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 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
700 }
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
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
703 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
704 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
705 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
706
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707 /* 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
708 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
709 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
710
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 /* 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
712 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
713 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
714 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
715 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
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 /* 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
718 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
719 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
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724
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
725 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
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 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
728 *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
729
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 /* 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
731 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
732 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
733 *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
734 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735 *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
736 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
737 *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
738 }
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
739 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
740 *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
741
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 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
743 }
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
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
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
746 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
747 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
748 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
749 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
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 /* 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
752 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
753 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
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_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
756 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
757 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
758 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
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 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
761 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
762
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
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
764 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
765 {
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 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
767 *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
768
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 /* 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
770 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
771 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
772 *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
773 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 *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
775 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
776 *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
777 }
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
778 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
779 *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
780
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 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
782 }
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
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
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
785 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
786 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
787 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
788 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
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 /* 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
791 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
792 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
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_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
795 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
796 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
797 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
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 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
800 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
801
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
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
803 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
804 {
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 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
806
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 /* 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
808 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
809 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
810 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
811 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
812 }
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 /* 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
816 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
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 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
819 }
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
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
822 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
823 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824 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
825
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826 /* 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
827 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
828 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
829
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 /* 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
831 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
832 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
833 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
834 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
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 /* 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
837 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
838 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
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
843
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
844 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
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 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
847
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 /* 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
849 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
850 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
851 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
852 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
853 }
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 /* 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
857 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
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 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
860 }
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
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
863 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
864 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
865 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
866
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
867 /* 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
868 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
869 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
870
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 /* 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
872 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
873 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
874 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
875 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
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 /* 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
878 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
879 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
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 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
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
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884
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
885 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
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 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
888
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
889 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
890 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
891 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
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 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
894 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
895
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
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
897 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
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 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
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 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
902 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
903 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
904
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
905 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
906 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
907
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
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
909 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
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 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
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 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
914 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
915 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
916
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
917 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
918 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
919

mercurial