Thu, 06 Apr 2023 20:53:06 +0200
Set the new measured deep sleep current consumption. This is half of the Wemos D1 system.
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 | static esp_err_t read_reg_8(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
|
122 | { |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
123 | I2C_DEV_TAKE_MUTEX(&dev->i2c_dev); |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
124 | I2C_DEV_CHECK(&dev->i2c_dev, read_reg_8_nolock(dev, reg, data)); |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
125 | 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
|
126 | |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
127 | return ESP_OK; |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
128 | } |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
129 | |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
130 | |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
131 | |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
132 | |
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
|
133 | 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
|
134 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | 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
|
136 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | |
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
|
139 | 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
|
140 | { |
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 | 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
|
142 | |
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | } |
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
|
147 | |
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
|
148 | 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
|
149 | 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
|
150 | 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
|
151 | 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
|
152 | #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
|
153 | 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
|
154 | #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
|
155 | |
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
|
156 | 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
|
157 | } |
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 | |
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
|
160 | 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
|
161 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | 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
|
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 | 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
|
165 | } |
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 | |
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 | |
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 | 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
|
169 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
170 | 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
|
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 | 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
|
173 | 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
|
174 | |
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
|
175 | 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
|
176 | 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
|
177 | 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
|
178 | "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
|
179 | 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
|
180 | } |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
181 | 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
|
182 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
183 | /* 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
|
184 | 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
|
185 | 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
|
186 | 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
|
187 | } |
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 | |
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 | /* 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
|
190 | 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
|
191 | 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
|
192 | 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
|
193 | 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
|
194 | 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
|
195 | 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
|
196 | 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
|
197 | |
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
|
198 | 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
|
199 | 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
|
200 | 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
|
201 | 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
|
202 | 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
|
203 | 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
|
204 | 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
|
205 | 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
|
206 | |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
207 | 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
|
208 | 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
|
209 | 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
|
210 | |
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
|
211 | 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
|
212 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
213 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
214 | /******************************************************************************* |
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 | * 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
|
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 | 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
|
219 | { |
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 | 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
|
221 | |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
222 | /* 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
|
223 | 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
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | } |
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 | |
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
|
229 | 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
|
230 | 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
|
231 | } |
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 | |
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 | |
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
|
234 | 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
|
235 | { |
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 | 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
|
237 | |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
238 | // 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
|
239 | /* Read current ENABLE register */ |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
240 | 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
|
241 | I2C_DEV_CHECK(&dev->i2c_dev, read_reg_8_nolock(dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, ®_val)); |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
242 | // i2c_dev_read_reg(&dev->i2c_dev, (uint8_t)APDS9930_ENABLE, ®_val, 1); |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
243 | 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
|
244 | ESP_LOGI(TAG, "apds9930_setMode(%d, %d) get=%02x", mode, enable, reg_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
|
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 | /* 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
|
247 | 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
|
248 | 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
|
249 | 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
|
250 | 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
|
251 | } 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
|
252 | 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
|
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 | } 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
|
255 | 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
|
256 | 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
|
257 | } 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
|
258 | 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
|
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 | } |
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 | |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
262 | ESP_LOGI(TAG, "apds9930_setMode write %02x", reg_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
|
263 | /* 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
|
264 | 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
|
265 | I2C_DEV_CHECK(&dev->i2c_dev, write_reg_8_nolock(dev, APDS9930_ENABLE | APDS9930_AUTO_INCREMENT, reg_val)); |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
266 | // CHECK_LOGE(dev, write_register8(&dev->i2c_dev, APDS9930_ENABLE, reg_val), "Enable register"); |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
267 | // CHECK_LOGE(dev, i2c_dev_write_reg(&dev->i2c_dev, (uint8_t)APDS9930_ENABLE, ®_val, 1), "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
|
268 | 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
|
269 | |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
270 | //vTaskDelay(12 / portTICK_PERIOD_MS); |
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
|
271 | 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
|
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 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | |
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
|
275 | 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
|
276 | { |
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 | 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
|
278 | |
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 | /* 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
|
280 | 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
|
281 | 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
|
282 | 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
|
283 | } 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
|
284 | 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
|
285 | } |
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 | 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
|
287 | 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
|
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 | 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
|
290 | } |
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 | |
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 | |
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
|
293 | 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
|
294 | { |
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_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
|
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_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
|
298 | 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
|
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_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
|
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 | /* 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
|
309 | 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
|
310 | 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
|
311 | 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
|
312 | 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
|
313 | } 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
|
314 | 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
|
315 | } |
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 | 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
|
317 | 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
|
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 | 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
|
320 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
321 | |
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 | |
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
|
323 | 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
|
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 | 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
|
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 | 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
|
328 | 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
|
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 | 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
|
331 | } |
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 | |
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
|
334 | 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
|
335 | { |
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 | 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
|
337 | } |
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 | |
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 | |
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
|
340 | 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
|
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 | 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
|
343 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
344 | |
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 | /******************************************************************************* |
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 | * 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
|
348 | ******************************************************************************/ |
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 | |
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
|
350 | 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
|
351 | { |
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 | 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
|
353 | |
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 | /* 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
|
355 | 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
|
356 | 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
|
357 | *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
|
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 | 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
|
360 | } |
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 | |
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
|
363 | 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
|
364 | { |
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 | 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
|
366 | |
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 | /* 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
|
368 | 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
|
369 | 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
|
370 | *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
|
371 | |
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 | 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
|
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 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
375 | |
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
|
376 | 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
|
377 | { |
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 | 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
|
379 | 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
|
380 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
381 | 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
|
382 | 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
|
383 | 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
|
384 | 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
|
385 | 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
|
386 | //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
|
387 | 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
|
388 | 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
|
389 | 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
|
390 | 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
|
391 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
392 | |
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 | |
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
|
394 | 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
|
395 | { |
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 | 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
|
397 | 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
|
398 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
399 | 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
|
400 | 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
|
401 | 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
|
402 | 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
|
403 | 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
|
404 | //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
|
405 | // 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
|
406 | 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
|
407 | 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
|
408 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
409 | |
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 | |
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
|
411 | 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
|
412 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
413 | uint8_t val_byte; |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
414 | 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
|
415 | *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
|
416 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
417 | 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
|
418 | |
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
|
419 | 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
|
420 | /* Read value from channel 0 */ |
17
1599e696d947
Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
421 | CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, (uint8_t)APDS9930_Ch0DATAL | APDS9930_AUTO_INCREMENT, &val_byte, 1), "Read ch0 low"); |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
422 | ESP_LOGI(TAG, "l %02x", val_byte); |
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
|
423 | *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
|
424 | CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, (uint8_t)APDS9930_Ch0DATAH | APDS9930_AUTO_INCREMENT, &val_byte, 1), "Read ch0 high"); |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
425 | ESP_LOGI(TAG, "h %02x", val_byte); |
11
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
426 | *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
|
427 | 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
|
428 | ESP_LOGI(TAG, "val %04x", *val); |
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
429 | |
17
1599e696d947
Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
430 | CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, (uint8_t)APDS9930_Ch0DATAL | APDS9930_AUTO_INCREMENT, &val_word, 2), "Read ch0 16"); |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
431 | ESP_LOGI(TAG, "16 %04x", 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
|
432 | |
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 | 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
|
434 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
435 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
436 | |
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
|
437 | 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
|
438 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
439 | 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
|
440 | *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
|
441 | |
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
|
442 | 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
|
443 | /* Read value from channel 1 */ |
17
1599e696d947
Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
444 | CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_Ch1DATAL | APDS9930_AUTO_INCREMENT, &val_byte, 1), "Read ch1 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
|
445 | *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
|
446 | CHECK_LOGE(dev, i2c_dev_read_reg(&dev->i2c_dev, APDS9930_Ch1DATAH | APDS9930_AUTO_INCREMENT, &val_byte, 1), "Read ch1 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
|
447 | *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
|
448 | 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
|
449 | |
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 | 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
|
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 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
453 | /******************************************************************************* |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
454 | * 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
|
455 | ******************************************************************************/ |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
456 | |
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
|
457 | 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
|
458 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
459 | *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 | 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
|
461 | |
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
|
462 | 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
|
463 | /* 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
|
464 | 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
|
465 | *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
|
466 | 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
|
467 | *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
|
468 | 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
|
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 | 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
|
471 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
472 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
473 | /******************************************************************************* |
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 | * 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
|
475 | ******************************************************************************/ |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
476 | |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
477 | 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
|
478 | { |
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 | 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
|
480 | 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
|
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 | /* 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
|
483 | 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
|
484 | 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
|
485 | 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
|
486 | } |
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 | 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
|
488 | 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
|
489 | 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
|
490 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
491 | I2C_DEV_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
|
492 | 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
|
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 | 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
|
495 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
496 | |
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 | 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
|
499 | { |
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 | 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
|
501 | 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
|
502 | 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
|
503 | 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
|
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 | 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
|
506 | 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
|
507 | 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
|
508 | 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
|
509 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
510 | 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
|
511 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
512 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
513 | |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
514 | 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
|
515 | { |
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 | 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
|
517 | 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
|
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 | /* 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
|
520 | 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
|
521 | 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
|
522 | 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
|
523 | } |
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 | 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
|
525 | 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
|
526 | 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
|
527 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
528 | I2C_DEV_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 | 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
|
530 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
531 | 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
|
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 | |
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 | |
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
|
535 | 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
|
536 | { |
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 | 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
|
538 | 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
|
539 | 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
|
540 | 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
|
541 | |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
542 | I2C_DEV_TAKE_MUTEX(&dev->i2c_dev); |
17
1599e696d947
Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
543 | 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
|
544 | 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
|
545 | 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
|
546 | |
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 | 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
|
548 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
549 | |
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 | |
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
|
551 | 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
|
552 | { |
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 | 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
|
554 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
555 | /* 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
|
556 | 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
|
557 | 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
|
558 | 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
|
559 | 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
|
560 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
561 | I2C_DEV_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
|
562 | |
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 | /* 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
|
564 | 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
|
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 | 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
|
567 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
568 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
569 | |
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
|
570 | 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
|
571 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
572 | 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
|
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 | /* 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
|
575 | 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
|
576 | 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
|
577 | |
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 | /* 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
|
579 | 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
|
580 | 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
|
581 | 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
|
582 | 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
|
583 | |
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 | /* 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
|
585 | 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
|
586 | 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
|
587 | |
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 | 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
|
589 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
590 | |
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 | |
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
|
592 | 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
|
593 | { |
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 | 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
|
595 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
596 | /* 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
|
597 | 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
|
598 | 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
|
599 | 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
|
600 | 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
|
601 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
602 | I2C_DEV_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
|
603 | |
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 | /* 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
|
605 | 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
|
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 | 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
|
608 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
609 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
610 | |
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
|
611 | 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
|
612 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
613 | 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
|
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 | /* 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
|
616 | 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
|
617 | 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
|
618 | |
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 | /* 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
|
620 | 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
|
621 | 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
|
622 | 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
|
623 | 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
|
624 | |
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 | /* 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
|
626 | 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
|
627 | 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
|
628 | |
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 | 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
|
630 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
631 | |
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 | |
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
|
633 | 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
|
634 | { |
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 | 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
|
636 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
637 | /* 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
|
638 | 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
|
639 | 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
|
640 | 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
|
641 | 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
|
642 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
643 | I2C_DEV_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
|
644 | |
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 | /* 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
|
646 | 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
|
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 | 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
|
649 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
650 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
651 | |
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
|
652 | 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
|
653 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
654 | 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
|
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 | /* 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
|
657 | 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
|
658 | 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
|
659 | |
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 | /* 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
|
661 | 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
|
662 | 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
|
663 | 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
|
664 | 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
|
665 | |
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 | /* 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
|
667 | 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
|
668 | 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
|
669 | |
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 | 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
|
671 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
672 | |
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 | |
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
|
674 | 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
|
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 | 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
|
677 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
678 | /* 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
|
679 | 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
|
680 | 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
|
681 | 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
|
682 | 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
|
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 | 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
|
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 | /* 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
|
687 | 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
|
688 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
689 | 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
|
690 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
691 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
692 | |
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
|
693 | 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
|
694 | { |
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 | 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
|
696 | |
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 | /* 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
|
698 | 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
|
699 | 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
|
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 | /* 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
|
702 | 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
|
703 | 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
|
704 | 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
|
705 | |
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 | /* 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
|
707 | 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
|
708 | 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
|
709 | |
16
b3e96bbe4ce4
First pass of debugging APDS9930 with a real chip.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
710 | 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
|
711 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
712 | |
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 | |
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
|
714 | 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
|
715 | { |
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 | 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
|
717 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
718 | /* 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
|
719 | 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
|
720 | 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
|
721 | 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
|
722 | 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
|
723 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
724 | I2C_DEV_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
|
725 | |
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 | /* 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
|
727 | 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
|
728 | |
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 | 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
|
730 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
731 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
732 | |
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
|
733 | 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
|
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 | 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
|
736 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
737 | /* 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
|
738 | 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
|
739 | 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
|
740 | |
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 | /* 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
|
742 | 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
|
743 | 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
|
744 | 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
|
745 | 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
|
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
|
747 | /* 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
|
748 | 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
|
749 | 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
|
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 | 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
|
752 | } |
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 | |
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 | 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
|
756 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
757 | 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
|
758 | *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
|
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 | /* 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
|
761 | 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
|
762 | 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
|
763 | *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
|
764 | } |
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 | *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
|
766 | 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
|
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 | } |
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
|
769 | 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
|
770 | *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
|
771 | |
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 | 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
|
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 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
775 | |
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
|
776 | 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
|
777 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
778 | 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
|
779 | 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
|
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 | /* 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
|
782 | 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
|
783 | 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
|
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 | 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
|
786 | 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
|
787 | 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
|
788 | 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
|
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 | 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
|
791 | } |
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 | |
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 | 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
|
795 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
796 | 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
|
797 | *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
|
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 | /* 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
|
800 | 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
|
801 | 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
|
802 | *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
|
803 | } |
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 | *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
|
805 | 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
|
806 | *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
|
807 | } |
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_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
|
809 | *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
|
810 | |
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 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
|
812 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
813 | |
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 | |
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
|
815 | 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
|
816 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
817 | 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
|
818 | 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
|
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 | /* 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
|
821 | 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
|
822 | 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
|
823 | |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
824 | I2C_DEV_TAKE_MUTEX(&dev->i2c_dev); |
17
1599e696d947
Code changes to try to fix the not working ADPS9930 driver.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
825 | 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
|
826 | 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
|
827 | 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
|
828 | |
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 | 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
|
830 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
831 | |
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 | |
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
|
833 | 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
|
834 | { |
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 | 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
|
836 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
837 | /* 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
|
838 | 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
|
839 | 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
|
840 | 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
|
841 | 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
|
842 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
843 | I2C_DEV_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
|
844 | |
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 | /* 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
|
846 | 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
|
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 | 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
|
849 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
850 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
851 | |
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
|
852 | 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
|
853 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
854 | 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
|
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 | /* 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
|
857 | 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
|
858 | 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
|
859 | |
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 | /* 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
|
861 | 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
|
862 | 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
|
863 | 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
|
864 | 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
|
865 | |
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 | /* 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
|
867 | 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
|
868 | 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
|
869 | |
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 | 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
|
871 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
872 | |
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 | |
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
|
874 | 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
|
875 | { |
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 | 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
|
877 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
878 | /* 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
|
879 | 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
|
880 | 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
|
881 | 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
|
882 | 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
|
883 | } |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
884 | I2C_DEV_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
|
885 | |
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 | /* 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
|
887 | 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
|
888 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
889 | 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
|
890 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
891 | |
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 | |
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
|
893 | 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
|
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 | 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
|
896 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
897 | /* 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
|
898 | 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
|
899 | 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
|
900 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
901 | /* 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
|
902 | 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
|
903 | 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
|
904 | 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
|
905 | 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
|
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 | /* 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
|
908 | 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
|
909 | 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
|
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 | 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
|
912 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
913 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
914 | |
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 | 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
|
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 | 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
|
918 | |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
919 | I2C_DEV_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
|
920 | 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
|
921 | 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
|
922 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
923 | 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
|
924 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
925 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
926 | |
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
|
927 | 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
|
928 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
929 | 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
|
930 | |
12
bb72d448e282
In the esp-idf-lib the adps9930 driver uses a device descriptor structure instead of just i2c_dev_t. Fixed a linking issue. Added APDS9930 task. Added getLightValues function. Added wifi quality value to the MQTT payload. The payload is complete and will be published.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
931 | I2C_DEV_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
|
932 | 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
|
933 | 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
|
934 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
935 | 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
|
936 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
937 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
938 | |
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
|
939 | 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
|
940 | { |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
941 | 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
|
942 | |
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
|
943 | 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
|
944 | 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
|
945 | 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
|
946 | |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
947 | 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
|
948 | } |
bdc123ae7b49
Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
949 |