diff --git a/html/_wipper_snapper___i2_c_8h.html b/html/_wipper_snapper___i2_c_8h.html index 64efd0790..32aa79a6c 100644 --- a/html/_wipper_snapper___i2_c_8h.html +++ b/html/_wipper_snapper___i2_c_8h.html @@ -106,6 +106,7 @@ #include "drivers/WipperSnapper_I2C_Driver_SCD30.h"
#include "drivers/WipperSnapper_I2C_Driver_SCD4X.h"
#include "drivers/WipperSnapper_I2C_Driver_SEN5X.h"
+#include "drivers/WipperSnapper_I2C_Driver_SEN6X.h"
#include "drivers/WipperSnapper_I2C_Driver_SGP30.h"
#include "drivers/WipperSnapper_I2C_Driver_SGP40.h"
#include "drivers/WipperSnapper_I2C_Driver_SHT3X.h"
@@ -117,6 +118,7 @@ #include "drivers/WipperSnapper_I2C_Driver_TSL2591.h"
#include "drivers/WipperSnapper_I2C_Driver_VCNL4020.h"
#include "drivers/WipperSnapper_I2C_Driver_VCNL4040.h"
+#include "drivers/WipperSnapper_I2C_Driver_VCNL4200.h"
#include "drivers/WipperSnapper_I2C_Driver_VEML7700.h"
#include "drivers/WipperSnapper_I2C_Driver_VL53L0X.h"
#include "drivers/WipperSnapper_I2C_Driver_VL53L1X.h"
diff --git a/html/_wipper_snapper___i2_c_8h_source.html b/html/_wipper_snapper___i2_c_8h_source.html index 9bdf4d2d6..57d1a508f 100644 --- a/html/_wipper_snapper___i2_c_8h_source.html +++ b/html/_wipper_snapper___i2_c_8h_source.html @@ -66,7 +66,7 @@
WipperSnapper_I2C.h
-Go to the documentation of this file.
1 
16 #ifndef WipperSnapper_Component_I2C_H
17 #define WipperSnapper_Component_I2C_H
18 
19 #include "Wippersnapper.h"
20 #include <Wire.h>
21 
25 #include "drivers/WipperSnapper_I2C_Driver_BH1750.h"
56 #include "drivers/WipperSnapper_I2C_Driver_SGP30.h"
73 
74 #define I2C_TIMEOUT_MS 50
75 
76 // forward decl.
77 class Wippersnapper;
78 
79 /**************************************************************************/
83 /**************************************************************************/
85 public:
87  wippersnapper_i2c_v1_I2CBusInitRequest *msgInitRequest);
89  bool isInitialized();
90  wippersnapper_i2c_v1_BusResponse getBusStatus();
91 
92  wippersnapper_i2c_v1_I2CBusScanResponse scanAddresses();
93  bool
94  initI2CDevice(wippersnapper_i2c_v1_I2CDeviceInitRequest *msgDeviceInitReq);
95 
97  wippersnapper_i2c_v1_I2CDeviceUpdateRequest *msgDeviceUpdateReq);
98  void deinitI2CDevice(
99  wippersnapper_i2c_v1_I2CDeviceDeinitRequest *msgDeviceDeinitReq);
100 
101  void update();
102 
103  void sensorEventRead(
104  std::vector<WipperSnapper_I2C_Driver *>::iterator &iter,
105  unsigned long curTime,
106  wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
107  bool (WipperSnapper_I2C_Driver::*getEventFunc)(sensors_event_t *),
108  long (WipperSnapper_I2C_Driver::*getPeriodFunc)(),
109  long (WipperSnapper_I2C_Driver::*getPeriodPrvFunc)(),
110  void (WipperSnapper_I2C_Driver::*setPeriodPrvFunc)(long),
111  wippersnapper_i2c_v1_SensorType sensorType, const char *sensorName,
112  const char *unit, sensors_event_t event,
113  float sensors_event_t::*valueMember, bool &sensorsReturningFalse,
114  int &retries);
115 
116  void fillEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
117  float value,
118  wippersnapper_i2c_v1_SensorType sensorType);
119 
120  void
121  displayDeviceEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
122  uint32_t sensorAddress);
123 
125  wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
126  uint32_t sensorAddress);
127 
128 private:
129  bool _isInit = false;
130  int32_t _portNum;
131  TwoWire *_i2c = nullptr;
132  wippersnapper_i2c_v1_BusResponse _busStatusResponse;
133  std::vector<WipperSnapper_I2C_Driver *> drivers;
134  // Sensor driver objects
135  WipperSnapper_I2C_Driver_AHTX0 *_ahtx0 = nullptr;
136  WipperSnapper_I2C_Driver_DPS310 *_dps310 = nullptr;
137  WipperSnapper_I2C_Driver_DS2484 *_ds2484 = nullptr;
138  WipperSnapper_I2C_Driver_ENS160 *_ens160 = nullptr;
139  WipperSnapper_I2C_Driver_SCD30 *_scd30 = nullptr;
140  WipperSnapper_I2C_Driver_BH1750 *_bh1750 = nullptr;
141  WipperSnapper_I2C_Driver_BME280 *_bme280 = nullptr;
142  WipperSnapper_I2C_Driver_BMP280 *_bmp280 = nullptr;
143  WipperSnapper_I2C_Driver_BMP3XX *_bmp3xx = nullptr;
144  WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
145  WipperSnapper_I2C_Driver_HDC302X *_hdc302x = nullptr;
146  WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
147  WipperSnapper_I2C_Driver_HTU21D *_htu21d = nullptr;
148  WipperSnapper_I2C_Driver_HTU31D *_htu31d = nullptr;
149  WipperSnapper_I2C_Driver_INA219 *_ina219 = nullptr;
150  WipperSnapper_I2C_Driver_LTR329_LTR303 *_ltr329 = nullptr;
151  WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr;
152  WipperSnapper_I2C_Driver_MCP3421 *_mcp3421 = nullptr;
153  WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
154  WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
155  WipperSnapper_I2C_Driver_MPRLS *_mprls = nullptr;
156  WipperSnapper_I2C_Driver_MS8607 *_ms8607 = nullptr;
157  WipperSnapper_I2C_Driver_NAU7802 *_nau7802 = nullptr;
158  WipperSnapper_I2C_Driver_TMP117 *_tmp117 = nullptr;
159  WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
160  WipperSnapper_I2C_Driver_VCNL4020 *_vcnl4020 = nullptr;
161  WipperSnapper_I2C_Driver_VCNL4040 *_vcnl4040 = nullptr;
162  WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
163  WipperSnapper_I2C_Driver_SCD4X *_scd40 = nullptr;
164  WipperSnapper_I2C_Driver_SEN5X *_sen5x = nullptr;
165  WipperSnapper_I2C_Driver_SGP30 *_sgp30 = nullptr;
166  WipperSnapper_I2C_Driver_SGP40 *_sgp40 = nullptr;
167  WipperSnapper_I2C_Driver_PCT2075 *_pct2075 = nullptr;
168  WipperSnapper_I2C_Driver_PM25 *_pm25 = nullptr;
169  WipperSnapper_I2C_Driver_SI7021 *_si7021 = nullptr;
170  WipperSnapper_I2C_Driver_SHT4X *_sht4x = nullptr;
171  WipperSnapper_I2C_Driver_SHT3X *_sht3x = nullptr;
172  WipperSnapper_I2C_Driver_SHTC3 *_shtc3 = nullptr;
173  WipperSnapper_I2C_Driver_LC709203F *_lc = nullptr;
174  WipperSnapper_I2C_Driver_LPS22HB *_lps22hb = nullptr;
175  WipperSnapper_I2C_Driver_LPS25HB *_lps25hb = nullptr;
176  WipperSnapper_I2C_Driver_LPS3XHW *_lps3xhw = nullptr;
178  WipperSnapper_I2C_Driver_VL53L0X *_vl53l0x = nullptr;
179  WipperSnapper_I2C_Driver_VL53L1X *_vl53l1x = nullptr;
180  WipperSnapper_I2C_Driver_VL53L4CD *_vl53l4cd = nullptr;
181  WipperSnapper_I2C_Driver_VL53L4CX *_vl53l4cx = nullptr;
182  WipperSnapper_I2C_Driver_VL6180X *_vl6180x = nullptr;
183  WipperSnapper_I2C_Driver_MAX17048 *_max17048 = nullptr;
184  WipperSnapper_I2C_Driver_ADT7410 *_adt7410 = nullptr;
185 };
186 extern Wippersnapper WS;
187 
188 #endif // WipperSnapper_Component_I2C_H
Class that provides an interface with the I2C bus.
Definition: WipperSnapper_I2C.h:84
+Go to the documentation of this file.
1 
16 #ifndef WipperSnapper_Component_I2C_H
17 #define WipperSnapper_Component_I2C_H
18 
19 #include "Wippersnapper.h"
20 #include <Wire.h>
21 
25 #include "drivers/WipperSnapper_I2C_Driver_BH1750.h"
57 #include "drivers/WipperSnapper_I2C_Driver_SGP30.h"
75 
76 #define I2C_TIMEOUT_MS 50
77 
78 // forward decl.
79 class Wippersnapper;
80 
81 /**************************************************************************/
85 /**************************************************************************/
87 public:
89  wippersnapper_i2c_v1_I2CBusInitRequest *msgInitRequest);
91  bool isInitialized();
92  wippersnapper_i2c_v1_BusResponse getBusStatus();
93 
94  wippersnapper_i2c_v1_I2CBusScanResponse scanAddresses();
95  bool
96  initI2CDevice(wippersnapper_i2c_v1_I2CDeviceInitRequest *msgDeviceInitReq);
97 
99  wippersnapper_i2c_v1_I2CDeviceUpdateRequest *msgDeviceUpdateReq);
100  void deinitI2CDevice(
101  wippersnapper_i2c_v1_I2CDeviceDeinitRequest *msgDeviceDeinitReq);
102 
103  void update();
104 
105  void sensorEventRead(
106  std::vector<WipperSnapper_I2C_Driver *>::iterator &iter,
107  unsigned long curTime,
108  wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
109  bool (WipperSnapper_I2C_Driver::*getEventFunc)(sensors_event_t *),
110  long (WipperSnapper_I2C_Driver::*getPeriodFunc)(),
111  long (WipperSnapper_I2C_Driver::*getPeriodPrvFunc)(),
112  void (WipperSnapper_I2C_Driver::*setPeriodPrvFunc)(long),
113  wippersnapper_i2c_v1_SensorType sensorType, const char *sensorName,
114  const char *unit, sensors_event_t event,
115  float sensors_event_t::*valueMember, bool &sensorsReturningFalse,
116  int &retries);
117 
118  void fillEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
119  float value,
120  wippersnapper_i2c_v1_SensorType sensorType);
121 
122  void
123  displayDeviceEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
124  uint32_t sensorAddress);
125 
127  wippersnapper_signal_v1_I2CResponse *msgi2cResponse,
128  uint32_t sensorAddress);
129 
130 private:
131  bool _isInit = false;
132  int32_t _portNum;
133  TwoWire *_i2c = nullptr;
134  wippersnapper_i2c_v1_BusResponse _busStatusResponse;
135  std::vector<WipperSnapper_I2C_Driver *> drivers;
136  // Sensor driver objects
137  WipperSnapper_I2C_Driver_AHTX0 *_ahtx0 = nullptr;
138  WipperSnapper_I2C_Driver_DPS310 *_dps310 = nullptr;
139  WipperSnapper_I2C_Driver_DS2484 *_ds2484 = nullptr;
140  WipperSnapper_I2C_Driver_ENS160 *_ens160 = nullptr;
141  WipperSnapper_I2C_Driver_SCD30 *_scd30 = nullptr;
142  WipperSnapper_I2C_Driver_BH1750 *_bh1750 = nullptr;
143  WipperSnapper_I2C_Driver_BME280 *_bme280 = nullptr;
144  WipperSnapper_I2C_Driver_BMP280 *_bmp280 = nullptr;
145  WipperSnapper_I2C_Driver_BMP3XX *_bmp3xx = nullptr;
146  WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
147  WipperSnapper_I2C_Driver_HDC302X *_hdc302x = nullptr;
148  WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
149  WipperSnapper_I2C_Driver_HTU21D *_htu21d = nullptr;
150  WipperSnapper_I2C_Driver_HTU31D *_htu31d = nullptr;
151  WipperSnapper_I2C_Driver_INA219 *_ina219 = nullptr;
152  WipperSnapper_I2C_Driver_LTR329_LTR303 *_ltr329 = nullptr;
153  WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr;
154  WipperSnapper_I2C_Driver_MCP3421 *_mcp3421 = nullptr;
155  WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
156  WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
157  WipperSnapper_I2C_Driver_MPRLS *_mprls = nullptr;
158  WipperSnapper_I2C_Driver_MS8607 *_ms8607 = nullptr;
159  WipperSnapper_I2C_Driver_NAU7802 *_nau7802 = nullptr;
160  WipperSnapper_I2C_Driver_TMP117 *_tmp117 = nullptr;
161  WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
162  WipperSnapper_I2C_Driver_VCNL4020 *_vcnl4020 = nullptr;
163  WipperSnapper_I2C_Driver_VCNL4040 *_vcnl4040 = nullptr;
164  WipperSnapper_I2C_Driver_VCNL4200 *_vcnl4200 = nullptr;
165  WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
166  WipperSnapper_I2C_Driver_SCD4X *_scd40 = nullptr;
167  WipperSnapper_I2C_Driver_SEN5X *_sen5x = nullptr;
168  WipperSnapper_I2C_Driver_SEN6X *_sen6x = nullptr;
169  WipperSnapper_I2C_Driver_SGP30 *_sgp30 = nullptr;
170  WipperSnapper_I2C_Driver_SGP40 *_sgp40 = nullptr;
171  WipperSnapper_I2C_Driver_PCT2075 *_pct2075 = nullptr;
172  WipperSnapper_I2C_Driver_PM25 *_pm25 = nullptr;
173  WipperSnapper_I2C_Driver_SI7021 *_si7021 = nullptr;
174  WipperSnapper_I2C_Driver_SHT4X *_sht4x = nullptr;
175  WipperSnapper_I2C_Driver_SHT3X *_sht3x = nullptr;
176  WipperSnapper_I2C_Driver_SHTC3 *_shtc3 = nullptr;
177  WipperSnapper_I2C_Driver_LC709203F *_lc = nullptr;
178  WipperSnapper_I2C_Driver_LPS22HB *_lps22hb = nullptr;
179  WipperSnapper_I2C_Driver_LPS25HB *_lps25hb = nullptr;
180  WipperSnapper_I2C_Driver_LPS3XHW *_lps3xhw = nullptr;
182  WipperSnapper_I2C_Driver_VL53L0X *_vl53l0x = nullptr;
183  WipperSnapper_I2C_Driver_VL53L1X *_vl53l1x = nullptr;
184  WipperSnapper_I2C_Driver_VL53L4CD *_vl53l4cd = nullptr;
185  WipperSnapper_I2C_Driver_VL53L4CX *_vl53l4cx = nullptr;
186  WipperSnapper_I2C_Driver_VL6180X *_vl6180x = nullptr;
187  WipperSnapper_I2C_Driver_MAX17048 *_max17048 = nullptr;
188  WipperSnapper_I2C_Driver_ADT7410 *_adt7410 = nullptr;
189 };
190 extern Wippersnapper WS;
191 
192 #endif // WipperSnapper_Component_I2C_H
Class that provides an interface with the I2C bus.
Definition: WipperSnapper_I2C.h:86
Class that provides a driver interface for the SCD30 sensor.
Definition: WipperSnapper_I2C_Driver_SCD30.h:27
Class that provides a sensor driver for the MS8607 PHT sensor.
Definition: WipperSnapper_I2C_Driver_MS8607.h:27
@@ -75,13 +75,14 @@
bool isInitialized()
Returns if i2c port is initialized.
Definition: WipperSnapper_I2C.cpp:125
Class that provides a driver interface for a VCNL4040 sensor.
Definition: WipperSnapper_I2C_Driver_VCNL4040.h:26
Class that provides a driver interface for the SCD40 sensor.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:29
+
wippersnapper_i2c_v1_I2CBusScanResponse scanAddresses()
Scans all I2C addresses on the bus between 0x08 and 0x7F inclusive and returns an array of the device...
Definition: WipperSnapper_I2C.cpp:145
Class that provides a driver interface for a PCT2075 sensor.
Definition: WipperSnapper_I2C_Driver_PCT2075.h:26
Class that provides a driver interface for a ADT7410 sensor.
Definition: WipperSnapper_I2C_Driver_ADT7410.h:26
Class that provides a driver interface for a VL53L4CD sensor.
Definition: WipperSnapper_I2C_Driver_VL53L4CD.h:26
-
void fillEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse, float value, wippersnapper_i2c_v1_SensorType sensorType)
Fills a sensor_event message with the sensor&#39;s value and type.
Definition: WipperSnapper_I2C.cpp:905
+
void fillEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse, float value, wippersnapper_i2c_v1_SensorType sensorType)
Fills a sensor_event message with the sensor&#39;s value and type.
Definition: WipperSnapper_I2C.cpp:933
Class that provides a driver interface for a VL6180X sensor.
Definition: WipperSnapper_I2C_Driver_VL6180X.h:27
@@ -89,7 +90,7 @@
bool initI2CDevice(wippersnapper_i2c_v1_I2CDeviceInitRequest *msgDeviceInitReq)
Initializes I2C device driver.
Definition: WipperSnapper_I2C.cpp:213
-
void displayDeviceEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse, uint32_t sensorAddress)
Displays a sensor event message on the TFT.
Definition: WipperSnapper_I2C.cpp:930
+
void displayDeviceEventMessage(wippersnapper_signal_v1_I2CResponse *msgi2cResponse, uint32_t sensorAddress)
Displays a sensor event message on the TFT.
Definition: WipperSnapper_I2C.cpp:958
Class that provides a sensor driver for the HTU31D humidity and temperature sensor.
Definition: WipperSnapper_I2C_Driver_HTU31D.h:19
Class that provides a driver interface for the PM25 sensor.
Definition: WipperSnapper_I2C_Driver_PM25.h:28
@@ -106,22 +107,23 @@
Class that provides a driver interface for a LC709203F sensor.
Definition: WipperSnapper_I2C_Driver_LC709203F.h:27
Class that provides a sensor driver for the BMP280 temperature and pressure sensor.
Definition: WipperSnapper_I2C_Driver_BMP280.h:30
-
void sensorEventRead(std::vector< WipperSnapper_I2C_Driver *>::iterator &iter, unsigned long curTime, wippersnapper_signal_v1_I2CResponse *msgi2cResponse, bool(WipperSnapper_I2C_Driver::*getEventFunc)(sensors_event_t *), long(WipperSnapper_I2C_Driver::*getPeriodFunc)(), long(WipperSnapper_I2C_Driver::*getPeriodPrvFunc)(), void(WipperSnapper_I2C_Driver::*setPeriodPrvFunc)(long), wippersnapper_i2c_v1_SensorType sensorType, const char *sensorName, const char *unit, sensors_event_t event, float sensors_event_t::*valueMember, bool &sensorsReturningFalse, int &retries)
Reads a sensor event from an I2C device driver.
Definition: WipperSnapper_I2C.cpp:1326
-
bool encodePublishI2CDeviceEventMsg(wippersnapper_signal_v1_I2CResponse *msgi2cResponse, uint32_t sensorAddress)
Encodes an I2C sensor device&#39;s signal message.
Definition: WipperSnapper_I2C.cpp:865
+
void sensorEventRead(std::vector< WipperSnapper_I2C_Driver *>::iterator &iter, unsigned long curTime, wippersnapper_signal_v1_I2CResponse *msgi2cResponse, bool(WipperSnapper_I2C_Driver::*getEventFunc)(sensors_event_t *), long(WipperSnapper_I2C_Driver::*getPeriodFunc)(), long(WipperSnapper_I2C_Driver::*getPeriodPrvFunc)(), void(WipperSnapper_I2C_Driver::*setPeriodPrvFunc)(long), wippersnapper_i2c_v1_SensorType sensorType, const char *sensorName, const char *unit, sensors_event_t event, float sensors_event_t::*valueMember, bool &sensorsReturningFalse, int &retries)
Reads a sensor event from an I2C device driver.
Definition: WipperSnapper_I2C.cpp:1354
+
bool encodePublishI2CDeviceEventMsg(wippersnapper_signal_v1_I2CResponse *msgi2cResponse, uint32_t sensorAddress)
Encodes an I2C sensor device&#39;s signal message.
Definition: WipperSnapper_I2C.cpp:893
Base class for I2C Drivers.
Definition: WipperSnapper_I2C_Driver.h:30
Class that provides a driver interface for a SGP30 sensor.
Definition: WipperSnapper_I2C_Driver_SGP30.h:12
-
Class that provides storage and functions for the Adafruit IO Wippersnapper interface.
Definition: Wippersnapper.h:278
+
Class that provides storage and functions for the Adafruit IO Wippersnapper interface.
Definition: Wippersnapper.h:283
-
Class that provides a driver interface for the SEN5X sensor.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:29
+
Class that provides a driver interface for the SEN5X sensor.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:28
+
Class that provides a driver interface for the SEN6X sensor.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:30
Class that provides a sensor driver for the HDC302X humidity and temperature sensor. This implementation uses the 1 Hz data rate.
Definition: WipperSnapper_I2C_Driver_HDC302X.h:19
WipperSnapper_Component_I2C(wippersnapper_i2c_v1_I2CBusInitRequest *msgInitRequest)
Creates a new WipperSnapper I2C component.
Definition: WipperSnapper_I2C.cpp:31
Class that provides a driver interface for the SHT4X sensor.
Definition: WipperSnapper_I2C_Driver_SHT4X.h:30
-
void deinitI2CDevice(wippersnapper_i2c_v1_I2CDeviceDeinitRequest *msgDeviceDeinitReq)
Deinitializes and deletes an I2C device driver object.
Definition: WipperSnapper_I2C.cpp:830
+
void deinitI2CDevice(wippersnapper_i2c_v1_I2CDeviceDeinitRequest *msgDeviceDeinitReq)
Deinitializes and deletes an I2C device driver object.
Definition: WipperSnapper_I2C.cpp:858
Class that provides a driver interface for the SHT3X sensor.
Definition: WipperSnapper_I2C_Driver_SHT3X.h:30
@@ -149,7 +151,8 @@
Class that provides a driver interface for a VL53L0X sensor.
Definition: WipperSnapper_I2C_Driver_VL53L0X.h:27
Class that provides a driver interface for a VL53L1X sensor.
Definition: WipperSnapper_I2C_Driver_VL53L1X.h:27
-
void updateI2CDeviceProperties(wippersnapper_i2c_v1_I2CDeviceUpdateRequest *msgDeviceUpdateReq)
Updates the properties of an I2C device driver.
Definition: WipperSnapper_I2C.cpp:802
+ +
void updateI2CDeviceProperties(wippersnapper_i2c_v1_I2CDeviceUpdateRequest *msgDeviceUpdateReq)
Updates the properties of an I2C device driver.
Definition: WipperSnapper_I2C.cpp:830
Wippersnapper WS
Definition: Wippersnapper.cpp:36
Class that provides a sensor driver for the MPRLS sensor.
Definition: WipperSnapper_I2C_Driver_MPRLS.h:27
@@ -170,6 +173,7 @@
Class that provides a driver interface for the SGP40 sensor.
Definition: WipperSnapper_I2C_Driver_SGP40.h:28
Class that provides a driver interface for a INA219 sensor.
Definition: WipperSnapper_I2C_Driver_INA219.h:26
+
Class that provides a driver interface for a VCNL4200 sensor.
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:26
Class that provides a driver interface for a MAX17048 sensor.
Definition: WipperSnapper_I2C_Driver_MAX17048.h:27
Class that provides a driver interface for the NAU7802.
Definition: WipperSnapper_I2C_Driver_NAU7802.h:29
@@ -182,7 +186,7 @@
Class that provides a driver interface for a VCNL4020 sensor.
Definition: WipperSnapper_I2C_Driver_VCNL4020.h:26
-
void update()
Queries all I2C device drivers for new values. Fills and sends an I2CSensorEvent with the sensor even...
Definition: WipperSnapper_I2C.cpp:1026
+
void update()
Queries all I2C device drivers for new values. Fills and sends an I2CSensorEvent with the sensor even...
Definition: WipperSnapper_I2C.cpp:1054
-Go to the documentation of this file.
1 
16 #ifndef WipperSnapper_I2C_Driver_H
17 #define WipperSnapper_I2C_Driver_H
18 
19 #include <Adafruit_Sensor.h>
20 #include <Arduino.h>
21 
22 #define PERIOD_24HRS_AGO_MILLIS (millis() - (24 * 60 * 60 * 1000))
23 
25 /**************************************************************************/
29 /**************************************************************************/
31 
32 public:
33  /*******************************************************************************/
41  /*******************************************************************************/
42  WipperSnapper_I2C_Driver(TwoWire *i2c, uint16_t sensorAddress) {
43  _i2c = i2c;
44  _sensorAddress = sensorAddress;
45  }
46 
47  /*******************************************************************************/
51  /*******************************************************************************/
53 
54  /*******************************************************************************/
59  /*******************************************************************************/
60  bool begin() { return false; }
61 
62  /*******************************************************************************/
70  /*******************************************************************************/
71  void setSensorPeriod(float period,
72  wippersnapper_i2c_v1_SensorType sensorType) {
73  long sensorPeriod = (long)period * 1000;
74 
75  switch (sensorType) {
76  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_AMBIENT_TEMPERATURE:
77  _tempSensorPeriod = sensorPeriod;
78  break;
79  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_RELATIVE_HUMIDITY:
80  _humidSensorPeriod = sensorPeriod;
81  break;
82  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PRESSURE:
83  _pressureSensorPeriod = sensorPeriod;
84  break;
85  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_CO2:
86  _CO2SensorPeriod = sensorPeriod;
87  break;
88  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_ECO2:
89  _ECO2SensorPeriod = sensorPeriod;
90  break;
91  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_TVOC:
92  _TVOCSensorPeriod = sensorPeriod;
93  break;
94  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_ALTITUDE:
95  _altitudeSensorPeriod = sensorPeriod;
96  break;
97  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE:
98  _objectTempSensorPeriod = sensorPeriod;
99  break;
100  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_LIGHT:
101  _lightSensorPeriod = sensorPeriod;
102  break;
103  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PM10_STD:
104  _PM10SensorPeriod = sensorPeriod;
105  break;
106  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PM25_STD:
107  _PM25SensorPeriod = sensorPeriod;
108  break;
109  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PM100_STD:
110  _PM100SensorPeriod = sensorPeriod;
111  break;
112  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_UNITLESS_PERCENT:
113  _unitlessPercentPeriod = sensorPeriod;
114  break;
115  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_VOLTAGE:
116  _voltagePeriod = sensorPeriod;
117  break;
118  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_CURRENT:
119  _currentPeriod = sensorPeriod;
120  break;
121  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PROXIMITY:
122  _proximitySensorPeriod = sensorPeriod;
123  break;
124  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_RAW:
125  _rawSensorPeriod = sensorPeriod;
126  break;
127  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_AMBIENT_TEMPERATURE_FAHRENHEIT:
128  _ambientTempFPeriod = sensorPeriod;
129  break;
130  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT:
131  _objectTempFPeriod = sensorPeriod;
132  break;
133  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_GAS_RESISTANCE:
134  _gasResistancePeriod = sensorPeriod;
135  break;
136  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_NOX_INDEX:
137  _NOxIndexPeriod = sensorPeriod;
138  break;
139  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_VOC_INDEX:
140  _VOCIndexPeriod = sensorPeriod;
141  break;
142  default:
143  break;
144  }
145  }
146 
147  /*******************************************************************************/
154  /*******************************************************************************/
155  void
156  configureDriver(wippersnapper_i2c_v1_I2CDeviceInitRequest *msgDeviceInitReq) {
157  int propertyIdx = 0; // contains the amount of i2c sensors in the
158  // msgDeviceInitReq to configure
159  while (propertyIdx < msgDeviceInitReq->i2c_device_properties_count) {
161  msgDeviceInitReq->i2c_device_properties[propertyIdx].sensor_period,
162  msgDeviceInitReq->i2c_device_properties[propertyIdx].sensor_type);
163  ++propertyIdx;
164  }
165  }
166 
167  /*******************************************************************************/
172  /*******************************************************************************/
173  uint16_t getI2CAddress() { return _sensorAddress; }
174 
175  /****************************** SENSOR_TYPE: CO2
176  * *******************************/
177  /*********************************************************************************/
183  /*********************************************************************************/
184  virtual long getSensorCO2Period() { return _CO2SensorPeriod; }
185 
186  /*********************************************************************************/
192  /*********************************************************************************/
193  virtual long getSensorCO2PeriodPrv() { return _CO2SensorPeriodPrv; }
194 
195  /*******************************************************************************/
201  /*******************************************************************************/
202  virtual void setSensorCO2PeriodPrv(long period) {
203  _CO2SensorPeriodPrv = period;
204  }
205 
206  /*******************************************************************************/
214  /*******************************************************************************/
215  virtual bool getEventCO2(sensors_event_t *co2Event) {
216  (void)
217  co2Event; // Parameter is intentionally unused in this virtual function.
218  return false;
219  }
220 
221  /****************************** SENSOR_TYPE: ECO2
222  * *******************************/
223  /*********************************************************************************/
229  /*********************************************************************************/
230  virtual long getSensorECO2Period() { return _ECO2SensorPeriod; }
231 
232  /*********************************************************************************/
238  /*********************************************************************************/
239  virtual long getSensorECO2PeriodPrv() { return _ECO2SensorPeriodPrv; }
240 
241  /*******************************************************************************/
247  /*******************************************************************************/
248  virtual void setSensorECO2PeriodPrv(long period) {
249  _ECO2SensorPeriodPrv = period;
250  }
251 
252  /*******************************************************************************/
260  /*******************************************************************************/
261  virtual bool getEventECO2(sensors_event_t *eco2Event) {
262  (void)eco2Event; // Parameter is intentionally unused in this virtual
263  // function.
264  return false;
265  }
266 
267  /****************************** SENSOR_TYPE: TVOC
268  * *******************************/
269  /*********************************************************************************/
275  /*********************************************************************************/
276  virtual long getSensorTVOCPeriod() { return _TVOCSensorPeriod; }
277 
278  /*********************************************************************************/
284  /*********************************************************************************/
285  virtual long getSensorTVOCPeriodPrv() { return _TVOCSensorPeriodPrv; }
286 
287  /*******************************************************************************/
293  /*******************************************************************************/
294  virtual void setSensorTVOCPeriodPrv(long period) {
295  _TVOCSensorPeriodPrv = period;
296  }
297 
298  /*******************************************************************************/
306  /*******************************************************************************/
307  virtual bool getEventTVOC(sensors_event_t *tvocEvent) {
308  (void)tvocEvent; // Parameter is intentionally unused in this virtual
309  // function.
310  return false;
311  }
312 
313  /********************** SENSOR_TYPE: AMBIENT TEMPERATURE (°C)
314  * ***********************/
315  /*********************************************************************************/
321  /*********************************************************************************/
323 
324  /*********************************************************************************/
331  /*********************************************************************************/
333 
334  /*******************************************************************************/
342  /*******************************************************************************/
343  virtual void setSensorAmbientTempPeriodPrv(long periodPrv) {
344  _tempSensorPeriodPrv = periodPrv;
345  }
346 
347  /*******************************************************************************/
356  /*******************************************************************************/
357  virtual bool getEventAmbientTemp(sensors_event_t *tempEvent) {
358  (void)tempEvent; // Parameter is intentionally unused in this virtual
359  // function.
360  return false;
361  }
362 
363  /************************* SENSOR_TYPE: RELATIVE_HUMIDITY
364  * ***********************/
365  /*********************************************************************************/
371  /*********************************************************************************/
373 
374  /*********************************************************************************/
380  /*********************************************************************************/
382  return _humidSensorPeriodPrv;
383  }
384 
385  /*******************************************************************************/
391  /*******************************************************************************/
392  virtual void setSensorRelativeHumidityPeriodPrv(long periodPrv) {
393  _humidSensorPeriodPrv = periodPrv;
394  }
395 
396  /*******************************************************************************/
405  /*******************************************************************************/
406  virtual bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
407  (void)humidEvent; // Parameter is intentionally unused in this virtual
408  // function.
409  return false;
410  }
411 
412  /**************************** SENSOR_TYPE: PRESSURE
413  * ****************************/
414  /*********************************************************************************/
420  /*********************************************************************************/
422 
423  /*********************************************************************************/
429  /*********************************************************************************/
431 
432  /*******************************************************************************/
438  /*******************************************************************************/
439  virtual void setSensorPressurePeriodPrv(long period) {
440  _pressureSensorPeriodPrv = period;
441  }
442 
443  /*******************************************************************************/
452  /*******************************************************************************/
453  virtual bool getEventPressure(sensors_event_t *pressureEvent) {
454  (void)pressureEvent; // Parameter is intentionally unused in this virtual
455  // function.
456  return false;
457  }
458 
459  /**************************** SENSOR_TYPE: Altitude
460  * ****************************/
461  /*********************************************************************************/
467  /*********************************************************************************/
469 
470  /*********************************************************************************/
476  /*********************************************************************************/
478 
479  /*******************************************************************************/
485  /*******************************************************************************/
486  virtual void setSensorAltitudePeriodPrv(long period) {
487  _altitudeSensorPeriodPrv = period;
488  }
489 
490  /*******************************************************************************/
499  /*******************************************************************************/
500  virtual bool getEventAltitude(sensors_event_t *altitudeEvent) {
501  (void)altitudeEvent; // Parameter is intentionally unused in this virtual
502  // function.
503  return false;
504  }
505 
506  /**************************** SENSOR_TYPE: Object_Temperature
507  * ****************************/
508  /*********************************************************************************/
515  /*********************************************************************************/
517 
518  /*********************************************************************************/
525  /*********************************************************************************/
528  }
529 
530  /*******************************************************************************/
537  /*******************************************************************************/
538  virtual void setSensorObjectTempPeriodPrv(long period) {
540  }
541 
542  /*******************************************************************************/
551  /*******************************************************************************/
552  virtual bool getEventObjectTemp(sensors_event_t *objectTempEvent) {
553  (void)objectTempEvent; // Parameter is intentionally unused in this virtual
554  // function.
555  return false;
556  }
557 
558  /**************************** SENSOR_TYPE: LIGHT
559  * ****************************/
560  /*********************************************************************************/
567  /*********************************************************************************/
568  virtual long getSensorLightPeriod() { return _lightSensorPeriod; }
569 
570  /*********************************************************************************/
577  /*********************************************************************************/
579 
580  /*******************************************************************************/
587  /*******************************************************************************/
588  virtual void setSensorLightPeriodPrv(long period) {
589  _lightSensorPeriodPrv = period;
590  }
591 
592  /*******************************************************************************/
601  /*******************************************************************************/
602  virtual bool getEventLight(sensors_event_t *lightEvent) {
603  (void)lightEvent; // Parameter is intentionally unused in this virtual
604  // function.
605  return false;
606  }
607 
608  /**************************** SENSOR_TYPE: PM10_STD
609  * ****************************/
610  /*********************************************************************************/
617  /*********************************************************************************/
618  virtual long getSensorPM10_STDPeriod() { return _PM10SensorPeriod; }
619 
620  /*********************************************************************************/
627  /*********************************************************************************/
629 
630  /*******************************************************************************/
637  /*******************************************************************************/
638  virtual void setSensorPM10_STDPeriodPrv(long period) {
639  _PM10SensorPeriodPrv = period;
640  }
641 
642  /*******************************************************************************/
651  /*******************************************************************************/
652  virtual bool getEventPM10_STD(sensors_event_t *pm10StdEvent) {
653  (void)pm10StdEvent; // Parameter is intentionally unused in this virtual
654  // function.
655  return false;
656  }
657 
658  /**************************** SENSOR_TYPE: PM25_STD
659  * ****************************/
660  /*********************************************************************************/
667  /*********************************************************************************/
668  virtual long getSensorPM25_STDPeriod() { return _PM25SensorPeriod; }
669 
670  /*********************************************************************************/
677  /*********************************************************************************/
679 
680  /*******************************************************************************/
687  /*******************************************************************************/
688  virtual void setSensorPM25_STDPeriodPrv(long period) {
689  _PM25SensorPeriodPrv = period;
690  }
691 
692  /*******************************************************************************/
701  /*******************************************************************************/
702  virtual bool getEventPM25_STD(sensors_event_t *pm25StdEvent) {
703  (void)pm25StdEvent; // Parameter is intentionally unused in this virtual
704  // function.
705  return false;
706  }
707 
708  /**************************** SENSOR_TYPE: PM100_STD
709  * ****************************/
710  /*********************************************************************************/
717  /*********************************************************************************/
718  virtual long getSensorPM100_STDPeriod() { return _PM100SensorPeriod; }
719 
720  /*********************************************************************************/
727  /*********************************************************************************/
729 
730  /*******************************************************************************/
737  /*******************************************************************************/
738  virtual void setSensorPM100_STDPeriodPrv(long period) {
739  _PM100SensorPeriodPrv = period;
740  }
741 
742  /*******************************************************************************/
751  /*******************************************************************************/
752  virtual bool getEventPM100_STD(sensors_event_t *pm100StdEvent) {
753  (void)pm100StdEvent; // Parameter is intentionally unused in this virtual
754  // function.
755  return false;
756  }
757 
758  /**************************** SENSOR_TYPE: UNITLESS_PERCENT
759  * ****************************/
760  /*********************************************************************************/
767  /*********************************************************************************/
769  return _unitlessPercentPeriod;
770  }
771 
772  /*********************************************************************************/
779  /*********************************************************************************/
782  }
783 
784  /*******************************************************************************/
791  /*******************************************************************************/
792  virtual void setSensorUnitlessPercentPeriodPrv(long period) {
793  _unitlessPercentPeriodPrv = period;
794  }
795 
796  /*******************************************************************************/
805  /*******************************************************************************/
806  virtual bool getEventUnitlessPercent(sensors_event_t *unitlessPercentEvent) {
807  (void)unitlessPercentEvent; // Parameter is intentionally unused in this
808  // virtual function.
809  return false;
810  }
811 
812  /**************************** SENSOR_TYPE: VOLTAGE
813  * ****************************/
814  /*********************************************************************************/
820  /*********************************************************************************/
821  virtual long getSensorVoltagePeriod() { return _voltagePeriod; }
822 
823  /*********************************************************************************/
829  /*********************************************************************************/
830  virtual long getSensorVoltagePeriodPrv() { return _voltagePeriodPrv; }
831 
832  /*******************************************************************************/
838  /*******************************************************************************/
839  virtual void setSensorVoltagePeriodPrv(long period) {
840  _voltagePeriodPrv = period;
841  }
842 
843  /*******************************************************************************/
852  /*******************************************************************************/
853  virtual bool getEventVoltage(sensors_event_t *voltageEvent) {
854  (void)voltageEvent; // Parameter is intentionally unused in this virtual
855  // function.
856  return false;
857  }
858 
859  /**************************** SENSOR_TYPE: CURRENT
860  * ****************************/
861  /*********************************************************************************/
867  /*********************************************************************************/
868  virtual long getSensorCurrentPeriod() { return _currentPeriod; }
869 
870  /*********************************************************************************/
876  /*********************************************************************************/
877  virtual long getSensorCurrentPeriodPrv() { return _currentPeriodPrv; }
878 
879  /*******************************************************************************/
885  /*******************************************************************************/
886  virtual void setSensorCurrentPeriodPrv(long period) {
887  _currentPeriodPrv = period;
888  }
889 
890  /*******************************************************************************/
899  /*******************************************************************************/
900  virtual bool getEventCurrent(sensors_event_t *currentEvent) {
901  (void)currentEvent; // Parameter is intentionally unused in this virtual
902  // function.
903  return false;
904  }
905 
906  /****************************** SENSOR_TYPE: Raw
907  * *******************************/
908  /*********************************************************************************/
914  /*********************************************************************************/
915  virtual long getSensorRawPeriod() { return _rawSensorPeriod; }
916 
917  /*********************************************************************************/
923  /*********************************************************************************/
924  virtual long getSensorRawPeriodPrv() { return _rawSensorPeriodPrv; }
925 
926  /*******************************************************************************/
932  /*******************************************************************************/
933  virtual void setSensorRawPeriodPrv(long period) {
934  _rawSensorPeriodPrv = period;
935  }
936 
937  /*******************************************************************************/
945  /*******************************************************************************/
946  virtual bool getEventRaw(sensors_event_t *rawEvent) {
947  (void)
948  rawEvent; // Parameter is intentionally unused in this virtual function.
949  return false;
950  }
951 
952  /****************************** SENSOR_TYPE: Ambient Temp (°F)
953  * *******************************/
954 
955  /*******************************************************************************/
960  /*******************************************************************************/
961  virtual void disableAmbientTempF() { _ambientTempFPeriod = 0.0L; }
962 
963  /*********************************************************************************/
970  /*********************************************************************************/
972 
973  /*********************************************************************************/
980  /*********************************************************************************/
982  return _ambientTempFPeriodPrv;
983  }
984 
985  /*******************************************************************************/
993  /*******************************************************************************/
994  virtual void setSensorAmbientTempFPeriodPrv(long period) {
995  _ambientTempFPeriodPrv = period;
996  }
997 
998  /*******************************************************************************/
1008  /*******************************************************************************/
1009  virtual bool getEventAmbientTempF(sensors_event_t *AmbientTempFEvent) {
1010  // obtain ambient temp. in °C
1011  if (!getEventAmbientTemp(AmbientTempFEvent))
1012  return false;
1013  // convert event from °C to °F
1014  AmbientTempFEvent->temperature =
1015  (AmbientTempFEvent->temperature * 9.0) / 5.0 + 32;
1016  return true;
1017  }
1018 
1019  /****************************** SENSOR_TYPE: Object Temp (°F)
1020  * *******************************/
1021  /*********************************************************************************/
1028  /*********************************************************************************/
1030 
1031  /*********************************************************************************/
1038  /*********************************************************************************/
1040 
1041  /*******************************************************************************/
1049  /*******************************************************************************/
1050  virtual void setSensorObjectTempFPeriodPrv(long period) {
1051  _objectTempFPeriodPrv = period;
1052  }
1053 
1054  /*******************************************************************************/
1064  /*******************************************************************************/
1065  virtual bool getEventObjectTempF(sensors_event_t *objectTempFEvent) {
1066  // obtain ambient temp. in °C
1067  if (!getEventObjectTemp(objectTempFEvent))
1068  return false;
1069  // convert event from °C to °F
1070  objectTempFEvent->temperature =
1071  (objectTempFEvent->temperature * 9.0) / 5.0 + 32.0;
1072  return true;
1073  }
1074 
1075  /****************************** SENSOR_TYPE: Gas Resistance (ohms)
1076  * *******************************/
1077  /*********************************************************************************/
1084  /*********************************************************************************/
1086 
1087  /*********************************************************************************/
1094  /*********************************************************************************/
1096  return _gasResistancePeriodPrv;
1097  }
1098 
1099  /*******************************************************************************/
1107  /*******************************************************************************/
1108  virtual void setSensorGasResistancePeriodPrv(long period) {
1109  _gasResistancePeriodPrv = period;
1110  }
1111 
1112  /*******************************************************************************/
1121  /*******************************************************************************/
1122  virtual bool getEventGasResistance(sensors_event_t *gasEvent) {
1123  (void)
1124  gasEvent; // Parameter is intentionally unused in this virtual function.
1125  return false;
1126  }
1127 
1128  /****************************** SENSOR_TYPE: NOx Index (index)
1129  * *******************************/
1130  /*********************************************************************************/
1137  /*********************************************************************************/
1138  virtual long getSensorNOxIndexPeriod() { return _NOxIndexPeriod; }
1139 
1140  /*********************************************************************************/
1147  /*********************************************************************************/
1149 
1150  /*******************************************************************************/
1158  /*******************************************************************************/
1159  virtual void setSensorNOxIndexPeriodPrv(long period) {
1160  _NOxIndexPeriodPrv = period;
1161  }
1162 
1163  /*******************************************************************************/
1172  /*******************************************************************************/
1173  virtual bool getEventNOxIndex(sensors_event_t *gasEvent) {
1174  (void)
1175  gasEvent; // Parameter is intentionally unused in this virtual function.
1176  return false;
1177  }
1178 
1179  /****************************** SENSOR_TYPE: VOC Index (index)
1180  * *******************************/
1181  /*********************************************************************************/
1188  /*********************************************************************************/
1189  virtual long getSensorVOCIndexPeriod() { return _VOCIndexPeriod; }
1190 
1191  /*********************************************************************************/
1198  /*********************************************************************************/
1200 
1201  /*******************************************************************************/
1209  /*******************************************************************************/
1210  virtual void setSensorVOCIndexPeriodPrv(long period) {
1211  _VOCIndexPeriodPrv = period;
1212  }
1213 
1214  /*******************************************************************************/
1223  /*******************************************************************************/
1224  virtual bool getEventVOCIndex(sensors_event_t *gasEvent) {
1225  (void)
1226  gasEvent; // Parameter is intentionally unused in this virtual function.
1227  return false;
1228  }
1229 
1230  /**************************** SENSOR_TYPE: PROXIMITY
1231  * ****************************/
1232  /*******************************************************************************/
1236  /*******************************************************************************/
1237  virtual void enableSensorProximity(){};
1238 
1239  /*******************************************************************************/
1243  /*******************************************************************************/
1245 
1246  /*********************************************************************************/
1253  /*********************************************************************************/
1255 
1256  /*******************************************************************************/
1263  /*******************************************************************************/
1264  virtual void setSensorProximityPeriod(long period) {
1265  if (period == 0)
1267  _proximitySensorPeriod = period;
1268  }
1269 
1270  /*********************************************************************************/
1277  /*********************************************************************************/
1279 
1280  /*******************************************************************************/
1287  /*******************************************************************************/
1288  virtual void setSensorProximityPeriodPrv(long period) {
1289  _proximitySensorPeriodPrv = period;
1290  }
1291 
1292  /*******************************************************************************/
1301  /*******************************************************************************/
1302  virtual bool getEventProximity(sensors_event_t *proximityEvent) {
1303  (void)proximityEvent; // Parameter is intentionally unused in this virtual
1304  // function.
1305  return false;
1306  }
1307 
1308  /*******************************************************************************/
1315  /*******************************************************************************/
1316  virtual void updateSensorProximity(float period) {
1317  setSensorProximityPeriod(period);
1318  }
1319 
1320 protected:
1321  TwoWire *_i2c;
1322  uint16_t _sensorAddress;
1324  0L;
1327  long _humidSensorPeriod =
1329  0L;
1332  long _pressureSensorPeriod =
1334  0L;
1337  long _CO2SensorPeriod =
1339  0L;
1343  0L;
1347  0L;
1351  0L;
1354  long _objectTempSensorPeriod = 0L;
1359  long _lightSensorPeriod =
1361  0L;
1364  long _PM10SensorPeriod =
1366  0L;
1370  0L;
1374  0L;
1377  long _unitlessPercentPeriod =
1379  0L;
1382  long _voltagePeriod =
1384  0L;
1387  long _currentPeriod =
1389  0L;
1392  long _rawSensorPeriod =
1394  0L;
1398  long _ambientTempFPeriodPrv =
1401  long _objectTempFPeriod = 0L;
1403  long _objectTempFPeriodPrv =
1406  long _gasResistancePeriod = 0L;
1411  long _NOxIndexPeriod =
1413  0L;
1416  long _VOCIndexPeriod =
1418  0L;
1421  long _proximitySensorPeriod =
1423  0L;
1426 };
1428 
1429 #endif // WipperSnapper_I2C_Driver_H
long _unitlessPercentPeriod
The time period between reading the unitless % sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1378
+Go to the documentation of this file.
1 
16 #ifndef WipperSnapper_I2C_Driver_H
17 #define WipperSnapper_I2C_Driver_H
18 
19 #include <Adafruit_Sensor.h>
20 #include <Arduino.h>
21 
22 #define PERIOD_24HRS_AGO_MILLIS (millis() - (24 * 60 * 60 * 1000))
23 
25 /**************************************************************************/
29 /**************************************************************************/
31 
32 public:
33  /*******************************************************************************/
41  /*******************************************************************************/
42  WipperSnapper_I2C_Driver(TwoWire *i2c, uint16_t sensorAddress) {
43  _i2c = i2c;
44  _sensorAddress = sensorAddress;
45  }
46 
47  /*******************************************************************************/
51  /*******************************************************************************/
53 
54  /*******************************************************************************/
59  /*******************************************************************************/
60  bool begin() { return false; }
61 
62  /*******************************************************************************/
70  /*******************************************************************************/
71  void setSensorPeriod(float period,
72  wippersnapper_i2c_v1_SensorType sensorType) {
73  long sensorPeriod = (long)period * 1000;
74 
75  switch (sensorType) {
76  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_AMBIENT_TEMPERATURE:
77  _tempSensorPeriod = sensorPeriod;
78  break;
79  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_RELATIVE_HUMIDITY:
80  _humidSensorPeriod = sensorPeriod;
81  break;
82  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PRESSURE:
83  _pressureSensorPeriod = sensorPeriod;
84  break;
85  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_CO2:
86  _CO2SensorPeriod = sensorPeriod;
87  break;
88  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_ECO2:
89  _ECO2SensorPeriod = sensorPeriod;
90  break;
91  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_TVOC:
92  _TVOCSensorPeriod = sensorPeriod;
93  break;
94  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_ALTITUDE:
95  _altitudeSensorPeriod = sensorPeriod;
96  break;
97  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE:
98  _objectTempSensorPeriod = sensorPeriod;
99  break;
100  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_LIGHT:
101  _lightSensorPeriod = sensorPeriod;
102  break;
103  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PM10_STD:
104  _PM10SensorPeriod = sensorPeriod;
105  break;
106  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PM25_STD:
107  _PM25SensorPeriod = sensorPeriod;
108  break;
109  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PM100_STD:
110  _PM100SensorPeriod = sensorPeriod;
111  break;
112  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_UNITLESS_PERCENT:
113  _unitlessPercentPeriod = sensorPeriod;
114  break;
115  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_VOLTAGE:
116  _voltagePeriod = sensorPeriod;
117  break;
118  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_CURRENT:
119  _currentPeriod = sensorPeriod;
120  break;
121  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_PROXIMITY:
122  _proximitySensorPeriod = sensorPeriod;
123  break;
124  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_RAW:
125  _rawSensorPeriod = sensorPeriod;
126  break;
127  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_AMBIENT_TEMPERATURE_FAHRENHEIT:
128  _ambientTempFPeriod = sensorPeriod;
129  break;
130  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT:
131  _objectTempFPeriod = sensorPeriod;
132  break;
133  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_GAS_RESISTANCE:
134  _gasResistancePeriod = sensorPeriod;
135  break;
136  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_NOX_INDEX:
137  _NOxIndexPeriod = sensorPeriod;
138  break;
139  case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_VOC_INDEX:
140  _VOCIndexPeriod = sensorPeriod;
141  break;
142  default:
143  break;
144  }
145  }
146 
147  /*******************************************************************************/
154  /*******************************************************************************/
155  void
156  configureDriver(wippersnapper_i2c_v1_I2CDeviceInitRequest *msgDeviceInitReq) {
157  int propertyIdx = 0; // contains the amount of i2c sensors in the
158  // msgDeviceInitReq to configure
159  while (propertyIdx < msgDeviceInitReq->i2c_device_properties_count) {
161  msgDeviceInitReq->i2c_device_properties[propertyIdx].sensor_period,
162  msgDeviceInitReq->i2c_device_properties[propertyIdx].sensor_type);
163  ++propertyIdx;
164  }
165  }
166 
167  /*******************************************************************************/
172  /*******************************************************************************/
173  uint16_t getI2CAddress() { return _sensorAddress; }
174 
175  /****************************** SENSOR_TYPE: CO2
176  * *******************************/
177  /*********************************************************************************/
183  /*********************************************************************************/
184  virtual long getSensorCO2Period() { return _CO2SensorPeriod; }
185 
186  /*********************************************************************************/
192  /*********************************************************************************/
193  virtual long getSensorCO2PeriodPrv() { return _CO2SensorPeriodPrv; }
194 
195  /*******************************************************************************/
201  /*******************************************************************************/
202  virtual void setSensorCO2PeriodPrv(long period) {
203  _CO2SensorPeriodPrv = period;
204  }
205 
206  /*******************************************************************************/
214  /*******************************************************************************/
215  virtual bool getEventCO2(sensors_event_t *co2Event) {
216  (void)
217  co2Event; // Parameter is intentionally unused in this virtual function.
218  return false;
219  }
220 
221  /****************************** SENSOR_TYPE: ECO2
222  * *******************************/
223  /*********************************************************************************/
229  /*********************************************************************************/
230  virtual long getSensorECO2Period() { return _ECO2SensorPeriod; }
231 
232  /*********************************************************************************/
238  /*********************************************************************************/
239  virtual long getSensorECO2PeriodPrv() { return _ECO2SensorPeriodPrv; }
240 
241  /*******************************************************************************/
247  /*******************************************************************************/
248  virtual void setSensorECO2PeriodPrv(long period) {
249  _ECO2SensorPeriodPrv = period;
250  }
251 
252  /*******************************************************************************/
260  /*******************************************************************************/
261  virtual bool getEventECO2(sensors_event_t *eco2Event) {
262  (void)eco2Event; // Parameter is intentionally unused in this virtual
263  // function.
264  return false;
265  }
266 
267  /****************************** SENSOR_TYPE: TVOC
268  * *******************************/
269  /*********************************************************************************/
275  /*********************************************************************************/
276  virtual long getSensorTVOCPeriod() { return _TVOCSensorPeriod; }
277 
278  /*********************************************************************************/
284  /*********************************************************************************/
285  virtual long getSensorTVOCPeriodPrv() { return _TVOCSensorPeriodPrv; }
286 
287  /*******************************************************************************/
293  /*******************************************************************************/
294  virtual void setSensorTVOCPeriodPrv(long period) {
295  _TVOCSensorPeriodPrv = period;
296  }
297 
298  /*******************************************************************************/
306  /*******************************************************************************/
307  virtual bool getEventTVOC(sensors_event_t *tvocEvent) {
308  (void)tvocEvent; // Parameter is intentionally unused in this virtual
309  // function.
310  return false;
311  }
312 
313  /********************** SENSOR_TYPE: AMBIENT TEMPERATURE (°C)
314  * ***********************/
315  /*********************************************************************************/
321  /*********************************************************************************/
323 
324  /*********************************************************************************/
331  /*********************************************************************************/
333 
334  /*******************************************************************************/
342  /*******************************************************************************/
343  virtual void setSensorAmbientTempPeriodPrv(long periodPrv) {
344  _tempSensorPeriodPrv = periodPrv;
345  }
346 
347  /*******************************************************************************/
356  /*******************************************************************************/
357  virtual bool getEventAmbientTemp(sensors_event_t *tempEvent) {
358  (void)tempEvent; // Parameter is intentionally unused in this virtual
359  // function.
360  return false;
361  }
362 
363  /************************* SENSOR_TYPE: RELATIVE_HUMIDITY
364  * ***********************/
365  /*********************************************************************************/
371  /*********************************************************************************/
373 
374  /*********************************************************************************/
380  /*********************************************************************************/
382  return _humidSensorPeriodPrv;
383  }
384 
385  /*******************************************************************************/
391  /*******************************************************************************/
392  virtual void setSensorRelativeHumidityPeriodPrv(long periodPrv) {
393  _humidSensorPeriodPrv = periodPrv;
394  }
395 
396  /*******************************************************************************/
405  /*******************************************************************************/
406  virtual bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
407  (void)humidEvent; // Parameter is intentionally unused in this virtual
408  // function.
409  return false;
410  }
411 
412  /**************************** SENSOR_TYPE: PRESSURE
413  * ****************************/
414  /*********************************************************************************/
420  /*********************************************************************************/
422 
423  /*********************************************************************************/
429  /*********************************************************************************/
431 
432  /*******************************************************************************/
438  /*******************************************************************************/
439  virtual void setSensorPressurePeriodPrv(long period) {
440  _pressureSensorPeriodPrv = period;
441  }
442 
443  /*******************************************************************************/
452  /*******************************************************************************/
453  virtual bool getEventPressure(sensors_event_t *pressureEvent) {
454  (void)pressureEvent; // Parameter is intentionally unused in this virtual
455  // function.
456  return false;
457  }
458 
459  /**************************** SENSOR_TYPE: Altitude
460  * ****************************/
461  /*********************************************************************************/
467  /*********************************************************************************/
469 
470  /*********************************************************************************/
476  /*********************************************************************************/
478 
479  /*******************************************************************************/
485  /*******************************************************************************/
486  virtual void setSensorAltitudePeriodPrv(long period) {
487  _altitudeSensorPeriodPrv = period;
488  }
489 
490  /*******************************************************************************/
499  /*******************************************************************************/
500  virtual bool getEventAltitude(sensors_event_t *altitudeEvent) {
501  (void)altitudeEvent; // Parameter is intentionally unused in this virtual
502  // function.
503  return false;
504  }
505 
506  /**************************** SENSOR_TYPE: Object_Temperature
507  * ****************************/
508  /*********************************************************************************/
515  /*********************************************************************************/
517 
518  /*********************************************************************************/
525  /*********************************************************************************/
528  }
529 
530  /*******************************************************************************/
537  /*******************************************************************************/
538  virtual void setSensorObjectTempPeriodPrv(long period) {
540  }
541 
542  /*******************************************************************************/
551  /*******************************************************************************/
552  virtual bool getEventObjectTemp(sensors_event_t *objectTempEvent) {
553  (void)objectTempEvent; // Parameter is intentionally unused in this virtual
554  // function.
555  return false;
556  }
557 
558  /**************************** SENSOR_TYPE: LIGHT
559  * ****************************/
560  /*********************************************************************************/
567  /*********************************************************************************/
568  virtual long getSensorLightPeriod() { return _lightSensorPeriod; }
569 
570  /*********************************************************************************/
577  /*********************************************************************************/
579 
580  /*******************************************************************************/
587  /*******************************************************************************/
588  virtual void setSensorLightPeriodPrv(long period) {
589  _lightSensorPeriodPrv = period;
590  }
591 
592  /*******************************************************************************/
601  /*******************************************************************************/
602  virtual bool getEventLight(sensors_event_t *lightEvent) {
603  (void)lightEvent; // Parameter is intentionally unused in this virtual
604  // function.
605  return false;
606  }
607 
608  /**************************** SENSOR_TYPE: PM10_STD
609  * ****************************/
610  /*********************************************************************************/
617  /*********************************************************************************/
618  virtual long getSensorPM10_STDPeriod() { return _PM10SensorPeriod; }
619 
620  /*********************************************************************************/
627  /*********************************************************************************/
629 
630  /*******************************************************************************/
637  /*******************************************************************************/
638  virtual void setSensorPM10_STDPeriodPrv(long period) {
639  _PM10SensorPeriodPrv = period;
640  }
641 
642  /*******************************************************************************/
651  /*******************************************************************************/
652  virtual bool getEventPM10_STD(sensors_event_t *pm10StdEvent) {
653  (void)pm10StdEvent; // Parameter is intentionally unused in this virtual
654  // function.
655  return false;
656  }
657 
658  /**************************** SENSOR_TYPE: PM25_STD
659  * ****************************/
660  /*********************************************************************************/
667  /*********************************************************************************/
668  virtual long getSensorPM25_STDPeriod() { return _PM25SensorPeriod; }
669 
670  /*********************************************************************************/
677  /*********************************************************************************/
679 
680  /*******************************************************************************/
687  /*******************************************************************************/
688  virtual void setSensorPM25_STDPeriodPrv(long period) {
689  _PM25SensorPeriodPrv = period;
690  }
691 
692  /*******************************************************************************/
701  /*******************************************************************************/
702  virtual bool getEventPM25_STD(sensors_event_t *pm25StdEvent) {
703  (void)pm25StdEvent; // Parameter is intentionally unused in this virtual
704  // function.
705  return false;
706  }
707 
708  /**************************** SENSOR_TYPE: PM100_STD
709  * ****************************/
710  /*********************************************************************************/
717  /*********************************************************************************/
718  virtual long getSensorPM100_STDPeriod() { return _PM100SensorPeriod; }
719 
720  /*********************************************************************************/
727  /*********************************************************************************/
729 
730  /*******************************************************************************/
737  /*******************************************************************************/
738  virtual void setSensorPM100_STDPeriodPrv(long period) {
739  _PM100SensorPeriodPrv = period;
740  }
741 
742  /*******************************************************************************/
751  /*******************************************************************************/
752  virtual bool getEventPM100_STD(sensors_event_t *pm100StdEvent) {
753  (void)pm100StdEvent; // Parameter is intentionally unused in this virtual
754  // function.
755  return false;
756  }
757 
758  /**************************** SENSOR_TYPE: UNITLESS_PERCENT
759  * ****************************/
760  /*********************************************************************************/
767  /*********************************************************************************/
769  return _unitlessPercentPeriod;
770  }
771 
772  /*********************************************************************************/
779  /*********************************************************************************/
782  }
783 
784  /*******************************************************************************/
791  /*******************************************************************************/
792  virtual void setSensorUnitlessPercentPeriodPrv(long period) {
793  _unitlessPercentPeriodPrv = period;
794  }
795 
796  /*******************************************************************************/
805  /*******************************************************************************/
806  virtual bool getEventUnitlessPercent(sensors_event_t *unitlessPercentEvent) {
807  (void)unitlessPercentEvent; // Parameter is intentionally unused in this
808  // virtual function.
809  return false;
810  }
811 
812  /**************************** SENSOR_TYPE: VOLTAGE
813  * ****************************/
814  /*********************************************************************************/
820  /*********************************************************************************/
821  virtual long getSensorVoltagePeriod() { return _voltagePeriod; }
822 
823  /*********************************************************************************/
829  /*********************************************************************************/
830  virtual long getSensorVoltagePeriodPrv() { return _voltagePeriodPrv; }
831 
832  /*******************************************************************************/
838  /*******************************************************************************/
839  virtual void setSensorVoltagePeriodPrv(long period) {
840  _voltagePeriodPrv = period;
841  }
842 
843  /*******************************************************************************/
852  /*******************************************************************************/
853  virtual bool getEventVoltage(sensors_event_t *voltageEvent) {
854  (void)voltageEvent; // Parameter is intentionally unused in this virtual
855  // function.
856  return false;
857  }
858 
859  /**************************** SENSOR_TYPE: CURRENT
860  * ****************************/
861  /*********************************************************************************/
867  /*********************************************************************************/
868  virtual long getSensorCurrentPeriod() { return _currentPeriod; }
869 
870  /*********************************************************************************/
876  /*********************************************************************************/
877  virtual long getSensorCurrentPeriodPrv() { return _currentPeriodPrv; }
878 
879  /*******************************************************************************/
885  /*******************************************************************************/
886  virtual void setSensorCurrentPeriodPrv(long period) {
887  _currentPeriodPrv = period;
888  }
889 
890  /*******************************************************************************/
899  /*******************************************************************************/
900  virtual bool getEventCurrent(sensors_event_t *currentEvent) {
901  (void)currentEvent; // Parameter is intentionally unused in this virtual
902  // function.
903  return false;
904  }
905 
906  /****************************** SENSOR_TYPE: Raw
907  * *******************************/
908  /*********************************************************************************/
914  /*********************************************************************************/
915  virtual long getSensorRawPeriod() { return _rawSensorPeriod; }
916 
917  /*********************************************************************************/
923  /*********************************************************************************/
924  virtual long getSensorRawPeriodPrv() { return _rawSensorPeriodPrv; }
925 
926  /*******************************************************************************/
932  /*******************************************************************************/
933  virtual void setSensorRawPeriodPrv(long period) {
934  _rawSensorPeriodPrv = period;
935  }
936 
937  /*******************************************************************************/
945  /*******************************************************************************/
946  virtual bool getEventRaw(sensors_event_t *rawEvent) {
947  (void)
948  rawEvent; // Parameter is intentionally unused in this virtual function.
949  return false;
950  }
951 
952  /****************************** SENSOR_TYPE: Ambient Temp (°F)
953  * *******************************/
954 
955  /*******************************************************************************/
960  /*******************************************************************************/
961  virtual void disableAmbientTempF() { _ambientTempFPeriod = 0.0L; }
962 
963  /*********************************************************************************/
970  /*********************************************************************************/
972 
973  /*********************************************************************************/
980  /*********************************************************************************/
982  return _ambientTempFPeriodPrv;
983  }
984 
985  /*******************************************************************************/
993  /*******************************************************************************/
994  virtual void setSensorAmbientTempFPeriodPrv(long period) {
995  _ambientTempFPeriodPrv = period;
996  }
997 
998  /*******************************************************************************/
1008  /*******************************************************************************/
1009  virtual bool getEventAmbientTempF(sensors_event_t *AmbientTempFEvent) {
1010  // obtain ambient temp. in °C
1011  if (!getEventAmbientTemp(AmbientTempFEvent))
1012  return false;
1013  // convert event from °C to °F
1014  AmbientTempFEvent->temperature =
1015  (AmbientTempFEvent->temperature * 9.0) / 5.0 + 32;
1016  return true;
1017  }
1018 
1019  /****************************** SENSOR_TYPE: Object Temp (°F)
1020  * *******************************/
1021  /*********************************************************************************/
1028  /*********************************************************************************/
1030 
1031  /*********************************************************************************/
1038  /*********************************************************************************/
1040 
1041  /*******************************************************************************/
1049  /*******************************************************************************/
1050  virtual void setSensorObjectTempFPeriodPrv(long period) {
1051  _objectTempFPeriodPrv = period;
1052  }
1053 
1054  /*******************************************************************************/
1064  /*******************************************************************************/
1065  virtual bool getEventObjectTempF(sensors_event_t *objectTempFEvent) {
1066  // obtain ambient temp. in °C
1067  if (!getEventObjectTemp(objectTempFEvent))
1068  return false;
1069  // convert event from °C to °F
1070  objectTempFEvent->temperature =
1071  (objectTempFEvent->temperature * 9.0) / 5.0 + 32.0;
1072  return true;
1073  }
1074 
1075  /****************************** SENSOR_TYPE: Gas Resistance (ohms)
1076  * *******************************/
1077  /*********************************************************************************/
1084  /*********************************************************************************/
1086 
1087  /*********************************************************************************/
1094  /*********************************************************************************/
1096  return _gasResistancePeriodPrv;
1097  }
1098 
1099  /*******************************************************************************/
1107  /*******************************************************************************/
1108  virtual void setSensorGasResistancePeriodPrv(long period) {
1109  _gasResistancePeriodPrv = period;
1110  }
1111 
1112  /*******************************************************************************/
1121  /*******************************************************************************/
1122  virtual bool getEventGasResistance(sensors_event_t *gasEvent) {
1123  (void)
1124  gasEvent; // Parameter is intentionally unused in this virtual function.
1125  return false;
1126  }
1127 
1128  /****************************** SENSOR_TYPE: NOx Index (index)
1129  * *******************************/
1130  /*********************************************************************************/
1137  /*********************************************************************************/
1138  virtual long getSensorNOxIndexPeriod() { return _NOxIndexPeriod; }
1139 
1140  /*********************************************************************************/
1147  /*********************************************************************************/
1149 
1150  /*******************************************************************************/
1158  /*******************************************************************************/
1159  virtual void setSensorNOxIndexPeriodPrv(long period) {
1160  _NOxIndexPeriodPrv = period;
1161  }
1162 
1163  /*******************************************************************************/
1172  /*******************************************************************************/
1173  virtual bool getEventNOxIndex(sensors_event_t *gasEvent) {
1174  (void)
1175  gasEvent; // Parameter is intentionally unused in this virtual function.
1176  return false;
1177  }
1178 
1179  /****************************** SENSOR_TYPE: VOC Index (index)
1180  * *******************************/
1181  /*********************************************************************************/
1188  /*********************************************************************************/
1189  virtual long getSensorVOCIndexPeriod() { return _VOCIndexPeriod; }
1190 
1191  /*********************************************************************************/
1198  /*********************************************************************************/
1200 
1201  /*******************************************************************************/
1209  /*******************************************************************************/
1210  virtual void setSensorVOCIndexPeriodPrv(long period) {
1211  _VOCIndexPeriodPrv = period;
1212  }
1213 
1214  /*******************************************************************************/
1223  /*******************************************************************************/
1224  virtual bool getEventVOCIndex(sensors_event_t *gasEvent) {
1225  (void)
1226  gasEvent; // Parameter is intentionally unused in this virtual function.
1227  return false;
1228  }
1229 
1230  /**************************** SENSOR_TYPE: PROXIMITY
1231  * ****************************/
1232  /*******************************************************************************/
1236  /*******************************************************************************/
1237  virtual void enableSensorProximity() {};
1238 
1239  /*******************************************************************************/
1243  /*******************************************************************************/
1245 
1246  /*********************************************************************************/
1253  /*********************************************************************************/
1255 
1256  /*******************************************************************************/
1263  /*******************************************************************************/
1264  virtual void setSensorProximityPeriod(long period) {
1265  if (period == 0)
1267  _proximitySensorPeriod = period;
1268  }
1269 
1270  /*********************************************************************************/
1277  /*********************************************************************************/
1279 
1280  /*******************************************************************************/
1287  /*******************************************************************************/
1288  virtual void setSensorProximityPeriodPrv(long period) {
1289  _proximitySensorPeriodPrv = period;
1290  }
1291 
1292  /*******************************************************************************/
1301  /*******************************************************************************/
1302  virtual bool getEventProximity(sensors_event_t *proximityEvent) {
1303  (void)proximityEvent; // Parameter is intentionally unused in this virtual
1304  // function.
1305  return false;
1306  }
1307 
1308  /*******************************************************************************/
1315  /*******************************************************************************/
1316  virtual void updateSensorProximity(float period) {
1317  setSensorProximityPeriod(period);
1318  }
1319 
1320 protected:
1321  TwoWire *_i2c;
1322  uint16_t _sensorAddress;
1324  0L;
1327  long _humidSensorPeriod =
1329  0L;
1332  long _pressureSensorPeriod =
1334  0L;
1337  long _CO2SensorPeriod =
1339  0L;
1343  0L;
1347  0L;
1351  0L;
1354  long _objectTempSensorPeriod = 0L;
1359  long _lightSensorPeriod =
1361  0L;
1364  long _PM10SensorPeriod =
1366  0L;
1370  0L;
1374  0L;
1377  long _unitlessPercentPeriod =
1379  0L;
1382  long _voltagePeriod =
1384  0L;
1387  long _currentPeriod =
1389  0L;
1392  long _rawSensorPeriod =
1394  0L;
1398  long _ambientTempFPeriodPrv =
1401  long _objectTempFPeriod = 0L;
1403  long _objectTempFPeriodPrv =
1406  long _gasResistancePeriod = 0L;
1411  long _NOxIndexPeriod =
1413  0L;
1416  long _VOCIndexPeriod =
1418  0L;
1421  long _proximitySensorPeriod =
1423  0L;
1426 };
1428 
1429 #endif // WipperSnapper_I2C_Driver_H
long _unitlessPercentPeriod
The time period between reading the unitless % sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1378
virtual long getSensorUnitlessPercentPeriodPrv()
Base implementation - Returns the previous time interval at which the unitless % sensor was queried l...
Definition: WipperSnapper_I2C_Driver.h:780
virtual long getSensorLightPeriodPrv()
Base implementation - Returns the previous time interval at which the light sensor was queried last...
Definition: WipperSnapper_I2C_Driver.h:578
virtual long getSensorObjectTempPeriodPrv()
Base implementation - Returns the previous time interval at which the object temperature sensor was q...
Definition: WipperSnapper_I2C_Driver.h:526
diff --git a/html/_wipper_snapper___i2_c___driver___b_m_e680_8h_source.html b/html/_wipper_snapper___i2_c___driver___b_m_e680_8h_source.html index 08645dcd4..4f5d1a46a 100644 --- a/html/_wipper_snapper___i2_c___driver___b_m_e680_8h_source.html +++ b/html/_wipper_snapper___i2_c___driver___b_m_e680_8h_source.html @@ -66,7 +66,7 @@
WipperSnapper_I2C_Driver_BME680.h
-Go to the documentation of this file.
1 
16 #ifndef WipperSnapper_I2C_Driver_BME680_H
17 #define WipperSnapper_I2C_Driver_BME680_H
18 
20 #include <Adafruit_BME680.h>
21 
22 #define SEALEVELPRESSURE_HPA (1013.25)
23 
24 /**************************************************************************/
29 /**************************************************************************/
31 
32 public:
33  /*******************************************************************************/
41  /*******************************************************************************/
42  WipperSnapper_I2C_Driver_BME680(TwoWire *i2c, uint16_t sensorAddress)
43  : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
44  _i2c = i2c;
45  _sensorAddress = sensorAddress;
46  }
47 
48  /*******************************************************************************/
52  /*******************************************************************************/
54 
55  /*******************************************************************************/
60  /*******************************************************************************/
61  bool begin() {
62  _bme = new Adafruit_BME680(_i2c);
63 
64  // attempt to initialize BME680
65  if (!_bme->begin(_sensorAddress))
66  return false;
67 
68  // Set up oversampling and filter initialization
69  // defaults from
70  // https://github.com/adafruit/Adafruit_BME680/blob/master/examples/bme680test/bme680test.ino
71  _bme->setTemperatureOversampling(BME680_OS_8X);
72  _bme->setHumidityOversampling(BME680_OS_2X);
73  _bme->setPressureOversampling(BME680_OS_4X);
74  _bme->setIIRFilterSize(BME680_FILTER_SIZE_3);
75  _bme->setGasHeater(320, 150); // 320*C for 150 ms
76 
77  return true;
78  }
79 
80  /*******************************************************************************/
85  /*******************************************************************************/
86  bool bmePerformReading() { return _bme->performReading(); }
87 
88  /*******************************************************************************/
96  /*******************************************************************************/
97  bool getEventAmbientTemp(sensors_event_t *tempEvent) {
98  if (!bmePerformReading())
99  return false;
100  tempEvent->temperature = _bme->temperature;
101  return true;
102  }
103 
104  /*******************************************************************************/
112  /*******************************************************************************/
113  bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
114  if (!bmePerformReading())
115  return false;
116  humidEvent->relative_humidity = _bme->humidity;
117  return true;
118  }
119 
120  /*******************************************************************************/
129  /*******************************************************************************/
130  bool getEventPressure(sensors_event_t *pressureEvent) {
131  if (!bmePerformReading())
132  return false;
133  pressureEvent->pressure = (float)_bme->pressure;
134  return true;
135  }
136 
137  /*******************************************************************************/
145  /*******************************************************************************/
146  bool getEventAltitude(sensors_event_t *altitudeEvent) {
147  if (!bmePerformReading())
148  return false;
149  altitudeEvent->altitude = (float)_bme->readAltitude(SEALEVELPRESSURE_HPA);
150  return true;
151  }
152 
153  /*******************************************************************************/
162  /*******************************************************************************/
163  virtual bool getEventGasResistance(sensors_event_t *gasEvent) {
164  if (!bmePerformReading())
165  return false;
166 
167  gasEvent->gas_resistance = (float)_bme->gas_resistance;
168  return true;
169  }
170 
171 protected:
172  Adafruit_BME680 *_bme;
173 };
174 
175 #endif // WipperSnapper_I2C_Driver_BME680
bool getEventAmbientTemp(sensors_event_t *tempEvent)
Gets the BME680&#39;s current temperature.
Definition: WipperSnapper_I2C_Driver_BME680.h:97
+Go to the documentation of this file.
1 
16 #ifndef WipperSnapper_I2C_Driver_BME680_H
17 #define WipperSnapper_I2C_Driver_BME680_H
18 
20 #include <Adafruit_BME680.h>
21 
22 #define SEALEVELPRESSURE_HPA (1013.25)
23 
24 /**************************************************************************/
29 /**************************************************************************/
31 
32 public:
33  /*******************************************************************************/
41  /*******************************************************************************/
42  WipperSnapper_I2C_Driver_BME680(TwoWire *i2c, uint16_t sensorAddress)
43  : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
44  _i2c = i2c;
45  _sensorAddress = sensorAddress;
46  }
47 
48  /*******************************************************************************/
52  /*******************************************************************************/
54 
55  /*******************************************************************************/
60  /*******************************************************************************/
61  bool begin() {
62  _bme = new Adafruit_BME680(_i2c);
63 
64  // attempt to initialize BME680
65  if (!_bme->begin(_sensorAddress))
66  return false;
67 
68  // Set up oversampling and filter initialization
69  // defaults from
70  // https://github.com/adafruit/Adafruit_BME680/blob/master/examples/bme680test/bme680test.ino
71  _bme->setTemperatureOversampling(BME680_OS_8X);
72  _bme->setHumidityOversampling(BME680_OS_2X);
73  _bme->setPressureOversampling(BME680_OS_4X);
74  _bme->setIIRFilterSize(BME680_FILTER_SIZE_3);
75  _bme->setGasHeater(320, 150); // 320*C for 150 ms
76 
77  return true;
78  }
79 
80  /*******************************************************************************/
85  /*******************************************************************************/
86  bool bmePerformReading() { return _bme->performReading(); }
87 
88  /*******************************************************************************/
96  /*******************************************************************************/
97  bool getEventAmbientTemp(sensors_event_t *tempEvent) {
98  if (!bmePerformReading())
99  return false;
100  tempEvent->temperature = _bme->temperature;
101  return true;
102  }
103 
104  /*******************************************************************************/
112  /*******************************************************************************/
113  bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
114  if (!bmePerformReading())
115  return false;
116  humidEvent->relative_humidity = _bme->humidity;
117  return true;
118  }
119 
120  /*******************************************************************************/
129  /*******************************************************************************/
130  bool getEventPressure(sensors_event_t *pressureEvent) {
131  if (!bmePerformReading())
132  return false;
133  pressureEvent->pressure = (float)_bme->pressure / 100.0;
134  return true;
135  }
136 
137  /*******************************************************************************/
145  /*******************************************************************************/
146  bool getEventAltitude(sensors_event_t *altitudeEvent) {
147  if (!bmePerformReading())
148  return false;
149  altitudeEvent->altitude = (float)_bme->readAltitude(SEALEVELPRESSURE_HPA);
150  return true;
151  }
152 
153  /*******************************************************************************/
162  /*******************************************************************************/
163  virtual bool getEventGasResistance(sensors_event_t *gasEvent) {
164  if (!bmePerformReading())
165  return false;
166 
167  gasEvent->gas_resistance = (float)_bme->gas_resistance;
168  return true;
169  }
170 
171 protected:
172  Adafruit_BME680 *_bme;
173 };
174 
175 #endif // WipperSnapper_I2C_Driver_BME680
bool getEventAmbientTemp(sensors_event_t *tempEvent)
Gets the BME680&#39;s current temperature.
Definition: WipperSnapper_I2C_Driver_BME680.h:97
WipperSnapper_I2C_Driver_BME680(TwoWire *i2c, uint16_t sensorAddress)
Constructor for an BME680 sensor.
Definition: WipperSnapper_I2C_Driver_BME680.h:42
bool getEventRelativeHumidity(sensors_event_t *humidEvent)
Gets the BME680&#39;s current relative humidity reading.
Definition: WipperSnapper_I2C_Driver_BME680.h:113
#define SEALEVELPRESSURE_HPA
Default sea level pressure, in hPa.
Definition: WipperSnapper_I2C_Driver_BME680.h:22
diff --git a/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h.html b/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h.html index e6cff6ab3..cf286b586 100644 --- a/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h.html +++ b/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h.html @@ -81,9 +81,9 @@  

Detailed Description

-

Device driver for the SEN5X CO2, Temperature, and Humidity sensor. TEMPORARY HACK

+

Device driver for the SEN5X air quality sensors.

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

-

Copyright (c) Marni Brewster 2022 for Adafruit Industries.

+

Copyright (c) Tyeth Gundry 2022 for Adafruit Industries.

MIT license, all text here must be included in any redistribution.

diff --git a/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h_source.html b/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h_source.html index d61f62f72..b54c812a6 100644 --- a/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h_source.html +++ b/html/_wipper_snapper___i2_c___driver___s_e_n5_x_8h_source.html @@ -66,26 +66,26 @@
WipperSnapper_I2C_Driver_SEN5X.h
-Go to the documentation of this file.
1 
17 #ifndef WipperSnapper_I2C_Driver_SEN5X_H
18 #define WipperSnapper_I2C_Driver_SEN5X_H
19 
21 #include <SensirionI2CSen5x.h>
22 #include <Wire.h>
23 
24 /**************************************************************************/
28 /**************************************************************************/
30 
31  const float OVERFLOW_SEN55 = (0xFFFF / 10); // maxes out at u_int16 / 10
32 
33 public:
34  /*******************************************************************************/
42  /*******************************************************************************/
43  WipperSnapper_I2C_Driver_SEN5X(TwoWire *i2c, uint16_t sensorAddress)
44  : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
45  _i2c = i2c;
46  _sensorAddress = sensorAddress;
47  }
48 
49  /*******************************************************************************/
54  /*******************************************************************************/
55  bool begin() {
56  _sen = new SensirionI2CSen5x();
57  _sen->begin(*_i2c);
58  u_int16_t error_stop = _sen->deviceReset();
59  if (error_stop != 0) {
60  return false;
61  }
62  // Wait 1 second for sensors to start recording + 100ms for reset command
63  delay(1100);
64  u_int16_t error_start = _sen->startMeasurement();
65  if (error_start != 0) {
66  return false;
67  }
68 
69  return true;
70  }
71 
72  /*******************************************************************************/
80  /*******************************************************************************/
81  bool getEventAmbientTemp(sensors_event_t *tempEvent) {
82  float massConcentrationPm1p0, massConcentrationPm2p5,
83  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
84  ambientTemperature, vocIndex, noxIndex;
85  uint16_t error;
86 
87  error = _sen->readMeasuredValues(
88  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
89  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
90  noxIndex);
91  if ((_tempSensorPeriod != 0 && error != 0) || ambientTemperature == NAN) {
92  return false;
93  }
94 
95  tempEvent->temperature = ambientTemperature;
96  return true;
97  }
98 
99  /*******************************************************************************/
107  /*******************************************************************************/
108  bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
109  float massConcentrationPm1p0, massConcentrationPm2p5,
110  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
111  ambientTemperature, vocIndex, noxIndex;
112  uint16_t error;
113 
114  error = _sen->readMeasuredValues(
115  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
116  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
117  noxIndex);
118  if ((_humidSensorPeriod != 0 && error != 0) || ambientHumidity == NAN) {
119  return false;
120  }
121 
122  humidEvent->relative_humidity = ambientHumidity;
123  return true;
124  }
125 
126  /*******************************************************************************/
137  /*******************************************************************************/
138  bool getEventNOxIndex(sensors_event_t *noxIndexEvent) {
139  float massConcentrationPm1p0, massConcentrationPm2p5,
140  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
141  ambientTemperature, vocIndex, noxIndex;
142  uint16_t error;
143 
144  error = _sen->readMeasuredValues(
145  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
146  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
147  noxIndex);
148  if ((_NOxIndexPeriod != 0 && error != 0) || noxIndex == NAN) {
149  return false;
150  }
151 
152  noxIndexEvent->nox_index = noxIndex;
153  return true;
154  }
155 
156  /*******************************************************************************/
164  /*******************************************************************************/
165  bool getEventVOCIndex(sensors_event_t *vocIndexEvent) {
166  float massConcentrationPm1p0, massConcentrationPm2p5,
167  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
168  ambientTemperature, vocIndex, noxIndex;
169  uint16_t error;
170 
171  error = _sen->readMeasuredValues(
172  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
173  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
174  noxIndex);
175  if ((_VOCIndexPeriod != 0 && error != 0) || vocIndex == NAN) {
176  return false;
177  }
178 
179  vocIndexEvent->voc_index = vocIndex;
180  return true;
181  }
182 
183  /*******************************************************************************/
191  /*******************************************************************************/
192  bool getEventPM10_STD(sensors_event_t *pm10StdEvent) {
193  float massConcentrationPm1p0, massConcentrationPm2p5,
194  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
195  ambientTemperature, vocIndex, noxIndex;
196  uint16_t error;
197 
198  error = _sen->readMeasuredValues(
199  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
200  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
201  noxIndex);
202  if ((_PM10SensorPeriod != 0 && error != 0) ||
203  massConcentrationPm1p0 == NAN ||
204  massConcentrationPm1p0 == OVERFLOW_SEN55) {
205  return false;
206  }
207 
208  pm10StdEvent->pm10_std = massConcentrationPm1p0;
209  return true;
210  }
211 
212  /*******************************************************************************/
220  /*******************************************************************************/
221  bool getEventPM25_STD(sensors_event_t *pm25StdEvent) {
222  float massConcentrationPm1p0, massConcentrationPm2p5,
223  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
224  ambientTemperature, vocIndex, noxIndex;
225  uint16_t error;
226 
227  error = _sen->readMeasuredValues(
228  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
229  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
230  noxIndex);
231  if ((_PM25SensorPeriod != 0 && error != 0) ||
232  massConcentrationPm2p5 == NAN ||
233  massConcentrationPm2p5 == OVERFLOW_SEN55) {
234  return false;
235  }
236 
237  pm25StdEvent->pm25_std = massConcentrationPm2p5;
238  return true;
239  }
240 
241  /*******************************************************************************/
249  /*******************************************************************************/
250  bool getEventPM40_STD(sensors_event_t *pm40StdEvent) {
251  float massConcentrationPm1p0, massConcentrationPm2p5,
252  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
253  ambientTemperature, vocIndex, noxIndex;
254  uint16_t error;
255 
256  error = _sen->readMeasuredValues(
257  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
258  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
259  noxIndex);
260  if ((_PM25SensorPeriod != 0 && error != 0) ||
261  massConcentrationPm4p0 == NAN ||
262  massConcentrationPm4p0 == OVERFLOW_SEN55) {
263  return false;
264  }
265 
266  pm40StdEvent->data[0] = massConcentrationPm4p0;
267  return true;
268  }
269 
270  /*******************************************************************************/
278  /*******************************************************************************/
279  bool getEventPM100_STD(sensors_event_t *pm100StdEvent) {
280  float massConcentrationPm1p0, massConcentrationPm2p5,
281  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
282  ambientTemperature, vocIndex, noxIndex;
283  uint16_t error;
284 
285  error = _sen->readMeasuredValues(
286  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
287  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
288  noxIndex);
289  if ((_PM100SensorPeriod != 0 && error != 0) ||
290  massConcentrationPm10p0 == NAN ||
291  massConcentrationPm10p0 == OVERFLOW_SEN55) {
292  return false;
293  }
294 
295  pm100StdEvent->pm100_std = massConcentrationPm10p0;
296  return true;
297  }
298 
299 protected:
300  SensirionI2CSen5x *_sen;
301 };
302 
303 #endif // WipperSnapper_I2C_Driver_SEN5X
SensirionI2CSen5x * _sen
SEN5X driver object.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:300
-
bool getEventVOCIndex(sensors_event_t *vocIndexEvent)
Gets the SEN5X&#39;s current VOC reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:165
+Go to the documentation of this file.
1 
16 #ifndef WipperSnapper_I2C_Driver_SEN5X_H
17 #define WipperSnapper_I2C_Driver_SEN5X_H
18 
20 #include <SensirionI2CSen5x.h>
21 #include <Wire.h>
22 
23 /**************************************************************************/
27 /**************************************************************************/
29 
30  const float OVERFLOW_SEN55 = (0xFFFF / 10); // maxes out at u_int16 / 10
31 
32 public:
33  /*******************************************************************************/
41  /*******************************************************************************/
42  WipperSnapper_I2C_Driver_SEN5X(TwoWire *i2c, uint16_t sensorAddress)
43  : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
44  _i2c = i2c;
45  _sensorAddress = sensorAddress;
46  }
47 
48  /*******************************************************************************/
53  /*******************************************************************************/
54  bool begin() {
55  _sen = new SensirionI2CSen5x();
56  _sen->begin(*_i2c);
57  u_int16_t error_stop = _sen->deviceReset();
58  if (error_stop != 0) {
59  return false;
60  }
61  // Wait 1 second for sensors to start recording + 100ms for reset command
62  delay(1100);
63  u_int16_t error_start = _sen->startMeasurement();
64  if (error_start != 0) {
65  return false;
66  }
67 
68  return true;
69  }
70 
71  /*******************************************************************************/
79  /*******************************************************************************/
80  bool getEventAmbientTemp(sensors_event_t *tempEvent) {
81  float massConcentrationPm1p0, massConcentrationPm2p5,
82  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
83  ambientTemperature, vocIndex, noxIndex;
84  uint16_t error;
85 
86  error = _sen->readMeasuredValues(
87  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
88  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
89  noxIndex);
90  if ((_tempSensorPeriod != 0 && error != 0) || ambientTemperature == NAN) {
91  return false;
92  }
93 
94  tempEvent->temperature = ambientTemperature;
95  return true;
96  }
97 
98  /*******************************************************************************/
106  /*******************************************************************************/
107  bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
108  float massConcentrationPm1p0, massConcentrationPm2p5,
109  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
110  ambientTemperature, vocIndex, noxIndex;
111  uint16_t error;
112 
113  error = _sen->readMeasuredValues(
114  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
115  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
116  noxIndex);
117  if ((_humidSensorPeriod != 0 && error != 0) || ambientHumidity == NAN) {
118  return false;
119  }
120 
121  humidEvent->relative_humidity = ambientHumidity;
122  return true;
123  }
124 
125  /*******************************************************************************/
136  /*******************************************************************************/
137  bool getEventNOxIndex(sensors_event_t *noxIndexEvent) {
138  float massConcentrationPm1p0, massConcentrationPm2p5,
139  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
140  ambientTemperature, vocIndex, noxIndex;
141  uint16_t error;
142 
143  error = _sen->readMeasuredValues(
144  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
145  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
146  noxIndex);
147  if ((_NOxIndexPeriod != 0 && error != 0) || noxIndex == NAN) {
148  return false;
149  }
150 
151  noxIndexEvent->nox_index = noxIndex;
152  return true;
153  }
154 
155  /*******************************************************************************/
163  /*******************************************************************************/
164  bool getEventVOCIndex(sensors_event_t *vocIndexEvent) {
165  float massConcentrationPm1p0, massConcentrationPm2p5,
166  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
167  ambientTemperature, vocIndex, noxIndex;
168  uint16_t error;
169 
170  error = _sen->readMeasuredValues(
171  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
172  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
173  noxIndex);
174  if ((_VOCIndexPeriod != 0 && error != 0) || vocIndex == NAN) {
175  return false;
176  }
177 
178  vocIndexEvent->voc_index = vocIndex;
179  return true;
180  }
181 
182  /*******************************************************************************/
190  /*******************************************************************************/
191  bool getEventPM10_STD(sensors_event_t *pm10StdEvent) {
192  float massConcentrationPm1p0, massConcentrationPm2p5,
193  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
194  ambientTemperature, vocIndex, noxIndex;
195  uint16_t error;
196 
197  error = _sen->readMeasuredValues(
198  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
199  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
200  noxIndex);
201  if ((_PM10SensorPeriod != 0 && error != 0) ||
202  massConcentrationPm1p0 == NAN ||
203  massConcentrationPm1p0 == OVERFLOW_SEN55) {
204  return false;
205  }
206 
207  pm10StdEvent->pm10_std = massConcentrationPm1p0;
208  return true;
209  }
210 
211  /*******************************************************************************/
219  /*******************************************************************************/
220  bool getEventPM25_STD(sensors_event_t *pm25StdEvent) {
221  float massConcentrationPm1p0, massConcentrationPm2p5,
222  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
223  ambientTemperature, vocIndex, noxIndex;
224  uint16_t error;
225 
226  error = _sen->readMeasuredValues(
227  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
228  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
229  noxIndex);
230  if ((_PM25SensorPeriod != 0 && error != 0) ||
231  massConcentrationPm2p5 == NAN ||
232  massConcentrationPm2p5 == OVERFLOW_SEN55) {
233  return false;
234  }
235 
236  pm25StdEvent->pm25_std = massConcentrationPm2p5;
237  return true;
238  }
239 
240  /*******************************************************************************/
248  /*******************************************************************************/
249  bool getEventPM40_STD(sensors_event_t *pm40StdEvent) {
250  float massConcentrationPm1p0, massConcentrationPm2p5,
251  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
252  ambientTemperature, vocIndex, noxIndex;
253  uint16_t error;
254 
255  error = _sen->readMeasuredValues(
256  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
257  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
258  noxIndex);
259  if ((_PM25SensorPeriod != 0 && error != 0) ||
260  massConcentrationPm4p0 == NAN ||
261  massConcentrationPm4p0 == OVERFLOW_SEN55) {
262  return false;
263  }
264 
265  pm40StdEvent->data[0] = massConcentrationPm4p0;
266  return true;
267  }
268 
269  /*******************************************************************************/
277  /*******************************************************************************/
278  bool getEventPM100_STD(sensors_event_t *pm100StdEvent) {
279  float massConcentrationPm1p0, massConcentrationPm2p5,
280  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
281  ambientTemperature, vocIndex, noxIndex;
282  uint16_t error;
283 
284  error = _sen->readMeasuredValues(
285  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
286  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
287  noxIndex);
288  if ((_PM100SensorPeriod != 0 && error != 0) ||
289  massConcentrationPm10p0 == NAN ||
290  massConcentrationPm10p0 == OVERFLOW_SEN55) {
291  return false;
292  }
293 
294  pm100StdEvent->pm100_std = massConcentrationPm10p0;
295  return true;
296  }
297 
298 protected:
299  SensirionI2CSen5x *_sen;
300 };
301 
302 #endif // WipperSnapper_I2C_Driver_SEN5X
SensirionI2CSen5x * _sen
SEN5X driver object.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:299
+
bool getEventVOCIndex(sensors_event_t *vocIndexEvent)
Gets the SEN5X&#39;s current VOC reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:164
long _PM10SensorPeriod
The time period between reading the pm25 sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1365
long _PM100SensorPeriod
The time period between reading the pm100_std sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1373
-
bool getEventRelativeHumidity(sensors_event_t *humidEvent)
Gets the SEN5X&#39;s current relative humidity reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:108
-
bool getEventPM25_STD(sensors_event_t *pm25StdEvent)
Gets the SEN5X sensor&#39;s PM2.5 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:221
-
WipperSnapper_I2C_Driver_SEN5X(TwoWire *i2c, uint16_t sensorAddress)
Constructor for a SEN5X sensor.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:43
-
bool getEventPM100_STD(sensors_event_t *pm100StdEvent)
Gets the SEN5X sensor&#39;s PM10.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:279
+
bool getEventRelativeHumidity(sensors_event_t *humidEvent)
Gets the SEN5X&#39;s current relative humidity reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:107
+
bool getEventPM25_STD(sensors_event_t *pm25StdEvent)
Gets the SEN5X sensor&#39;s PM2.5 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:220
+
WipperSnapper_I2C_Driver_SEN5X(TwoWire *i2c, uint16_t sensorAddress)
Constructor for a SEN5X sensor.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:42
+
bool getEventPM100_STD(sensors_event_t *pm100StdEvent)
Gets the SEN5X sensor&#39;s PM10.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:278
long _tempSensorPeriod
The time period between reading the temperature sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1323
-
bool getEventPM40_STD(sensors_event_t *pm40StdEvent)
Gets the SEN5X sensor&#39;s PM4.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:250
+
bool getEventPM40_STD(sensors_event_t *pm40StdEvent)
Gets the SEN5X sensor&#39;s PM4.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:249
Base class for I2C Drivers.
Definition: WipperSnapper_I2C_Driver.h:30
-
Class that provides a driver interface for the SEN5X sensor.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:29
-
bool getEventNOxIndex(sensors_event_t *noxIndexEvent)
Gets the SEN5X&#39;s current NOX reading. Note: If this value is unknown, which is true for SEN54...
Definition: WipperSnapper_I2C_Driver_SEN5X.h:138
+
Class that provides a driver interface for the SEN5X sensor.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:28
+
bool getEventNOxIndex(sensors_event_t *noxIndexEvent)
Gets the SEN5X&#39;s current NOX reading. Note: If this value is unknown, which is true for SEN54...
Definition: WipperSnapper_I2C_Driver_SEN5X.h:137
long _humidSensorPeriod
The time period between reading the humidity sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1328
-
bool getEventPM10_STD(sensors_event_t *pm10StdEvent)
Gets the SEN5X sensor&#39;s PM1.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:192
+
bool getEventPM10_STD(sensors_event_t *pm10StdEvent)
Gets the SEN5X sensor&#39;s PM1.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:191
uint16_t _sensorAddress
The I2C driver&#39;s unique I2C address.
Definition: WipperSnapper_I2C_Driver.h:1322
long _VOCIndexPeriod
The time period between reading the VOC Index sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1417
-
bool getEventAmbientTemp(sensors_event_t *tempEvent)
Gets the SEN5X&#39;s current temperature.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:81
+
bool getEventAmbientTemp(sensors_event_t *tempEvent)
Gets the SEN5X&#39;s current temperature.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:80
-
bool begin()
Initializes the SEN5X sensor and begins I2C.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:55
+
bool begin()
Initializes the SEN5X sensor and begins I2C.
Definition: WipperSnapper_I2C_Driver_SEN5X.h:54
long _PM25SensorPeriod
The time period between reading the pm25 sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1369
long _NOxIndexPeriod
The time period between reading the NOx Index sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1412
TwoWire * _i2c
Pointer to the I2C driver&#39;s Wire object.
Definition: WipperSnapper_I2C_Driver.h:1321
diff --git a/html/_wipper_snapper___i2_c___driver___s_e_n6_x_8h.html b/html/_wipper_snapper___i2_c___driver___s_e_n6_x_8h.html new file mode 100644 index 000000000..3cd126ddb --- /dev/null +++ b/html/_wipper_snapper___i2_c___driver___s_e_n6_x_8h.html @@ -0,0 +1,96 @@ + + + + + + + +Adafruit Library: src/components/i2c/drivers/WipperSnapper_I2C_Driver_SEN6X.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
Adafruit Library +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
WipperSnapper_I2C_Driver_SEN6X.h File Reference
+
+
+
#include "WipperSnapper_I2C_Driver.h"
+#include <SensirionI2cSen66.h>
+#include <Wire.h>
+
+

Go to the source code of this file.

+ + + + + +

+Classes

class  WipperSnapper_I2C_Driver_SEN6X
 Class that provides a driver interface for the SEN6X sensor. More...
 
+

Detailed Description

+

Device driver for the SEN66 Particulate Matter, Temperature, Humidity, VOC, NOX, and CO2 sensor.

+

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

+

Copyright (c) Tyeth Gundry 2022 for Adafruit Industries. Modified (c) by Martin Ebner 2024 https://github.com/MartinEbnerSensirion

+

MIT license, all text here must be included in any redistribution.

+
+ + + + diff --git a/html/_wipper_snapper___i2_c___driver___s_e_n6_x_8h_source.html b/html/_wipper_snapper___i2_c___driver___s_e_n6_x_8h_source.html new file mode 100644 index 000000000..02a0baa36 --- /dev/null +++ b/html/_wipper_snapper___i2_c___driver___s_e_n6_x_8h_source.html @@ -0,0 +1,102 @@ + + + + + + + +Adafruit Library: src/components/i2c/drivers/WipperSnapper_I2C_Driver_SEN6X.h Source File + + + + + + + + + +
+
+ + + + + + +
+
Adafruit Library +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
WipperSnapper_I2C_Driver_SEN6X.h
+
+
+Go to the documentation of this file.
1 
18 #ifndef WipperSnapper_I2C_Driver_SEN6X_H
19 #define WipperSnapper_I2C_Driver_SEN6X_H
20 
22 #include <SensirionI2cSen66.h>
23 #include <Wire.h>
24 
25 /**************************************************************************/
29 /**************************************************************************/
31 
32  const float OVERFLOW_SEN6X = (0xFFFF / 10); // maxes out at u_int16 / 10
33 
34 public:
35  /*******************************************************************************/
43  /*******************************************************************************/
44  WipperSnapper_I2C_Driver_SEN6X(TwoWire *i2c, uint16_t sensorAddress)
45  : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
46  _i2c = i2c;
47  _sensorAddress = sensorAddress;
48  }
49 
50  /*******************************************************************************/
55  /*******************************************************************************/
56  bool begin() {
57  _sen = new SensirionI2cSen66();
58  _sen->begin(*_i2c, (uint8_t)_sensorAddress);
59  u_int16_t error_stop = _sen->deviceReset();
60  if (error_stop != 0) {
61  return false;
62  }
63  // Wait 1 second for sensors to start recording + 100ms for reset command
64  delay(1100);
65  u_int16_t error_start = _sen->startContinuousMeasurement();
66  if (error_start != 0) {
67  return false;
68  }
69 
70  return true;
71  }
72 
73  /*******************************************************************************/
81  /*******************************************************************************/
82  bool getEventAmbientTemp(sensors_event_t *tempEvent) {
83  float massConcentrationPm1p0, massConcentrationPm2p5,
84  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
85  ambientTemperature, vocIndex, noxIndex;
86  uint16_t co2;
87  uint16_t error;
88 
89  error = _sen->readMeasuredValues(
90  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
91  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
92  noxIndex, co2);
93  if ((_tempSensorPeriod != 0 && error != 0) || ambientTemperature == NAN) {
94  return false;
95  }
96 
97  tempEvent->temperature = ambientTemperature;
98  return true;
99  }
100 
101  /*******************************************************************************/
109  /*******************************************************************************/
110  bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
111  float massConcentrationPm1p0, massConcentrationPm2p5,
112  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
113  ambientTemperature, vocIndex, noxIndex;
114  uint16_t co2;
115  uint16_t error;
116 
117  error = _sen->readMeasuredValues(
118  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
119  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
120  noxIndex, co2);
121  if ((_humidSensorPeriod != 0 && error != 0) || ambientHumidity == NAN) {
122  return false;
123  }
124 
125  humidEvent->relative_humidity = ambientHumidity;
126  return true;
127  }
128 
129  /*******************************************************************************/
140  /*******************************************************************************/
141  bool getEventNOxIndex(sensors_event_t *noxIndexEvent) {
142  float massConcentrationPm1p0, massConcentrationPm2p5,
143  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
144  ambientTemperature, vocIndex, noxIndex;
145  uint16_t co2;
146  uint16_t error;
147 
148  error = _sen->readMeasuredValues(
149  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
150  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
151  noxIndex, co2);
152  if ((_NOxIndexPeriod != 0 && error != 0) || noxIndex == NAN) {
153  return false;
154  }
155 
156  noxIndexEvent->nox_index = noxIndex;
157  return true;
158  }
159 
160  /*******************************************************************************/
168  /*******************************************************************************/
169  bool getEventVOCIndex(sensors_event_t *vocIndexEvent) {
170  float massConcentrationPm1p0, massConcentrationPm2p5,
171  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
172  ambientTemperature, vocIndex, noxIndex;
173  uint16_t co2;
174  uint16_t error;
175 
176  error = _sen->readMeasuredValues(
177  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
178  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
179  noxIndex, co2);
180  if ((_VOCIndexPeriod != 0 && error != 0) || vocIndex == NAN) {
181  return false;
182  }
183 
184  vocIndexEvent->voc_index = vocIndex;
185  return true;
186  }
187 
188  /*******************************************************************************/
196  /*******************************************************************************/
197  bool getEventPM10_STD(sensors_event_t *pm10StdEvent) {
198  float massConcentrationPm1p0, massConcentrationPm2p5,
199  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
200  ambientTemperature, vocIndex, noxIndex;
201  uint16_t co2;
202  uint16_t error;
203 
204  error = _sen->readMeasuredValues(
205  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
206  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
207  noxIndex, co2);
208  if ((_PM10SensorPeriod != 0 && error != 0) ||
209  massConcentrationPm1p0 == NAN ||
210  massConcentrationPm1p0 == OVERFLOW_SEN6X) {
211  return false;
212  }
213 
214  pm10StdEvent->pm10_std = massConcentrationPm1p0;
215  return true;
216  }
217 
218  /*******************************************************************************/
226  /*******************************************************************************/
227  bool getEventPM25_STD(sensors_event_t *pm25StdEvent) {
228  float massConcentrationPm1p0, massConcentrationPm2p5,
229  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
230  ambientTemperature, vocIndex, noxIndex;
231  uint16_t co2;
232  uint16_t error;
233 
234  error = _sen->readMeasuredValues(
235  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
236  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
237  noxIndex, co2);
238  if ((_PM25SensorPeriod != 0 && error != 0) ||
239  massConcentrationPm2p5 == NAN ||
240  massConcentrationPm2p5 == OVERFLOW_SEN6X) {
241  return false;
242  }
243 
244  pm25StdEvent->pm25_std = massConcentrationPm2p5;
245  return true;
246  }
247 
248  /*******************************************************************************/
256  /*******************************************************************************/
257  bool getEventPM40_STD(sensors_event_t *pm40StdEvent) {
258  float massConcentrationPm1p0, massConcentrationPm2p5,
259  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
260  ambientTemperature, vocIndex, noxIndex;
261  uint16_t co2;
262  uint16_t error;
263 
264  error = _sen->readMeasuredValues(
265  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
266  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
267  noxIndex, co2);
268  if ((_PM25SensorPeriod != 0 && error != 0) ||
269  massConcentrationPm4p0 == NAN ||
270  massConcentrationPm4p0 == OVERFLOW_SEN6X) {
271  return false;
272  }
273 
274  pm40StdEvent->data[0] = massConcentrationPm4p0;
275  return true;
276  }
277 
278  /*******************************************************************************/
286  /*******************************************************************************/
287  bool getEventPM100_STD(sensors_event_t *pm100StdEvent) {
288  float massConcentrationPm1p0, massConcentrationPm2p5,
289  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
290  ambientTemperature, vocIndex, noxIndex;
291  uint16_t co2;
292  uint16_t error;
293 
294  error = _sen->readMeasuredValues(
295  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
296  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
297  noxIndex, co2);
298  if ((_PM100SensorPeriod != 0 && error != 0) ||
299  massConcentrationPm10p0 == NAN ||
300  massConcentrationPm10p0 == OVERFLOW_SEN6X) {
301  return false;
302  }
303 
304  pm100StdEvent->pm100_std = massConcentrationPm10p0;
305  return true;
306  }
307 
308  /*******************************************************************************/
316  /*******************************************************************************/
317  bool getEventCO2(sensors_event_t *co2Event) {
318  float massConcentrationPm1p0, massConcentrationPm2p5,
319  massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity,
320  ambientTemperature, vocIndex, noxIndex;
321  uint16_t co2;
322  uint16_t error;
323 
324  error = _sen->readMeasuredValues(
325  massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
326  massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex,
327  noxIndex, co2);
328 
329  if ((_CO2SensorPeriod != 0 && error != 0) || co2 == 0xFFFF) {
330  return false;
331  }
332 
333  co2Event->CO2 = co2;
334  return true;
335  }
336 
337 protected:
338  SensirionI2cSen66 *_sen;
339 };
340 
341 #endif // WipperSnapper_I2C_Driver_SEN6X
long _PM10SensorPeriod
The time period between reading the pm25 sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1365
+
long _PM100SensorPeriod
The time period between reading the pm100_std sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1373
+
bool getEventPM40_STD(sensors_event_t *pm40StdEvent)
Gets the SEN6X sensor&#39;s PM4.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:257
+
bool getEventCO2(sensors_event_t *co2Event)
Gets the SEN6X sensor&#39;s CO2 reading.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:317
+
bool getEventNOxIndex(sensors_event_t *noxIndexEvent)
Gets the SEN6X&#39;s current NOX reading. Note: If this value is unknown, which is true for SEN54...
Definition: WipperSnapper_I2C_Driver_SEN6X.h:141
+
bool getEventRelativeHumidity(sensors_event_t *humidEvent)
Gets the SEN6X&#39;s current relative humidity reading.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:110
+
bool getEventPM10_STD(sensors_event_t *pm10StdEvent)
Gets the SEN6X sensor&#39;s PM1.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:197
+
bool getEventVOCIndex(sensors_event_t *vocIndexEvent)
Gets the SEN6X&#39;s current VOC reading.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:169
+
long _tempSensorPeriod
The time period between reading the temperature sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1323
+
bool getEventPM25_STD(sensors_event_t *pm25StdEvent)
Gets the SEN6X sensor&#39;s PM2.5 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:227
+
Base class for I2C Drivers.
Definition: WipperSnapper_I2C_Driver.h:30
+
Class that provides a driver interface for the SEN6X sensor.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:30
+
long _humidSensorPeriod
The time period between reading the humidity sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1328
+
bool getEventPM100_STD(sensors_event_t *pm100StdEvent)
Gets the SEN6X sensor&#39;s PM10.0 STD reading.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:287
+
uint16_t _sensorAddress
The I2C driver&#39;s unique I2C address.
Definition: WipperSnapper_I2C_Driver.h:1322
+
long _VOCIndexPeriod
The time period between reading the VOC Index sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1417
+
WipperSnapper_I2C_Driver_SEN6X(TwoWire *i2c, uint16_t sensorAddress)
Constructor for a SEN6X sensor.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:44
+ +
bool begin()
Initializes the SEN6X sensor and begins I2C.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:56
+
SensirionI2cSen66 * _sen
SEN6X driver object.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:338
+
long _PM25SensorPeriod
The time period between reading the pm25 sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1369
+
long _CO2SensorPeriod
The time period between reading the CO2 sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1338
+
bool getEventAmbientTemp(sensors_event_t *tempEvent)
Gets the SEN6X&#39;s current temperature.
Definition: WipperSnapper_I2C_Driver_SEN6X.h:82
+
long _NOxIndexPeriod
The time period between reading the NOx Index sensor&#39;s value.
Definition: WipperSnapper_I2C_Driver.h:1412
+
TwoWire * _i2c
Pointer to the I2C driver&#39;s Wire object.
Definition: WipperSnapper_I2C_Driver.h:1321
+
+ + + + diff --git a/html/_wipper_snapper___i2_c___driver___v_c_n_l4200_8h.html b/html/_wipper_snapper___i2_c___driver___v_c_n_l4200_8h.html new file mode 100644 index 000000000..707379fe9 --- /dev/null +++ b/html/_wipper_snapper___i2_c___driver___v_c_n_l4200_8h.html @@ -0,0 +1,95 @@ + + + + + + + +Adafruit Library: src/components/i2c/drivers/WipperSnapper_I2C_Driver_VCNL4200.h File Reference + + + + + + + + + +
+
+ + + + + + +
+
Adafruit Library +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
WipperSnapper_I2C_Driver_VCNL4200.h File Reference
+
+
+
#include "WipperSnapper_I2C_Driver.h"
+#include <Adafruit_VCNL4200.h>
+
+

Go to the source code of this file.

+ + + + + +

+Classes

class  WipperSnapper_I2C_Driver_VCNL4200
 Class that provides a driver interface for a VCNL4200 sensor. More...
 
+

Detailed Description

+

Device driver for the VCNL4200 light + proximity sensor.

+

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

+

Copyright (c) Tyeth Gundry 2024 for Adafruit Industries.

+

MIT license, all text here must be included in any redistribution.

+
+ + + + diff --git a/html/_wipper_snapper___i2_c___driver___v_c_n_l4200_8h_source.html b/html/_wipper_snapper___i2_c___driver___v_c_n_l4200_8h_source.html new file mode 100644 index 000000000..da57f3d70 --- /dev/null +++ b/html/_wipper_snapper___i2_c___driver___v_c_n_l4200_8h_source.html @@ -0,0 +1,88 @@ + + + + + + + +Adafruit Library: src/components/i2c/drivers/WipperSnapper_I2C_Driver_VCNL4200.h Source File + + + + + + + + + +
+
+ + + + + + +
+
Adafruit Library +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
WipperSnapper_I2C_Driver_VCNL4200.h
+
+
+Go to the documentation of this file.
1 
15 #ifndef WipperSnapper_I2C_Driver_VCNL4200_H
16 #define WipperSnapper_I2C_Driver_VCNL4200_H
17 
19 #include <Adafruit_VCNL4200.h>
20 
21 /**************************************************************************/
25 /**************************************************************************/
27 public:
28  /*******************************************************************************/
36  /*******************************************************************************/
37  WipperSnapper_I2C_Driver_VCNL4200(TwoWire *i2c, uint16_t sensorAddress)
38  : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
39  _i2c = i2c;
40  _sensorAddress = sensorAddress;
41  }
42 
43  /*******************************************************************************/
47  /*******************************************************************************/
49 
50  /*******************************************************************************/
55  /*******************************************************************************/
56  bool begin() {
57  _vcnl4200 = new Adafruit_VCNL4200();
58  bool status = false;
59  // Attempt to initialize and configure VCNL4200
60  if (!_vcnl4200->begin(_sensorAddress, _i2c)) {
61  return false;
62  }
63  status = _vcnl4200->setALSshutdown(false);
64  status &= _vcnl4200->setProxShutdown(false);
65  status &= _vcnl4200->setProxHD(true); // 16bit instead of 12bit
66  status &= _vcnl4200->setALSIntegrationTime(VCNL4200_ALS_IT_400MS);
67  status &= _vcnl4200->setProxDuty(VCNL4200_PS_DUTY_1_160);
68  status &= _vcnl4200->setProxLEDCurrent(VCNL4200_LED_I_200MA);
69  status &= _vcnl4200->setProxIntegrationTime(VCNL4200_PS_IT_9T);
70  return status;
71  }
72 
73  /*******************************************************************************/
82  /*******************************************************************************/
83  bool getEventLight(sensors_event_t *lightEvent) {
84  // Get sensor event populated in lux via AUTO integration and gain
85  lightEvent->light = _vcnl4200->readALSdata();
86  return true;
87  }
88 
89  /*******************************************************************************/
97  /*******************************************************************************/
98  bool getEventProximity(sensors_event_t *proximityEvent) {
99  proximityEvent->data[0] = (float)_vcnl4200->readProxData();
100  return true;
101  }
102 
103 protected:
104  Adafruit_VCNL4200 *_vcnl4200;
105 };
106 
107 #endif // WipperSnapper_I2C_Driver_VCNL4200
~WipperSnapper_I2C_Driver_VCNL4200()
Destructor for an VCNL4200 sensor.
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:48
+
Base class for I2C Drivers.
Definition: WipperSnapper_I2C_Driver.h:30
+
bool getEventLight(sensors_event_t *lightEvent)
Performs a light sensor read using the Adafruit Unified Sensor API.
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:83
+
uint16_t _sensorAddress
The I2C driver&#39;s unique I2C address.
Definition: WipperSnapper_I2C_Driver.h:1322
+
bool begin()
Initializes the VCNL4200 sensor and begins I2C.
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:56
+ +
WipperSnapper_I2C_Driver_VCNL4200(TwoWire *i2c, uint16_t sensorAddress)
Constructor for a VCNL4200 sensor.
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:37
+
Class that provides a driver interface for a VCNL4200 sensor.
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:26
+
bool getEventProximity(sensors_event_t *proximityEvent)
Reads the VCNL4200&#39;s proximity value into an event (no unit).
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:98
+
Adafruit_VCNL4200 * _vcnl4200
Pointer to VCNL4200 light sensor object.
Definition: WipperSnapper_I2C_Driver_VCNL4200.h:104
+
TwoWire * _i2c
Pointer to the I2C driver&#39;s Wire object.
Definition: WipperSnapper_I2C_Driver.h:1321
+
+ + + + diff --git a/html/_wippersnapper_8h.html b/html/_wippersnapper_8h.html index 1a8ceedfd..54d616c34 100644 --- a/html/_wippersnapper_8h.html +++ b/html/_wippersnapper_8h.html @@ -137,7 +137,7 @@  Retry a function until a condition is met or a timeout is reached. More...
  -#define WS_VERSION   "1.0.0-beta.92" +#define WS_VERSION   "1.0.0-beta.95"  WipperSnapper app. version (semver-formatted)
  diff --git a/html/_wippersnapper_8h_source.html b/html/_wippersnapper_8h_source.html index d59720417..ad95e308a 100644 --- a/html/_wippersnapper_8h_source.html +++ b/html/_wippersnapper_8h_source.html @@ -66,152 +66,152 @@
Wippersnapper.h
-Go to the documentation of this file.
1 
18 #ifndef WIPPERSNAPPER_H
19 #define WIPPERSNAPPER_H
20 
21 // Cpp STD
22 #include <vector>
23 
24 // Nanopb dependencies
25 #include <nanopb/pb_common.h>
26 #include <nanopb/pb_decode.h>
27 #include <nanopb/pb_encode.h>
28 #include <pb.h>
29 
30 #include <wippersnapper/description/v1/description.pb.h> // description.proto
31 #include <wippersnapper/signal/v1/signal.pb.h> // signal.proto
32 
33 // External libraries
34 #include "Adafruit_MQTT.h" // MQTT Client
35 #include "Adafruit_SleepyDog.h" // Watchdog
36 #include "Arduino.h" // Wiring
37 #include <SPI.h> // SPI
38 
39 // Wippersnapper API Helpers
40 #include "Wippersnapper_Boards.h"
42 #include "provisioning/ConfigJson.h"
43 
44 #define WS_DEBUG
45 #define WS_PRINTER Serial
46 
47 // Define actual debug output functions when necessary.
48 #ifdef WS_DEBUG
49 #define WS_DEBUG_PRINT(...) \
50  { WS_PRINTER.print(__VA_ARGS__); }
51 #define WS_DEBUG_PRINTLN(...) \
52  { WS_PRINTER.println(__VA_ARGS__); }
53 #define WS_DEBUG_PRINTHEX(...) \
54  { WS_PRINTER.print(__VA_ARGS__, HEX); }
55 #else
56 #define WS_DEBUG_PRINT(...) \
57  {}
58 #define WS_DEBUG_PRINTLN(...) \
59  {}
60 #endif
61 
62 #define WS_DELAY_WITH_WDT(timeout) \
63  { \
64  unsigned long start = millis(); \
65  while (millis() - start < timeout) { \
66  delay(10); \
67  yield(); \
68  feedWDT(); \
69  if (millis() < start) { \
70  start = millis(); /* if rollover */ \
71  } \
72  } \
73  }
74 
75 /**************************************************************************/
93 /**************************************************************************/
94 #define RETRY_FUNCTION_UNTIL_TIMEOUT(func, result_type, result_var, condition, \
95  timeout, interval, ...) \
96  { \
97  unsigned long startTime = millis(); \
98  while (millis() - startTime < timeout) { \
99  result_type result_var = func(__VA_ARGS__); \
100  if (condition(result_var)) { \
101  break; \
102  } \
103  if (startTime > millis()) { \
104  startTime = millis(); /* if rollover */ \
105  } \
106  WS_DELAY_WITH_WDT(interval); \
107  } \
108  }
109 
110 // Wippersnapper pb helpers
111 #include <nanopb/ws_pb_helpers.h>
112 
113 // Wippersnapper components
117 
118 // Includes for ESP32-only
119 #ifdef ARDUINO_ARCH_ESP32
120 #include "components/ledc/ws_ledc.h"
121 #include <Esp.h>
122 #endif
123 
124 // Display
125 #ifdef USE_DISPLAY
128 #endif
129 
132 #include "components/pwm/ws_pwm.h"
134 #include "components/uart/ws_uart.h"
135 
136 #if defined(USE_TINYUSB)
137 #include "provisioning/tinyusb/Wippersnapper_FS.h"
138 #endif
139 
140 #if defined(USE_LITTLEFS)
141 #include "provisioning/littlefs/WipperSnapper_LittleFS.h"
142 #endif
143 
144 #define WS_VERSION \
145  "1.0.0-beta.92"
146 
147 // Reserved Adafruit IO MQTT topics
148 #define TOPIC_IO_THROTTLE "/throttle"
149 #define TOPIC_IO_ERRORS "/errors"
150 
151 // Reserved Wippersnapper topics
152 #define TOPIC_WS "/wprsnpr/"
153 #define TOPIC_INFO "/info/"
154 #define TOPIC_SIGNALS "/signals/"
155 #define TOPIC_I2C "/i2c"
156 #define MQTT_TOPIC_PIXELS_DEVICE \
157  "/signals/device/pixel"
158 #define MQTT_TOPIC_PIXELS_BROKER \
159  "/signals/broker/pixel"
160 
161 
162 typedef enum {
163  WS_IDLE = 0, // Waiting for connection establishement
164  WS_NET_DISCONNECTED = 1, // Network disconnected
165  WS_DISCONNECTED = 2, // Disconnected from Adafruit IO
166  WS_FINGERPRINT_UNKOWN = 3, // Unknown WS_SSL_FINGERPRINT
167 
168  WS_NET_CONNECT_FAILED = 10, // Failed to connect to network
169  WS_CONNECT_FAILED = 11, // Failed to connect to Adafruit IO
170  WS_FINGERPRINT_INVALID = 12, // Unknown WS_SSL_FINGERPRINT
171  WS_AUTH_FAILED = 13, // Invalid Adafruit IO login credentials provided.
172  WS_SSID_INVALID =
173  14, // SSID is "" or otherwise invalid, connection not attempted
174 
175  WS_NET_CONNECTED = 20, // Connected to Adafruit IO
176  WS_CONNECTED = 21, // Connected to network
177  WS_CONNECTED_INSECURE = 22, // Insecurely (non-SSL) connected to network
178  WS_FINGERPRINT_UNSUPPORTED = 23, // Unsupported WS_SSL_FINGERPRINT
179  WS_FINGERPRINT_VALID = 24, // Valid WS_SSL_FINGERPRINT
180  WS_BOARD_DESC_INVALID = 25, // Unable to send board description
181  WS_BOARD_RESYNC_FAILED = 26 // Board sync failure
185 typedef enum {
186  WS_MQTT_CONNECTED = 0, // Connected
187  WS_MQTT_INVALID_PROTOCOL = 1, // Invalid mqtt protocol
188  WS_MQTT_INVALID_CID = 2, // Client id rejected
189  WS_MQTT_SERVICE_UNAVALIABLE = 3, // Malformed user/pass
190  WS_MQTT_INVALID_USER_PASS = 4, // Unauthorized access to resource
191  WS_MQTT_UNAUTHORIZED = 5, // MQTT service unavailable
192  WS_MQTT_THROTTLED = 6, // Account throttled
193  WS_MQTT_BANNED = 7 // Account banned
195 
197 typedef enum {
198  WS_BOARD_DEF_IDLE,
199  WS_BOARD_DEF_SEND_FAILED,
200  WS_BOARD_DEF_SENT,
201  WS_BOARD_DEF_OK,
202  WS_BOARD_DEF_INVALID,
203  WS_BOARD_DEF_UNSPECIFIED
205 
207 typedef enum {
208  FSM_NET_IDLE,
209  FSM_NET_CONNECTED,
210  FSM_MQTT_CONNECTED,
211  FSM_NET_CHECK_MQTT,
212  FSM_NET_CHECK_NETWORK,
213  FSM_NET_ESTABLISH_NETWORK,
214  FSM_NET_ESTABLISH_MQTT,
215 } fsm_net_t;
216 
217 #define WS_WDT_TIMEOUT 60000
218 #define WS_MAX_ALT_WIFI_NETWORKS 3
219 /* MQTT Configuration */
220 #define WS_KEEPALIVE_INTERVAL_MS \
221  5000
222 
223 #define WS_MQTT_MAX_PAYLOAD_SIZE \
224  512
228 class Wippersnapper_FS;
229 class WipperSnapper_LittleFS;
230 #ifdef USE_DISPLAY
231 class ws_display_driver;
233 #endif
234 #ifdef ARDUINO_ARCH_ESP32
235 class ws_ledc;
236 #endif
238 class ws_servo;
239 class ws_pwm;
240 class ws_ds18x20;
241 class ws_pixels;
242 class ws_uart;
243 
244 /**************************************************************************/
249 /**************************************************************************/
250 class Wippersnapper {
251 public:
252  Wippersnapper();
253  virtual ~Wippersnapper();
254 
255  void provision();
256 
257  bool lockStatusNeoPixel;
258  bool lockStatusDotStar;
259  bool lockStatusLED;
262 
264  virtual void set_user_key();
265  virtual void set_ssid_pass(const char *ssid, const char *ssidPassword);
266  virtual void set_ssid_pass();
267  virtual bool check_valid_ssid();
268 
269  virtual void _connect();
270  virtual void _disconnect();
271  void connect();
272  void disconnect();
273 
274  virtual void getMacAddr();
275  virtual int32_t getRSSI();
276  virtual void setupMQTTClient(const char *clientID);
277 
280 
281  bool generateDeviceUID();
282  bool generateWSTopics();
283  bool generateWSErrorTopics();
284 
285  // Registration API
288  void decodeRegistrationResp(char *data, uint16_t len);
289  void pollRegistrationResp();
290  // Configuration API
292 
293  // run() loop
294  ws_status_t run();
295  void processPackets();
296  void publish(const char *topic, uint8_t *payload, uint16_t bLen,
297  uint8_t qos = 0);
298 
299  // Networking helpers
300  void pingBroker();
301  void runNetFSM();
302 
303  // WDT helpers
304  void enableWDT(int timeoutMS = 0);
305  void feedWDT();
306 
307  // Error handling helpers
308  void haltError(String error,
309  ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME);
310  void errorWriteHang(String error);
311 
312  // MQTT topic callbacks //
313  // Decodes a signal message
314  bool decodeSignalMsg(
315  wippersnapper_signal_v1_CreateSignalRequest *encodedSignalMsg);
316 
317  // Encodes a pin event message
318  bool
319  encodePinEvent(wippersnapper_signal_v1_CreateSignalRequest *outgoingSignalMsg,
320  uint8_t pinName, int pinVal);
321 
322  // Pin configure message
323  bool configureDigitalPinReq(wippersnapper_pin_v1_ConfigurePinRequest *pinMsg);
324  bool configAnalogInPinReq(wippersnapper_pin_v1_ConfigurePinRequest *pinMsg);
325 
326  // I2C
327  std::vector<WipperSnapper_Component_I2C *>
328  i2cComponents;
330  NULL;
332  NULL;
333  bool _isI2CPort0Init =
334  false;
335  bool _isI2CPort1Init =
336  false;
337 
340  uint8_t
343  uint16_t bufSize;
346  WS_BOARD_DEF_IDLE;
347 
348  // TODO: We really should look at making these static definitions, not dynamic
349  // to free up space on the heap
352  Wippersnapper_FS *_fileSystem;
353  WipperSnapper_LittleFS
354  *_littleFS;
355 #ifdef USE_DISPLAY
358  nullptr;
359 #endif
365 
366  // TODO: does this really need to be global?
367  uint8_t _macAddr[6];
368  char sUID[13];
369  const char *_boardId;
370  Adafruit_MQTT *_mqtt;
372  secretsConfig _config;
373  networkConfig _multiNetworks[3];
374  bool _isWiFiMulti = false;
376  // TODO: Does this need to be within this class?
377  int32_t totalDigitalPins;
379  char *_topic_description = NULL;
380  char *_topic_signal_device = NULL;
381  char *_topic_signal_i2c_brkr = NULL;
383  char *_topic_signal_i2c_device = NULL;
387  char *_topic_signal_servo_device = NULL;
390  NULL;
392  NULL;
393  char *_topic_signal_ds18_brkr = NULL;
399  char *_topic_signal_uart_brkr = NULL;
402  wippersnapper_signal_v1_CreateSignalRequest
404  wippersnapper_signal_v1_I2CRequest msgSignalI2C =
405  wippersnapper_signal_v1_I2CRequest_init_zero;
406 
408  // ds signal msg
409  wippersnapper_signal_v1_Ds18x20Request msgSignalDS =
410  wippersnapper_signal_v1_Ds18x20Request_init_zero;
413  // servo message
414  wippersnapper_signal_v1_ServoRequest
416  wippersnapper_signal_v1_PWMRequest msgPWM =
417  wippersnapper_signal_v1_PWMRequest_init_zero;
418 
420  // pixels signal message
421  wippersnapper_signal_v1_PixelsRequest
422  msgPixels;
424  wippersnapper_signal_v1_UARTRequest
431  bool pinCfgCompleted = false;
433 // enable LEDC if esp32
434 #ifdef ARDUINO_ARCH_ESP32
435  ws_ledc *_ledc = nullptr;
436 #endif
438 private:
439  void _init();
440 
441 protected:
442  ws_status_t _status = WS_IDLE;
443  uint32_t _last_mqtt_connect = 0;
445  uint32_t _prv_ping = 0;
447  uint32_t _prvKATBlink = 0;
450  // Device information
451  const char *_deviceId;
452  char *_device_uid;
454  // MQTT topics
456  NULL;
462  NULL;
465  char *_topic_signal_brkr = NULL;
466  char *_err_topic = NULL;
467  char *_throttle_topic = NULL;
469  Adafruit_MQTT_Subscribe *_topic_description_sub;
471  Adafruit_MQTT_Publish *_topic_signal_device_pub;
473  Adafruit_MQTT_Subscribe *_topic_signal_brkr_sub;
475  Adafruit_MQTT_Subscribe
477  Adafruit_MQTT_Subscribe
479  Adafruit_MQTT_Subscribe
481  Adafruit_MQTT_Subscribe
483  Adafruit_MQTT_Subscribe
485  Adafruit_MQTT_Subscribe
488  Adafruit_MQTT_Subscribe
490  Adafruit_MQTT_Subscribe
491  *_throttle_sub;
493  wippersnapper_signal_v1_CreateSignalRequest
495 };
496 extern Wippersnapper WS;
498 #endif // ADAFRUIT_WIPPERSNAPPER_H
-
Class that provides an interface with the I2C bus.
Definition: WipperSnapper_I2C.h:84
-
char * _topic_signal_pixels_brkr
Definition: Wippersnapper.h:425
-
wippersnapper_signal_v1_PWMRequest msgPWM
Definition: Wippersnapper.h:444
+Go to the documentation of this file.
1 
18 #ifndef WIPPERSNAPPER_H
19 #define WIPPERSNAPPER_H
20 
21 // Cpp STD
22 #include <vector>
23 
24 // Nanopb dependencies
25 #include <nanopb/pb_common.h>
26 #include <nanopb/pb_decode.h>
27 #include <nanopb/pb_encode.h>
28 #include <pb.h>
29 
30 #include <wippersnapper/description/v1/description.pb.h> // description.proto
31 #include <wippersnapper/signal/v1/signal.pb.h> // signal.proto
32 
33 // External libraries
34 #include "Adafruit_MQTT.h" // MQTT Client
35 #include "Adafruit_SleepyDog.h" // Watchdog
36 #include "Arduino.h" // Wiring
37 #include <SPI.h> // SPI
38 
39 // Wippersnapper API Helpers
40 #include "Wippersnapper_Boards.h"
42 #include "provisioning/ConfigJson.h"
43 
44 #define WS_DEBUG
45 #define WS_PRINTER Serial
46 
47 // Define actual debug output functions when necessary.
48 #ifdef WS_DEBUG
49 #define WS_DEBUG_PRINT(...) \
50  { WS_PRINTER.print(__VA_ARGS__); }
51 #define WS_DEBUG_PRINTLN(...) \
52  { WS_PRINTER.println(__VA_ARGS__); }
53 #define WS_DEBUG_PRINTHEX(...) \
54  { WS_PRINTER.print(__VA_ARGS__, HEX); }
55 #else
56 #define WS_DEBUG_PRINT(...) \
57  {}
58 #define WS_DEBUG_PRINTLN(...) \
59  {}
60 #endif
61 
62 #define WS_DELAY_WITH_WDT(timeout) \
63  { \
64  unsigned long start = millis(); \
65  while (millis() - start < timeout) { \
66  delay(10); \
67  yield(); \
68  feedWDT(); \
69  if (millis() < start) { \
70  start = millis(); /* if rollover */ \
71  } \
72  } \
73  }
74 
75 /**************************************************************************/
93 /**************************************************************************/
94 #define RETRY_FUNCTION_UNTIL_TIMEOUT(func, result_type, result_var, condition, \
95  timeout, interval, ...) \
96  { \
97  unsigned long startTime = millis(); \
98  while (millis() - startTime < timeout) { \
99  result_type result_var = func(__VA_ARGS__); \
100  if (condition(result_var)) { \
101  break; \
102  } \
103  if (startTime > millis()) { \
104  startTime = millis(); /* if rollover */ \
105  } \
106  WS_DELAY_WITH_WDT(interval); \
107  } \
108  }
109 
110 // Wippersnapper pb helpers
111 #include <nanopb/ws_pb_helpers.h>
112 
113 // Wippersnapper components
117 
118 // Includes for ESP32-only
119 #ifdef ARDUINO_ARCH_ESP32
120 #include "components/ledc/ws_ledc.h"
121 #include <Esp.h>
122 #endif
123 
124 // Display
125 #ifdef USE_DISPLAY
128 #endif
129 
132 #include "components/pwm/ws_pwm.h"
134 #include "components/uart/ws_uart.h"
135 
136 #if defined(USE_TINYUSB)
137 #include "provisioning/tinyusb/Wippersnapper_FS.h"
138 #endif
139 
140 #if defined(USE_LITTLEFS)
141 #include "provisioning/littlefs/WipperSnapper_LittleFS.h"
142 #endif
143 
144 #define WS_VERSION \
145  "1.0.0-beta.95"
146 
147 // Reserved Adafruit IO MQTT topics
148 #define TOPIC_IO_THROTTLE "/throttle"
149 #define TOPIC_IO_ERRORS "/errors"
150 
151 // Reserved Wippersnapper topics
152 #define TOPIC_WS "/wprsnpr/"
153 #define TOPIC_INFO "/info/"
154 #define TOPIC_SIGNALS "/signals/"
155 #define TOPIC_I2C "/i2c"
156 #define MQTT_TOPIC_PIXELS_DEVICE \
157  "/signals/device/pixel"
158 #define MQTT_TOPIC_PIXELS_BROKER \
159  "/signals/broker/pixel"
160 
161 
162 typedef enum {
163  WS_IDLE = 0, // Waiting for connection establishement
164  WS_NET_DISCONNECTED = 1, // Network disconnected
165  WS_DISCONNECTED = 2, // Disconnected from Adafruit IO
166  WS_FINGERPRINT_UNKOWN = 3, // Unknown WS_SSL_FINGERPRINT
167 
168  WS_NET_CONNECT_FAILED = 10, // Failed to connect to network
169  WS_CONNECT_FAILED = 11, // Failed to connect to Adafruit IO
170  WS_FINGERPRINT_INVALID = 12, // Unknown WS_SSL_FINGERPRINT
171  WS_AUTH_FAILED = 13, // Invalid Adafruit IO login credentials provided.
172  WS_SSID_INVALID =
173  14, // SSID is "" or otherwise invalid, connection not attempted
174 
175  WS_NET_CONNECTED = 20, // Connected to Adafruit IO
176  WS_CONNECTED = 21, // Connected to network
177  WS_CONNECTED_INSECURE = 22, // Insecurely (non-SSL) connected to network
178  WS_FINGERPRINT_UNSUPPORTED = 23, // Unsupported WS_SSL_FINGERPRINT
179  WS_FINGERPRINT_VALID = 24, // Valid WS_SSL_FINGERPRINT
180  WS_BOARD_DESC_INVALID = 25, // Unable to send board description
181  WS_BOARD_RESYNC_FAILED = 26 // Board sync failure
185 typedef enum {
186  WS_MQTT_CONNECTED = 0, // Connected
187  WS_MQTT_INVALID_PROTOCOL = 1, // Invalid mqtt protocol
188  WS_MQTT_INVALID_CID = 2, // Client id rejected
189  WS_MQTT_SERVICE_UNAVALIABLE = 3, // Malformed user/pass
190  WS_MQTT_INVALID_USER_PASS = 4, // Unauthorized access to resource
191  WS_MQTT_UNAUTHORIZED = 5, // MQTT service unavailable
192  WS_MQTT_THROTTLED = 6, // Account throttled
193  WS_MQTT_BANNED = 7 // Account banned
195 
197 typedef enum {
198  WS_BOARD_DEF_IDLE,
199  WS_BOARD_DEF_SEND_FAILED,
200  WS_BOARD_DEF_SENT,
201  WS_BOARD_DEF_OK,
202  WS_BOARD_DEF_INVALID,
203  WS_BOARD_DEF_UNSPECIFIED
205 
207 typedef enum {
208  FSM_NET_IDLE,
209  FSM_NET_CONNECTED,
210  FSM_MQTT_CONNECTED,
211  FSM_NET_CHECK_MQTT,
212  FSM_NET_CHECK_NETWORK,
213  FSM_NET_ESTABLISH_NETWORK,
214  FSM_NET_ESTABLISH_MQTT,
215 } fsm_net_t;
216 
217 #ifdef ARDUINO_ARCH_RP2040
218 #define WS_WDT_TIMEOUT 8388
219 #else
220 #define WS_WDT_TIMEOUT 60000
221 #endif
222 
223 #define WS_MAX_ALT_WIFI_NETWORKS 3
224 /* MQTT Configuration */
225 #define WS_KEEPALIVE_INTERVAL_MS \
226  5000
227 
228 #define WS_MQTT_MAX_PAYLOAD_SIZE \
229  512
230 
233 class Wippersnapper_FS;
234 class WipperSnapper_LittleFS;
235 #ifdef USE_DISPLAY
236 class ws_display_driver;
238 #endif
239 #ifdef ARDUINO_ARCH_ESP32
240 class ws_ledc;
241 #endif
243 class ws_servo;
244 class ws_pwm;
245 class ws_ds18x20;
246 class ws_pixels;
247 class ws_uart;
249 /**************************************************************************/
254 /**************************************************************************/
255 class Wippersnapper {
256 public:
257  Wippersnapper();
258  virtual ~Wippersnapper();
259 
260  void provision();
261 
262  bool lockStatusNeoPixel;
263  bool lockStatusDotStar;
264  bool lockStatusLED;
267 
269  virtual void set_user_key();
270  virtual void set_ssid_pass(const char *ssid, const char *ssidPassword);
271  virtual void set_ssid_pass();
272  virtual bool check_valid_ssid();
273 
274  virtual void _connect();
275  virtual void _disconnect();
276  void connect();
277  void disconnect();
278 
279  virtual void getMacAddr();
280  virtual int32_t getRSSI();
281  virtual void setupMQTTClient(const char *clientID);
282 
285 
286  bool generateDeviceUID();
287  bool generateWSTopics();
288  bool generateWSErrorTopics();
289 
290  // Registration API
293  void decodeRegistrationResp(char *data, uint16_t len);
294  void pollRegistrationResp();
295  // Configuration API
297 
298  // run() loop
299  ws_status_t run();
300  void processPackets();
301  void publish(const char *topic, uint8_t *payload, uint16_t bLen,
302  uint8_t qos = 0);
303 
304  // Networking helpers
305  void pingBroker();
306  void runNetFSM();
307 
308  // WDT helpers
309  void enableWDT(int timeoutMS = 0);
310  void feedWDT();
311 
312  // Error handling helpers
313  void haltError(String error,
314  ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME,
315  uint8_t seconds_until_reboot = 25);
316  void errorWriteHang(String error);
317 
318  // MQTT topic callbacks //
319  // Decodes a signal message
320  bool decodeSignalMsg(
321  wippersnapper_signal_v1_CreateSignalRequest *encodedSignalMsg);
322 
323  // Encodes a pin event message
324  bool
325  encodePinEvent(wippersnapper_signal_v1_CreateSignalRequest *outgoingSignalMsg,
326  uint8_t pinName, int pinVal);
327 
328  // Pin configure message
329  bool configureDigitalPinReq(wippersnapper_pin_v1_ConfigurePinRequest *pinMsg);
330  bool configAnalogInPinReq(wippersnapper_pin_v1_ConfigurePinRequest *pinMsg);
331 
332  // I2C
333  std::vector<WipperSnapper_Component_I2C *>
334  i2cComponents;
336  NULL;
338  NULL;
339  bool _isI2CPort0Init =
340  false;
341  bool _isI2CPort1Init =
342  false;
343 
346  uint8_t
349  uint16_t bufSize;
352  WS_BOARD_DEF_IDLE;
353 
354  // TODO: We really should look at making these static definitions, not dynamic
355  // to free up space on the heap
358  Wippersnapper_FS *_fileSystem;
359  WipperSnapper_LittleFS
360  *_littleFS;
361 #ifdef USE_DISPLAY
364  nullptr;
365 #endif
371 
372  // TODO: does this really need to be global?
373  uint8_t _macAddr[6];
374  char sUID[13];
375  const char *_boardId;
376  Adafruit_MQTT *_mqtt;
378  secretsConfig _config;
379  networkConfig _multiNetworks[3];
380  bool _isWiFiMulti = false;
382  // TODO: Does this need to be within this class?
383  int32_t totalDigitalPins;
385  char *_topic_description = NULL;
386  char *_topic_signal_device = NULL;
387  char *_topic_signal_i2c_brkr = NULL;
389  char *_topic_signal_i2c_device = NULL;
393  char *_topic_signal_servo_device = NULL;
396  NULL;
398  NULL;
399  char *_topic_signal_ds18_brkr = NULL;
405  char *_topic_signal_uart_brkr = NULL;
408  wippersnapper_signal_v1_CreateSignalRequest
410  wippersnapper_signal_v1_I2CRequest msgSignalI2C =
411  wippersnapper_signal_v1_I2CRequest_init_zero;
412 
414  // ds signal msg
415  wippersnapper_signal_v1_Ds18x20Request msgSignalDS =
416  wippersnapper_signal_v1_Ds18x20Request_init_zero;
419  // servo message
420  wippersnapper_signal_v1_ServoRequest
422  wippersnapper_signal_v1_PWMRequest msgPWM =
423  wippersnapper_signal_v1_PWMRequest_init_zero;
424 
426  // pixels signal message
427  wippersnapper_signal_v1_PixelsRequest
428  msgPixels;
430  wippersnapper_signal_v1_UARTRequest
437  bool pinCfgCompleted = false;
439 // enable LEDC if esp32
440 #ifdef ARDUINO_ARCH_ESP32
441  ws_ledc *_ledc = nullptr;
442 #endif
444 private:
445  void _init();
446 
447 protected:
448  ws_status_t _status = WS_IDLE;
449  uint32_t _last_mqtt_connect = 0;
451  uint32_t _prv_ping = 0;
453  uint32_t _prvKATBlink = 0;
456  // Device information
457  const char *_deviceId;
458  char *_device_uid;
460  // MQTT topics
462  NULL;
468  NULL;
471  char *_topic_signal_brkr = NULL;
472  char *_err_topic = NULL;
473  char *_throttle_topic = NULL;
475  Adafruit_MQTT_Subscribe *_topic_description_sub;
477  Adafruit_MQTT_Publish *_topic_signal_device_pub;
479  Adafruit_MQTT_Subscribe *_topic_signal_brkr_sub;
481  Adafruit_MQTT_Subscribe
483  Adafruit_MQTT_Subscribe
485  Adafruit_MQTT_Subscribe
487  Adafruit_MQTT_Subscribe
489  Adafruit_MQTT_Subscribe
491  Adafruit_MQTT_Subscribe
494  Adafruit_MQTT_Subscribe
496  Adafruit_MQTT_Subscribe
497  *_throttle_sub;
499  wippersnapper_signal_v1_CreateSignalRequest
501 };
502 extern Wippersnapper WS;
504 #endif // ADAFRUIT_WIPPERSNAPPER_H
+
Class that provides an interface with the I2C bus.
Definition: WipperSnapper_I2C.h:86
+
char * _topic_signal_pixels_brkr
Definition: Wippersnapper.h:431
+
wippersnapper_signal_v1_PWMRequest msgPWM
Definition: Wippersnapper.h:450
void disconnect()
Disconnects from Adafruit IO+ Wippersnapper.
Definition: Wippersnapper.cpp:153
-
char * _topic_signal_uart_brkr
Definition: Wippersnapper.h:427
+
char * _topic_signal_uart_brkr
Definition: Wippersnapper.h:433
virtual void setupMQTTClient(const char *clientID)
Sets up the MQTT client session.
Definition: Wippersnapper.cpp:203
-
const char * _boardId
Definition: Wippersnapper.h:397
+
const char * _boardId
Definition: Wippersnapper.h:403
ws_mqtt_status_t
Definition: Wippersnapper.h:213
-
Adafruit_MQTT_Subscribe * _throttle_sub
Definition: Wippersnapper.h:519
+
Adafruit_MQTT_Subscribe * _throttle_sub
Definition: Wippersnapper.h:525
High-level interface for the ESP32/ESP32-Sx/ESP32-Cx LED Control (LEDC) peripheral. Instead of specifying a timer or channel, this class automatically allocates a channel and associates it with a pin. Underlying esp32-hal-ledc performs timer management and handles the low-level LEDC peripheral API calls.
Definition: ws_ledc.h:37
-
bool _isI2CPort1Init
True if I2C port 1 has been initialized, False otherwise.
Definition: Wippersnapper.h:363
-
ws_ledc * _ledc
Pointer to LEDC object.
Definition: Wippersnapper.h:463
+
bool _isI2CPort1Init
True if I2C port 1 has been initialized, False otherwise.
Definition: Wippersnapper.h:369
+
ws_ledc * _ledc
Pointer to LEDC object.
Definition: Wippersnapper.h:469
bool generateWSErrorTopics()
Builds MQTT topics for handling errors returned from the Adafruit IO broker and subscribes to them...
Definition: Wippersnapper.cpp:1776
-
ws_pixels * _ws_pixelsComponent
ptr to instance of ws_pixels class
Definition: Wippersnapper.h:388
+
ws_pixels * _ws_pixelsComponent
ptr to instance of ws_pixels class
Definition: Wippersnapper.h:394
Class that provides functions for reading and interacting with digital inputs and outputs...
Definition: Wippersnapper_DigitalGPIO.h:38
-
void publish(const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos=0)
Publishes a message to the Adafruit IO MQTT broker. Handles network connectivity. ...
Definition: Wippersnapper.cpp:2637
-
char * _topic_signal_pwm_brkr
Definition: Wippersnapper.h:417
-
void processPackets()
Process all incoming packets from the Adafruit IO MQTT broker. Handles network connectivity.
Definition: Wippersnapper.cpp:2615
-
const char * _deviceId
Definition: Wippersnapper.h:479
-
char * _device_uid
Definition: Wippersnapper.h:480
+
void publish(const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos=0)
Publishes a message to the Adafruit IO MQTT broker. Handles network connectivity. ...
Definition: Wippersnapper.cpp:2656
+
char * _topic_signal_pwm_brkr
Definition: Wippersnapper.h:423
+
void processPackets()
Process all incoming packets from the Adafruit IO MQTT broker. Handles network connectivity.
Definition: Wippersnapper.cpp:2634
+
const char * _deviceId
Definition: Wippersnapper.h:485
+
char * _device_uid
Definition: Wippersnapper.h:486
virtual ~Wippersnapper()
Wippersnapper destructor.
Definition: Wippersnapper.cpp:79
ws_led_status_t
Definition: Wippersnapper_StatusLED.h:34
-
#define WS_MQTT_MAX_PAYLOAD_SIZE
MAXIMUM expected payload size, in bytes.
Definition: Wippersnapper.h:251
-
void connect()
Connects to Adafruit IO+ Wippersnapper broker.
Definition: Wippersnapper.cpp:2745
+
#define WS_MQTT_MAX_PAYLOAD_SIZE
MAXIMUM expected payload size, in bytes.
Definition: Wippersnapper.h:256
+
void connect()
Connects to Adafruit IO+ Wippersnapper broker.
Definition: Wippersnapper.cpp:2764
bool encodePinEvent(wippersnapper_signal_v1_CreateSignalRequest *outgoingSignalMsg, uint8_t pinName, int pinVal)
Handles MQTT messages on signal topic until timeout.
Definition: Wippersnapper.cpp:1646
-
char * _topic_description_status
Definition: Wippersnapper.h:483
+
char * _topic_description_status
Definition: Wippersnapper.h:489
bool generateWSTopics()
Generates device-specific Wippersnapper control topics and subscribes to them.
Definition: Wippersnapper.cpp:1875
Class that provides an interface for reading and controlling analog pins. Stores information about an...
Definition: Wippersnapper_AnalogIO.h:43
-
WipperSnapper_LittleFS * _littleFS
Instance of LittleFS Filesystem (non-native USB)
Definition: Wippersnapper.h:382
-
float status_pixel_brightness
Definition: Wippersnapper.h:288
-
uint8_t _buffer_outgoing[WS_MQTT_MAX_PAYLOAD_SIZE]
Definition: Wippersnapper.h:369
+
WipperSnapper_LittleFS * _littleFS
Instance of LittleFS Filesystem (non-native USB)
Definition: Wippersnapper.h:388
+
float status_pixel_brightness
Definition: Wippersnapper.h:293
+
uint8_t _buffer_outgoing[WS_MQTT_MAX_PAYLOAD_SIZE]
Definition: Wippersnapper.h:375
void errorWriteHang(String error)
Writes an error message to the serial and the filesystem, blinks WS_LED_STATUS_ERROR_RUNTIME pattern ...
Definition: Wippersnapper.cpp:2334
-
Adafruit_MQTT_Subscribe * _topic_signal_ds18_sub
Definition: Wippersnapper.h:510
+
Adafruit_MQTT_Subscribe * _topic_signal_ds18_sub
Definition: Wippersnapper.h:516
bool decodeSignalMsg(wippersnapper_signal_v1_CreateSignalRequest *encodedSignalMsg)
Decodes a signal buffer protobuf message. NOTE: Should be executed in-order after a new _buffer is re...
Definition: Wippersnapper.cpp:500
void provision()
Provisions a WipperSnapper device with its network configuration and Adafruit IO credentials.
Definition: Wippersnapper.cpp:94
-
Adafruit_MQTT_Subscribe * _topic_signal_i2c_sub
Definition: Wippersnapper.h:504
-
char * _topic_signal_device
Definition: Wippersnapper.h:408
-
uint8_t _buffer[WS_MQTT_MAX_PAYLOAD_SIZE]
Definition: Wippersnapper.h:366
-
secretsConfig _config
Definition: Wippersnapper.h:400
-
uint32_t _last_mqtt_connect
Definition: Wippersnapper.h:471
+
Adafruit_MQTT_Subscribe * _topic_signal_i2c_sub
Definition: Wippersnapper.h:510
+
char * _topic_signal_device
Definition: Wippersnapper.h:414
+
uint8_t _buffer[WS_MQTT_MAX_PAYLOAD_SIZE]
Definition: Wippersnapper.h:372
+
secretsConfig _config
Definition: Wippersnapper.h:406
+
uint32_t _last_mqtt_connect
Definition: Wippersnapper.h:477
-
char * _topic_signal_i2c_device
Definition: Wippersnapper.h:411
-
char * _topic_signal_pixels_device
Definition: Wippersnapper.h:426
-
ws_display_ui_helper * _ui_helper
Instance of display UI helper class.
Definition: Wippersnapper.h:385
-
wippersnapper_signal_v1_I2CRequest msgSignalI2C
Definition: Wippersnapper.h:432
-
Wippersnapper_DigitalGPIO * _digitalGPIO
Instance of digital gpio class.
Definition: Wippersnapper.h:378
+
char * _topic_signal_i2c_device
Definition: Wippersnapper.h:417
+
char * _topic_signal_pixels_device
Definition: Wippersnapper.h:432
+
ws_display_ui_helper * _ui_helper
Instance of display UI helper class.
Definition: Wippersnapper.h:391
+
wippersnapper_signal_v1_I2CRequest msgSignalI2C
Definition: Wippersnapper.h:438
+
Wippersnapper_DigitalGPIO * _digitalGPIO
Instance of digital gpio class.
Definition: Wippersnapper.h:384
ws_status_t
Definition: Wippersnapper.h:190
-
WipperSnapper_Component_I2C * _i2cPort1
WipperSnapper I2C Component for I2C port #1.
Definition: Wippersnapper.h:359
-
wippersnapper_signal_v1_CreateSignalRequest _incomingSignalMsg
Definition: Wippersnapper.h:431
+
WipperSnapper_Component_I2C * _i2cPort1
WipperSnapper I2C Component for I2C port #1.
Definition: Wippersnapper.h:365
+
wippersnapper_signal_v1_CreateSignalRequest _incomingSignalMsg
Definition: Wippersnapper.h:437
virtual bool check_valid_ssid()
Performs a scan of local WiFi networks.
Definition: Wippersnapper.cpp:248
-
Class that provides storage and functions for the Adafruit IO Wippersnapper interface.
Definition: Wippersnapper.h:278
+
Class that provides storage and functions for the Adafruit IO Wippersnapper interface.
Definition: Wippersnapper.h:283
Interface for WipperSnapper servo control.
Definition: ws_servo.h:61
bool configureDigitalPinReq(wippersnapper_pin_v1_ConfigurePinRequest *pinMsg)
Configures a pin according to a wippersnapper_pin_v1_ConfigurePinRequest message. ...
Definition: Wippersnapper.cpp:326
friend class
Definition: ws_pixels.h:49
-
ws_status_t run()
Processes incoming commands and handles network connection.
Definition: Wippersnapper.cpp:2856
+
ws_status_t run()
Processes incoming commands and handles network connection.
Definition: Wippersnapper.cpp:2874
virtual void _connect()
Connects to wireless network.
Definition: Wippersnapper.cpp:162
-
wippersnapper_signal_v1_CreateSignalRequest _outgoingSignalMsg
Definition: Wippersnapper.h:522
-
char * _topic_signal_pwm_device
Definition: Wippersnapper.h:419
+
wippersnapper_signal_v1_CreateSignalRequest _outgoingSignalMsg
Definition: Wippersnapper.h:528
+
char * _topic_signal_pwm_device
Definition: Wippersnapper.h:425
bool encodePubRegistrationReq()
Encodes hardware registration request message and publishes the message to the Adafruit IO broker...
Definition: Wippersnapper_Register.cpp:27
-
char * throttleMessage
Definition: Wippersnapper.h:455
-
uint32_t _prv_ping
Definition: Wippersnapper.h:473
+
char * throttleMessage
Definition: Wippersnapper.h:461
+
uint32_t _prv_ping
Definition: Wippersnapper.h:479
virtual void getMacAddr()
Sets the network interface&#39;s unique identifer, typically the MAC address.
Definition: Wippersnapper.cpp:181
bool generateDeviceUID()
Attempts to generate unique device identifier.
Definition: Wippersnapper.cpp:1834
-
Adafruit_MQTT_Subscribe * _topic_description_sub
Definition: Wippersnapper.h:497
-
char sUID[13]
Definition: Wippersnapper.h:396
+
Adafruit_MQTT_Subscribe * _topic_description_sub
Definition: Wippersnapper.h:503
+
char sUID[13]
Definition: Wippersnapper.h:402
Wippersnapper WS
Global member variable for callbacks.
Definition: Wippersnapper.cpp:36
virtual void set_ssid_pass()
Sets the device&#39;s wireless network credentials from the secrets.json configuration file...
Definition: Wippersnapper.cpp:238
-
char * _err_topic
Definition: Wippersnapper.h:494
-
void feedWDT()
Feeds the WDT to prevent hardware reset.
Definition: Wippersnapper.cpp:2589
-
uint32_t _prvKATBlink
Definition: Wippersnapper.h:475
-
char * _topic_signal_servo_device
Definition: Wippersnapper.h:415
+
char * _err_topic
Definition: Wippersnapper.h:500
+
void feedWDT()
Feeds the WDT to prevent hardware reset.
Definition: Wippersnapper.cpp:2608
+
uint32_t _prvKATBlink
Definition: Wippersnapper.h:481
+
char * _topic_signal_servo_device
Definition: Wippersnapper.h:421
Display driver for LVGL and LVGL_Glue in WipperSnapper.
Definition: ws_display_driver.h:33
-
bool _isWiFiMulti
Definition: Wippersnapper.h:402
-
Adafruit_MQTT_Subscribe * _topic_signal_pixels_sub
Definition: Wippersnapper.h:512
+
bool _isWiFiMulti
Definition: Wippersnapper.h:408
+
Adafruit_MQTT_Subscribe * _topic_signal_pixels_sub
Definition: Wippersnapper.h:518
-
ws_ds18x20 * _ds18x20Component
Instance of DS18x20 class.
Definition: Wippersnapper.h:391
-
ws_board_status_t _boardStatus
Hardware&#39;s registration status.
Definition: Wippersnapper.h:373
-
wippersnapper_signal_v1_UARTRequest msgSignalUART
UARTReq wrapper message.
Definition: Wippersnapper.h:453
+
ws_ds18x20 * _ds18x20Component
Instance of DS18x20 class.
Definition: Wippersnapper.h:397
+
ws_board_status_t _boardStatus
Hardware&#39;s registration status.
Definition: Wippersnapper.h:379
+
wippersnapper_signal_v1_UARTRequest msgSignalUART
UARTReq wrapper message.
Definition: Wippersnapper.h:459
void runNetFSM()
Checks network and MQTT connectivity. Handles network re-connection and mqtt re-establishment.
Definition: Wippersnapper.cpp:2358
-
networkConfig _multiNetworks[3]
Definition: Wippersnapper.h:401
-
bool pinCfgCompleted
Definition: Wippersnapper.h:459
-
char * _topic_signal_uart_device
Definition: Wippersnapper.h:428
-
void pingBroker()
Pings the MQTT broker within the keepalive interval to keep the connection alive. Blinks the keepaliv...
Definition: Wippersnapper.cpp:2557
-
wippersnapper_signal_v1_Ds18x20Request msgSignalDS
Definition: Wippersnapper.h:437
+
networkConfig _multiNetworks[3]
Definition: Wippersnapper.h:407
+
bool pinCfgCompleted
Definition: Wippersnapper.h:465
+
void haltError(String error, ws_led_status_t ledStatusColor=WS_LED_STATUS_ERROR_RUNTIME, uint8_t seconds_until_reboot=25)
Prints an error to the serial and halts the hardware until the WDT bites.
Definition: Wippersnapper.cpp:2504
+
char * _topic_signal_uart_device
Definition: Wippersnapper.h:434
+
void pingBroker()
Pings the MQTT broker within the keepalive interval to keep the connection alive. Blinks the keepaliv...
Definition: Wippersnapper.cpp:2576
+
wippersnapper_signal_v1_Ds18x20Request msgSignalDS
Definition: Wippersnapper.h:443
-
ws_display_driver * _display
Instance of display driver class.
Definition: Wippersnapper.h:384
-
wippersnapper_signal_v1_PixelsRequest msgPixels
PixelsRequest wrapper message.
Definition: Wippersnapper.h:450
-
void enableWDT(int timeoutMS=0)
Enables the watchdog timer.
Definition: Wippersnapper.cpp:2599
-
Adafruit_MQTT_Subscribe * _topic_signal_pwm_sub
Definition: Wippersnapper.h:508
+
ws_display_driver * _display
Instance of display driver class.
Definition: Wippersnapper.h:390
+
wippersnapper_signal_v1_PixelsRequest msgPixels
PixelsRequest wrapper message.
Definition: Wippersnapper.h:456
+
void enableWDT(int timeoutMS=0)
Enables the watchdog timer.
Definition: Wippersnapper.cpp:2618
+
Adafruit_MQTT_Subscribe * _topic_signal_pwm_sub
Definition: Wippersnapper.h:514
Class that provides an interface with DS18X20-compatible sensors.
Definition: ws_ds18x20.h:48
-
char * _topic_signal_ds18_brkr
Definition: Wippersnapper.h:421
-
void publishPinConfigComplete()
Publishes an ACK to the broker that the device has completed its hardware configuration.
Definition: Wippersnapper.cpp:2822
-
std::vector< WipperSnapper_Component_I2C * > i2cComponents
Vector containing all I2C components.
Definition: Wippersnapper.h:356
+
char * _topic_signal_ds18_brkr
Definition: Wippersnapper.h:427
+
void publishPinConfigComplete()
Publishes an ACK to the broker that the device has completed its hardware configuration.
Definition: Wippersnapper.cpp:2840
+
std::vector< WipperSnapper_Component_I2C * > i2cComponents
Vector containing all I2C components.
Definition: Wippersnapper.h:362
Helps build and manage the LVGL objects and screens for the application code.
Definition: ws_display_ui_helper.h:63
-
uint16_t bufSize
Definition: Wippersnapper.h:371
-
char * _topic_signal_i2c_brkr
Definition: Wippersnapper.h:409
-
Adafruit_MQTT_Subscribe * _topic_signal_brkr_sub
Definition: Wippersnapper.h:501
-
char * _topic_signal_brkr
Definition: Wippersnapper.h:493
-
int32_t totalDigitalPins
Definition: Wippersnapper.h:405
+
uint16_t bufSize
Definition: Wippersnapper.h:377
+
char * _topic_signal_i2c_brkr
Definition: Wippersnapper.h:415
+
Adafruit_MQTT_Subscribe * _topic_signal_brkr_sub
Definition: Wippersnapper.h:507
+
char * _topic_signal_brkr
Definition: Wippersnapper.h:499
+
int32_t totalDigitalPins
Definition: Wippersnapper.h:411
Interface for WipperSnapper PWM.
Definition: ws_pwm.h:34
-
ws_status_t _status
Definition: Wippersnapper.h:470
+
ws_status_t _status
Definition: Wippersnapper.h:476
ws_board_status_t
Definition: Wippersnapper.h:225
-
uint8_t _macAddr[6]
Definition: Wippersnapper.h:395
-
ws_pwm * _pwmComponent
Instance of pwm class.
Definition: Wippersnapper.h:389
+
uint8_t _macAddr[6]
Definition: Wippersnapper.h:401
+
ws_pwm * _pwmComponent
Instance of pwm class.
Definition: Wippersnapper.h:395
fsm_net_t
Definition: Wippersnapper.h:235
-
bool lockStatusLED
True if status LED is using the built-in LED.
Definition: Wippersnapper.h:287
-
Wippersnapper_FS * _fileSystem
Instance of Filesystem (native USB)
Definition: Wippersnapper.h:380
-
Adafruit_MQTT_Subscribe * _topic_signal_uart_sub
Definition: Wippersnapper.h:514
-
Adafruit_MQTT * _mqtt
Definition: Wippersnapper.h:398
+
bool lockStatusLED
True if status LED is using the built-in LED.
Definition: Wippersnapper.h:292
+
Wippersnapper_FS * _fileSystem
Instance of Filesystem (native USB)
Definition: Wippersnapper.h:386
+
Adafruit_MQTT_Subscribe * _topic_signal_uart_sub
Definition: Wippersnapper.h:520
+
Adafruit_MQTT * _mqtt
Definition: Wippersnapper.h:404
#define STATUS_PIXEL_BRIGHTNESS_DEFAULT
Default status pixel brightness.
Definition: Wippersnapper_StatusLED.h:59
virtual ws_status_t networkStatus()
Returns the network&#39;s connection status.
Definition: Wippersnapper.cpp:213
-
char * _topic_device_pin_config_complete
Definition: Wippersnapper.h:489
-
char * _topic_signal_servo_brkr
Definition: Wippersnapper.h:413
-
Wippersnapper_AnalogIO * _analogIO
Instance of analog io class.
Definition: Wippersnapper.h:379
-
char * _topic_description_status_complete
Definition: Wippersnapper.h:486
+
char * _topic_device_pin_config_complete
Definition: Wippersnapper.h:495
+
char * _topic_signal_servo_brkr
Definition: Wippersnapper.h:419
+
Wippersnapper_AnalogIO * _analogIO
Instance of analog io class.
Definition: Wippersnapper.h:385
+
char * _topic_description_status_complete
Definition: Wippersnapper.h:492
void pollRegistrationResp()
Polls the broker for the hardware registration response message.
Definition: Wippersnapper_Register.cpp:78
-
ws_board_status_t getBoardStatus()
Returns the board definition status.
Definition: Wippersnapper.cpp:2548
+
ws_board_status_t getBoardStatus()
Returns the board definition status.
Definition: Wippersnapper.cpp:2567
bool configAnalogInPinReq(wippersnapper_pin_v1_ConfigurePinRequest *pinMsg)
Configures an analog input pin according to a wippersnapper_pin_v1_ConfigurePinRequest message...
Definition: Wippersnapper.cpp:275
-
bool lockStatusDotStar
True if status LED is using the status dotstar.
Definition: Wippersnapper.h:286
-
wippersnapper_signal_v1_ServoRequest msgServo
ServoRequest wrapper message.
Definition: Wippersnapper.h:443
-
char * _throttle_topic
Definition: Wippersnapper.h:495
+
bool lockStatusDotStar
True if status LED is using the status dotstar.
Definition: Wippersnapper.h:291
+
wippersnapper_signal_v1_ServoRequest msgServo
ServoRequest wrapper message.
Definition: Wippersnapper.h:449
+
char * _throttle_topic
Definition: Wippersnapper.h:501
void decodeRegistrationResp(char *data, uint16_t len)
Decodes hardware registration response message from the Adafruit IO MQTT broker and initializes hardw...
Definition: Wippersnapper_Register.cpp:98
-
bool lockStatusNeoPixel
True if status LED is using the status neopixel.
Definition: Wippersnapper.h:285
-
Adafruit_MQTT_Subscribe * _topic_signal_servo_sub
Definition: Wippersnapper.h:506
-
WipperSnapper_Component_I2C * _i2cPort0
WipperSnapper I2C Component for I2C port #0.
Definition: Wippersnapper.h:357
-
bool registerBoard()
Attempts to register hardware with Adafruit.io WipperSnapper.
Definition: Wippersnapper.cpp:2524
-
int throttleTime
Definition: Wippersnapper.h:456
-
Adafruit_MQTT_Subscribe * _err_sub
Definition: Wippersnapper.h:517
-
void haltError(String error, ws_led_status_t ledStatusColor=WS_LED_STATUS_ERROR_RUNTIME)
Prints an error to the serial and halts the hardware until the WDT bites.
Definition: Wippersnapper.cpp:2502
-
char * _topic_signal_ds18_device
Definition: Wippersnapper.h:423
+
bool lockStatusNeoPixel
True if status LED is using the status neopixel.
Definition: Wippersnapper.h:290
+
Adafruit_MQTT_Subscribe * _topic_signal_servo_sub
Definition: Wippersnapper.h:512
+
WipperSnapper_Component_I2C * _i2cPort0
WipperSnapper I2C Component for I2C port #0.
Definition: Wippersnapper.h:363
+
bool registerBoard()
Attempts to register hardware with Adafruit.io WipperSnapper.
Definition: Wippersnapper.cpp:2543
+
int throttleTime
Definition: Wippersnapper.h:462
+
Adafruit_MQTT_Subscribe * _err_sub
Definition: Wippersnapper.h:523
+
char * _topic_signal_ds18_device
Definition: Wippersnapper.h:429
-
bool _isI2CPort0Init
True if I2C port 0 has been initialized, False otherwise.
Definition: Wippersnapper.h:361
+
bool _isI2CPort0Init
True if I2C port 0 has been initialized, False otherwise.
Definition: Wippersnapper.h:367
virtual int32_t getRSSI()
Gets the network&#39;s RSSI.
Definition: Wippersnapper.cpp:191
virtual void _disconnect()
Disconnect Wippersnapper MQTT session and network.
Definition: Wippersnapper.cpp:171
-
ws_servo * _servoComponent
Instance of servo class.
Definition: Wippersnapper.h:390
+
ws_servo * _servoComponent
Instance of servo class.
Definition: Wippersnapper.h:396
-
Adafruit_MQTT_Publish * _topic_signal_device_pub
Definition: Wippersnapper.h:499
-
ws_uart * _uartComponent
Instance of UART class.
Definition: Wippersnapper.h:392
-
char * _topic_description
Definition: Wippersnapper.h:407
+
Adafruit_MQTT_Publish * _topic_signal_device_pub
Definition: Wippersnapper.h:505
+
ws_uart * _uartComponent
Instance of UART class.
Definition: Wippersnapper.h:398
+
char * _topic_description
Definition: Wippersnapper.h:413
Class that provides an interface between WipperSnapper&#39;s app and the device&#39;s UART bus...
Definition: ws_uart.h:29
virtual void set_user_key()
Configures the device&#39;s Adafruit IO credentials. This method should be used only if filesystem-backed...
Definition: Wippersnapper.cpp:260
diff --git a/html/_wippersnapper___a_i_r_l_i_f_t_8h_source.html b/html/_wippersnapper___a_i_r_l_i_f_t_8h_source.html index 4c125db21..ad37d9731 100644 --- a/html/_wippersnapper___a_i_r_l_i_f_t_8h_source.html +++ b/html/_wippersnapper___a_i_r_l_i_f_t_8h_source.html @@ -66,51 +66,53 @@
Wippersnapper_AIRLIFT.h
-Go to the documentation of this file.
1 
20 #ifndef WIPPERSNAPPER_AIRLIFT_H
21 #define WIPPERSNAPPER_AIRLIFT_H
22 
23 #include "Adafruit_MQTT.h"
24 #include "Adafruit_MQTT_Client.h"
25 #include "Arduino.h"
26 #include "SPI.h"
27 #include "WiFiNINA.h"
28 #include "Wippersnapper.h"
29 
30 #define NINAFWVER \
31  "1.7.7"
32 #define AIRLIFT_CONNECT_TIMEOUT_MS 20000
33 #define AIRLIFT_CONNECT_RETRY_DELAY_MS 200
35 #define SPIWIFI SPI
37 extern Wippersnapper WS;
38 /****************************************************************************/
42 /****************************************************************************/
44 
45 public:
46  /**************************************************************************/
50  /**************************************************************************/
52  _ssPin = SPIWIFI_SS; // 10;
53  _ackPin = SPIWIFI_ACK; // 7;
54  _rstPin = SPIWIFI_RESET; // 5; // should be 7 on PyPortals
55 #ifdef ESP32_GPIO0
56  _gpio0Pin = ESP32_GPIO0;
57 #else
58  _gpio0Pin = -1;
59 #endif
60  _wifi = &SPIWIFI;
61  _ssid = 0;
62  _pass = 0;
63  _mqtt_client = new WiFiSSLClient;
64 
65  // setup ESP32 co-processor pins during init.
66  WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);
67  }
68 
69  /**************************************************************************/
73  /**************************************************************************/
75  if (_mqtt)
76  delete _mqtt;
77  }
78 
79  /**********************************************************/
87  /**********************************************************/
88  void set_ssid_pass(const char *ssid, const char *ssidPassword) {
89  _ssid = ssid;
90  _pass = ssidPassword;
91  }
92 
93  /**********************************************************/
98  /**********************************************************/
99  void set_ssid_pass() {
100  _ssid = WS._config.network.ssid;
101  _pass = WS._config.network.pass;
102  }
103 
104  /***********************************************************/
109  /***********************************************************/
111  // Disconnect WiFi from an AP if it was previously connected
112  WiFi.disconnect();
113  delay(100);
114 
115  // Perform a network scan
116  int n = WiFi.scanNetworks();
117  if (n == 0) {
118  WS_DEBUG_PRINTLN("ERROR: No WiFi networks found!");
119  return false;
120  }
121 
122  // Was the network within secrets.json found?
123  for (int i = 0; i < n; ++i) {
124  if (strcmp(_ssid, WiFi.SSID(i)) == 0) {
125  WS_DEBUG_PRINT("SSID found! RSSI: ");
126  WS_DEBUG_PRINTLN(WiFi.RSSI(i));
127  return true;
128  }
129  }
130 
131  // User-set network not found, print scan results to serial console
132  WS_DEBUG_PRINTLN("ERROR: Your requested WiFi network was not found!");
133  WS_DEBUG_PRINTLN("WipperSnapper found these WiFi networks: ");
134  for (int i = 0; i < n; ++i) {
135  WS_DEBUG_PRINT(WiFi.SSID(i));
136  WS_DEBUG_PRINT(" ");
137  WS_DEBUG_PRINT(WiFi.RSSI(i));
138  WS_DEBUG_PRINTLN("dB");
139  }
140 
141  return false;
142  }
143 
144  /********************************************************/
150  /********************************************************/
151  void set_wifi(SPIClass *wifi) {
152  _wifi = wifi;
153  _mqtt_client = new WiFiSSLClient;
154  }
155 
156  /********************************************************/
168  /********************************************************/
169  void set_airlift_pins(int ssPin, int ackPin, int rstPin, int gpio0Pin) {
170  _ssPin = ssPin;
171  _ackPin = ackPin;
172  _rstPin = rstPin;
173  _gpio0Pin = gpio0Pin;
174  }
175 
176  /********************************************************/
183  /********************************************************/
184  bool firmwareCheck() {
185  _fv = WiFi.firmwareVersion();
186  return compareVersions(_fv, NINAFWVER);
187  }
188 
189  /********************************************************/
199  /********************************************************/
200  bool compareVersions(const char *currentVersion,
201  const char *requiredVersion) {
202  int curMajor = 0, curMinor = 0, curPatch = 0;
203  int reqMajor = 0, reqMinor = 0, reqPatch = 0;
204 
205  if (!sscanf(currentVersion, "%d.%d.%d", &curMajor, &curMinor, &curPatch) ||
206  !sscanf(requiredVersion, "%d.%d.%d", &reqMajor, &reqMinor, &reqPatch)) {
207  WS_DEBUG_PRINTLN("Error parsing firmware version strings");
208  WS_PRINTER.flush();
209  WS_DEBUG_PRINT("Required version: ");
210  WS_DEBUG_PRINTLN(requiredVersion);
211  WS_PRINTER.flush();
212  WS_DEBUG_PRINT("Current version: ");
213  WS_DEBUG_PRINTLN(currentVersion);
214  WS_PRINTER.flush();
215  return false;
216  }
217 
218  if (curMajor != reqMajor)
219  return curMajor > reqMajor;
220  if (curMinor != reqMinor)
221  return curMinor > reqMinor;
222  return curPatch >= reqPatch;
223  }
224 
225  /********************************************************/
230  /********************************************************/
231  void getMacAddr() {
232  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
233  WiFi.macAddress(mac);
234  memcpy(WS._macAddr, mac, sizeof(mac));
235  }
236 
237  /********************************************************/
242  /********************************************************/
243  int32_t getRSSI() { return WiFi.RSSI(); }
244 
245  /********************************************************/
251  /********************************************************/
252  void setupMQTTClient(const char *clientID) {
253  WS._mqtt = new Adafruit_MQTT_Client(
254  _mqtt_client, WS._config.aio_url, WS._config.io_port, clientID,
255  WS._config.aio_user, WS._config.aio_key);
256  }
257 
258  /********************************************************/
263  /********************************************************/
265  switch (WiFi.status()) {
266  case WL_CONNECTED:
267  return WS_NET_CONNECTED;
268  case WL_CONNECT_FAILED:
269  return WS_NET_CONNECT_FAILED;
270  case WL_IDLE_STATUS:
271  return WS_IDLE;
272  default:
273  return WS_NET_DISCONNECTED;
274  }
275  }
276 
277  /*******************************************************************/
282  /*******************************************************************/
283  const char *connectionType() { return "AIRLIFT"; }
284 
285 protected:
286  const char *_ssid;
287  const char *_pass;
288  const char *_fv = "0.0.1";
289  int _ssPin = -1;
290  int _ackPin = -1;
291  int _rstPin = -1;
292  int _gpio0Pin = -1;
293  WiFiSSLClient *_mqtt_client;
294  SPIClass *_wifi;
296  /**************************************************************************/
300  /**************************************************************************/
301  void _connect() {
302  if (strlen(_ssid) == 0) {
303  _status = WS_SSID_INVALID; // possibly unneccesary as already checking
304  // elsewhere
305  } else {
306  // disconnect from possible previous connection
307  _disconnect();
308  delay(100);
309  WiFi.end();
310  _wifi->end();
311  delay(100);
312  _wifi->begin();
313  feedWDT();
314  // reset the esp32 if possible
315  resetAirLift();
316  feedWDT();
317 
318  WS_DEBUG_PRINT("ESP32 booted, version: ");
319  WS_PRINTER.flush();
320  WS_DEBUG_PRINTLN(WiFi.firmwareVersion());
321  WS_PRINTER.flush();
322  feedWDT();
323 
324  // validate co-processor's firmware version
325  if (!firmwareCheck()) {
326  WS_DEBUG_PRINTLN("Please upgrade the firmware on the ESP module to the "
327  "latest version.");
328  }
329 
330  WS_DEBUG_PRINT("Connecting to ");
331  WS_DEBUG_PRINTLN(_ssid);
332  WS_PRINTER.flush();
333  feedWDT();
334  WiFi.begin(_ssid, _pass);
335  _status = WS_NET_DISCONNECTED;
336 
337  // Use the macro to retry the status check until connected / timed out
338  int lastResult = -1;
340  []() -> int { return WiFi.status(); }, // Function call each cycle
341  int, // return type
342  lastResult, // return variable
343  [](int status) { return status == WL_CONNECTED; }, // check
344  AIRLIFT_CONNECT_TIMEOUT_MS, // timeout interval (ms)
345  AIRLIFT_CONNECT_RETRY_DELAY_MS); // interval between retries
346 
347  if (lastResult == WL_CONNECTED) {
348  _status = WS_NET_CONNECTED;
349  // wait 2seconds for connection to stabilize
350  WS_DELAY_WITH_WDT(2000);
351  } else {
352  _status = WS_NET_DISCONNECTED; // maybe connect failed instead?
353  }
354  }
355  }
356 
357  /**************************************************************************/
361  /**************************************************************************/
362  void resetAirLift() {
363  if (_rstPin != -1) {
364  WS_DEBUG_PRINTLN("Resetting ESP32...");
365  WS_PRINTER.flush();
366  // Chip select for esp32
367  pinMode(_ssPin, OUTPUT);
368  digitalWrite(_ssPin, HIGH); // Do we need to set SS low again?
369  if (_gpio0Pin != -1) {
370  pinMode(_gpio0Pin, OUTPUT);
371  digitalWrite(_gpio0Pin, LOW);
372  }
373  pinMode(_rstPin, OUTPUT);
374  digitalWrite(_rstPin, LOW);
375  delay(50);
376  digitalWrite(_rstPin, HIGH);
377  delay(10);
378  if (_gpio0Pin != -1) {
379  pinMode(_gpio0Pin, INPUT);
380  }
381  // wait for the ESP32 to boot
382  delay(2000);
383  }
384  }
385 
386  /**************************************************************************/
390  /**************************************************************************/
391  void _disconnect() {
392  WiFi.disconnect();
393  delay(500);
394  }
395 };
396 
397 #endif // WIPPERSNAPPER_AIRLIFT_H
#define RETRY_FUNCTION_UNTIL_TIMEOUT(func, result_type, result_var, condition, timeout, interval,...)
Retry a function until a condition is met or a timeout is reached.
Definition: Wippersnapper.h:108
+Go to the documentation of this file.
1 
20 #ifndef WIPPERSNAPPER_AIRLIFT_H
21 #define WIPPERSNAPPER_AIRLIFT_H
22 
23 #include "Adafruit_MQTT.h"
24 #include "Adafruit_MQTT_Client.h"
25 #include "Arduino.h"
26 #include "SPI.h"
27 #include "WiFiNINA.h"
28 #include "Wippersnapper.h"
29 
30 #define NINAFWVER \
31  "1.7.7"
32 #define AIRLIFT_CONNECT_TIMEOUT_MS 20000
33 #define AIRLIFT_CONNECT_RETRY_DELAY_MS 200
35 #define SPIWIFI SPI
37 extern Wippersnapper WS;
38 /****************************************************************************/
42 /****************************************************************************/
44 
45 public:
46  /**************************************************************************/
50  /**************************************************************************/
52  _ssPin = SPIWIFI_SS; // 10;
53  _ackPin = SPIWIFI_ACK; // 7;
54  _rstPin = SPIWIFI_RESET; // 5; // should be 7 on PyPortals
55 #ifdef ESP32_GPIO0
56  _gpio0Pin = ESP32_GPIO0;
57 #else
58  _gpio0Pin = -1;
59 #endif
60  _wifi = &SPIWIFI;
61  _ssid = 0;
62  _pass = 0;
63  _mqtt_client = new WiFiSSLClient;
64 
65  // setup ESP32 co-processor pins during init.
66  WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);
67  }
68 
69  /**************************************************************************/
73  /**************************************************************************/
75  if (_mqtt)
76  delete _mqtt;
77  }
78 
79  /**********************************************************/
87  /**********************************************************/
88  void set_ssid_pass(const char *ssid, const char *ssidPassword) {
89  _ssid = ssid;
90  _pass = ssidPassword;
91  }
92 
93  /**********************************************************/
98  /**********************************************************/
99  void set_ssid_pass() {
100  _ssid = WS._config.network.ssid;
101  _pass = WS._config.network.pass;
102  }
103 
104  /***********************************************************/
109  /***********************************************************/
111  // Disconnect WiFi from an AP if it was previously connected
112  WiFi.disconnect();
113  delay(100);
114 
115  // Perform a network scan
116  int n = WiFi.scanNetworks();
117  if (n == 0) {
118  WS_DEBUG_PRINTLN("ERROR: No WiFi networks found!");
119  return false;
120  }
121 
122  bool foundNetwork = false;
123 
124  WS_DEBUG_PRINTLN("WipperSnapper found these WiFi networks:");
125  for (uint8_t i = 0; i < n; i++) {
126  if (!foundNetwork && strcmp(WiFi.SSID(i), _ssid) == 0) {
127  foundNetwork = true;
128  }
129  WS_DEBUG_PRINT(WiFi.SSID(i));
130  WS_DEBUG_PRINT(" (");
131  uint8_t BSSID[WL_MAC_ADDR_LENGTH];
132  WiFi.BSSID(i, BSSID);
133  for (int m = 0; m < WL_MAC_ADDR_LENGTH; m++) {
134  if (m != 0)
135  WS_DEBUG_PRINT(":");
136  WS_DEBUG_PRINTHEX(BSSID[m]);
137  }
138  WS_DEBUG_PRINT(") ");
139  WS_DEBUG_PRINT(WiFi.RSSI(i));
140  WS_DEBUG_PRINT("dB (ch");
141  WS_DEBUG_PRINT(WiFi.channel(i))
142  WS_DEBUG_PRINTLN(")");
143  }
144 
145  if (!foundNetwork) {
146  WS_DEBUG_PRINTLN("ERROR: Your requested WiFi network was not found!");
147  }
148  return foundNetwork;
149  }
150 
151  /********************************************************/
157  /********************************************************/
158  void set_wifi(SPIClass *wifi) {
159  _wifi = wifi;
160  _mqtt_client = new WiFiSSLClient;
161  }
162 
163  /********************************************************/
175  /********************************************************/
176  void set_airlift_pins(int ssPin, int ackPin, int rstPin, int gpio0Pin) {
177  _ssPin = ssPin;
178  _ackPin = ackPin;
179  _rstPin = rstPin;
180  _gpio0Pin = gpio0Pin;
181  }
182 
183  /********************************************************/
190  /********************************************************/
191  bool firmwareCheck() {
192  _fv = WiFi.firmwareVersion();
193  return compareVersions(_fv, NINAFWVER);
194  }
195 
196  /********************************************************/
206  /********************************************************/
207  bool compareVersions(const char *currentVersion,
208  const char *requiredVersion) {
209  int curMajor = 0, curMinor = 0, curPatch = 0;
210  int reqMajor = 0, reqMinor = 0, reqPatch = 0;
211 
212  if (!sscanf(currentVersion, "%d.%d.%d", &curMajor, &curMinor, &curPatch) ||
213  !sscanf(requiredVersion, "%d.%d.%d", &reqMajor, &reqMinor, &reqPatch)) {
214  WS_DEBUG_PRINTLN("Error parsing firmware version strings");
215  WS_PRINTER.flush();
216  WS_DEBUG_PRINT("Required version: ");
217  WS_DEBUG_PRINTLN(requiredVersion);
218  WS_PRINTER.flush();
219  WS_DEBUG_PRINT("Current version: ");
220  WS_DEBUG_PRINTLN(currentVersion);
221  WS_PRINTER.flush();
222  return false;
223  }
224 
225  if (curMajor != reqMajor)
226  return curMajor > reqMajor;
227  if (curMinor != reqMinor)
228  return curMinor > reqMinor;
229  return curPatch >= reqPatch;
230  }
231 
232  /********************************************************/
237  /********************************************************/
238  void getMacAddr() {
239  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
240  WiFi.macAddress(mac);
241  memcpy(WS._macAddr, mac, sizeof(mac));
242  }
243 
244  /********************************************************/
249  /********************************************************/
250  int32_t getRSSI() { return WiFi.RSSI(); }
251 
252  /********************************************************/
258  /********************************************************/
259  void setupMQTTClient(const char *clientID) {
260  WS._mqtt = new Adafruit_MQTT_Client(
261  _mqtt_client, WS._config.aio_url, WS._config.io_port, clientID,
262  WS._config.aio_user, WS._config.aio_key);
263  }
264 
265  /********************************************************/
270  /********************************************************/
272  switch (WiFi.status()) {
273  case WL_CONNECTED:
274  return WS_NET_CONNECTED;
275  case WL_CONNECT_FAILED:
276  return WS_NET_CONNECT_FAILED;
277  case WL_IDLE_STATUS:
278  return WS_IDLE;
279  default:
280  return WS_NET_DISCONNECTED;
281  }
282  }
283 
284  /*******************************************************************/
289  /*******************************************************************/
290  const char *connectionType() { return "AIRLIFT"; }
291 
292 protected:
293  const char *_ssid;
294  const char *_pass;
295  const char *_fv = "0.0.1";
296  int _ssPin = -1;
297  int _ackPin = -1;
298  int _rstPin = -1;
299  int _gpio0Pin = -1;
300  WiFiSSLClient *_mqtt_client;
301  SPIClass *_wifi;
303  /**************************************************************************/
307  /**************************************************************************/
308  void _connect() {
309  if (strlen(_ssid) == 0) {
310  _status = WS_SSID_INVALID; // possibly unneccesary as already checking
311  // elsewhere
312  } else {
313  // disconnect from possible previous connection
314  _disconnect();
315  delay(100);
316  WiFi.end();
317  _wifi->end();
318  delay(100);
319  _wifi->begin();
320  feedWDT();
321  // reset the esp32 if possible
322  resetAirLift();
323  feedWDT();
324 
325  WS_DEBUG_PRINT("ESP32 booted, version: ");
326  WS_PRINTER.flush();
327  WS_DEBUG_PRINTLN(WiFi.firmwareVersion());
328  WS_PRINTER.flush();
329  feedWDT();
330 
331  // validate co-processor's firmware version
332  if (!firmwareCheck()) {
333  // TODO: see if there's a way to add to bootlog without usb reattach
334  WS_DEBUG_PRINTLN("Please upgrade the firmware on the ESP module to the "
335  "latest version.");
336  }
337 
338  WS_DEBUG_PRINT("Connecting to ");
339  WS_DEBUG_PRINTLN(_ssid);
340  WS_PRINTER.flush();
341  feedWDT();
342  WiFi.begin(_ssid, _pass);
343  _status = WS_NET_DISCONNECTED;
344 
345  // Use the macro to retry the status check until connected / timed out
346  int lastResult = -1;
348  []() -> int { return WiFi.status(); }, // Function call each cycle
349  int, // return type
350  lastResult, // return variable
351  [](int status) { return status == WL_CONNECTED; }, // check
352  AIRLIFT_CONNECT_TIMEOUT_MS, // timeout interval (ms)
353  AIRLIFT_CONNECT_RETRY_DELAY_MS); // interval between retries
354 
355  if (lastResult == WL_CONNECTED) {
356  _status = WS_NET_CONNECTED;
357  // wait 2seconds for connection to stabilize
358  WS_DELAY_WITH_WDT(2000);
359  } else {
360  _status = WS_NET_DISCONNECTED; // maybe connect failed instead?
361  }
362  }
363  }
364 
365  /**************************************************************************/
369  /**************************************************************************/
370  void resetAirLift() {
371  if (_rstPin != -1) {
372  WS_DEBUG_PRINTLN("Resetting ESP32...");
373  WS_PRINTER.flush();
374  // Chip select for esp32
375  pinMode(_ssPin, OUTPUT);
376  digitalWrite(_ssPin, HIGH); // Do we need to set SS low again?
377  if (_gpio0Pin != -1) {
378  pinMode(_gpio0Pin, OUTPUT);
379  digitalWrite(_gpio0Pin, LOW);
380  }
381  pinMode(_rstPin, OUTPUT);
382  digitalWrite(_rstPin, LOW);
383  delay(50);
384  digitalWrite(_rstPin, HIGH);
385  delay(10);
386  if (_gpio0Pin != -1) {
387  pinMode(_gpio0Pin, INPUT);
388  }
389  // wait for the ESP32 to boot
390  delay(2000);
391  }
392  }
393 
394  /**************************************************************************/
398  /**************************************************************************/
399  void _disconnect() {
400  WiFi.disconnect();
401  delay(500);
402  }
403 };
404 
405 #endif // WIPPERSNAPPER_AIRLIFT_H
#define RETRY_FUNCTION_UNTIL_TIMEOUT(func, result_type, result_var, condition, timeout, interval,...)
Retry a function until a condition is met or a timeout is reached.
Definition: Wippersnapper.h:108
#define WS_DEBUG_PRINT(...)
Prints debug output.
Definition: Wippersnapper.h:49
-
int _rstPin
Definition: Wippersnapper_AIRLIFT.h:291
-
void _disconnect()
Disconnects from the wireless network.
Definition: Wippersnapper_AIRLIFT.h:391
-
const char * _fv
Definition: Wippersnapper_AIRLIFT.h:288
-
void setupMQTTClient(const char *clientID)
Initializes the MQTT client.
Definition: Wippersnapper_AIRLIFT.h:252
-
int _ackPin
Definition: Wippersnapper_AIRLIFT.h:290
-
void set_airlift_pins(int ssPin, int ackPin, int rstPin, int gpio0Pin)
Configures ESP32 "AirLift" pins.
Definition: Wippersnapper_AIRLIFT.h:169
+
int _rstPin
Definition: Wippersnapper_AIRLIFT.h:298
+
void _disconnect()
Disconnects from the wireless network.
Definition: Wippersnapper_AIRLIFT.h:399
+
const char * _fv
Definition: Wippersnapper_AIRLIFT.h:295
+
void setupMQTTClient(const char *clientID)
Initializes the MQTT client.
Definition: Wippersnapper_AIRLIFT.h:259
+
int _ackPin
Definition: Wippersnapper_AIRLIFT.h:297
+
void set_airlift_pins(int ssPin, int ackPin, int rstPin, int gpio0Pin)
Configures ESP32 "AirLift" pins.
Definition: Wippersnapper_AIRLIFT.h:176
Class for using the AirLift Co-Processor network iface.
Definition: Wippersnapper_AIRLIFT.h:43
-
const char * connectionType()
Returns the type of network connection used by Wippersnapper.
Definition: Wippersnapper_AIRLIFT.h:283
+
const char * connectionType()
Returns the type of network connection used by Wippersnapper.
Definition: Wippersnapper_AIRLIFT.h:290
+
#define WS_DEBUG_PRINTHEX(...)
Prints debug output.
Definition: Wippersnapper.h:55
#define SPIWIFI
Definition: Wippersnapper_AIRLIFT.h:35
-
void set_wifi(SPIClass *wifi)
Sets the WiFi client.
Definition: Wippersnapper_AIRLIFT.h:151
-
const char * _pass
Definition: Wippersnapper_AIRLIFT.h:287
-
int _gpio0Pin
Definition: Wippersnapper_AIRLIFT.h:292
+
void set_wifi(SPIClass *wifi)
Sets the WiFi client.
Definition: Wippersnapper_AIRLIFT.h:158
+
const char * _pass
Definition: Wippersnapper_AIRLIFT.h:294
+
int _gpio0Pin
Definition: Wippersnapper_AIRLIFT.h:299
Wippersnapper_AIRLIFT()
Initializes the Adafruit IO class for AirLift devices.
Definition: Wippersnapper_AIRLIFT.h:51
-
secretsConfig _config
Definition: Wippersnapper.h:400
+
secretsConfig _config
Definition: Wippersnapper.h:406
#define AIRLIFT_CONNECT_RETRY_DELAY_MS
Definition: Wippersnapper_AIRLIFT.h:33
-
const char * _ssid
Definition: Wippersnapper_AIRLIFT.h:286
-
void _connect()
Establishes a connection with the wireless network.
Definition: Wippersnapper_AIRLIFT.h:301
+
#define WL_MAC_ADDR_LENGTH
MAC address length - from RP2040 BSP.
Definition: Wippersnapper_Networking.h:20
+
const char * _ssid
Definition: Wippersnapper_AIRLIFT.h:293
+
void _connect()
Establishes a connection with the wireless network.
Definition: Wippersnapper_AIRLIFT.h:308
void set_ssid_pass()
Sets the WiFi client&#39;s ssid and password from the secrets.json provisioning file. ...
Definition: Wippersnapper_AIRLIFT.h:99
ws_status_t
Definition: Wippersnapper.h:190
-
Class that provides storage and functions for the Adafruit IO Wippersnapper interface.
Definition: Wippersnapper.h:278
-
int _ssPin
Definition: Wippersnapper_AIRLIFT.h:289
+
Class that provides storage and functions for the Adafruit IO Wippersnapper interface.
Definition: Wippersnapper.h:283
+
int _ssPin
Definition: Wippersnapper_AIRLIFT.h:296
#define NINAFWVER
Definition: Wippersnapper_AIRLIFT.h:30
~Wippersnapper_AIRLIFT()
Destructor for the Adafruit IO AirLift class.
Definition: Wippersnapper_AIRLIFT.h:74
Wippersnapper WS
Definition: Wippersnapper.cpp:36
#define WS_PRINTER
Where debug messages will be printed.
Definition: Wippersnapper.h:45
#define AIRLIFT_CONNECT_TIMEOUT_MS
Definition: Wippersnapper_AIRLIFT.h:32
-
void feedWDT()
Feeds the WDT to prevent hardware reset.
Definition: Wippersnapper.cpp:2589
-
SPIClass * _wifi
Definition: Wippersnapper_AIRLIFT.h:294
+
void feedWDT()
Feeds the WDT to prevent hardware reset.
Definition: Wippersnapper.cpp:2608
+
SPIClass * _wifi
Definition: Wippersnapper_AIRLIFT.h:301
void set_ssid_pass(const char *ssid, const char *ssidPassword)
Sets the WiFi client&#39;s ssid and password.
Definition: Wippersnapper_AIRLIFT.h:88
#define WS_DEBUG_PRINTLN(...)
Prints line from debug output.
Definition: Wippersnapper.h:52
-
void resetAirLift()
Resets the ESP32 module.
Definition: Wippersnapper_AIRLIFT.h:362
+
void resetAirLift()
Resets the ESP32 module.
Definition: Wippersnapper_AIRLIFT.h:370
#define WS_DELAY_WITH_WDT(timeout)
Delay function.
Definition: Wippersnapper.h:65
-
ws_status_t networkStatus()
Returns the network status of an ESP32 module.
Definition: Wippersnapper_AIRLIFT.h:264
+
ws_status_t networkStatus()
Returns the network status of an ESP32 module.
Definition: Wippersnapper_AIRLIFT.h:271
bool check_valid_ssid()
Performs a scan of local WiFi networks.
Definition: Wippersnapper_AIRLIFT.h:110
-
ws_status_t _status
Definition: Wippersnapper.h:470
-
uint8_t _macAddr[6]
Definition: Wippersnapper.h:395
-
bool compareVersions(const char *currentVersion, const char *requiredVersion)
Compares two version strings.
Definition: Wippersnapper_AIRLIFT.h:200
-
Adafruit_MQTT * _mqtt
Definition: Wippersnapper.h:398
-
int32_t getRSSI()
Gets the current network RSSI value.
Definition: Wippersnapper_AIRLIFT.h:243
-
bool firmwareCheck()
Checks the version of an ESP32 module running nina-fw.
Definition: Wippersnapper_AIRLIFT.h:184
-
void getMacAddr()
Gets the ESP32&#39;s unique client identifier.
Definition: Wippersnapper_AIRLIFT.h:231
-
WiFiSSLClient * _mqtt_client
Definition: Wippersnapper_AIRLIFT.h:293
+
ws_status_t _status
Definition: Wippersnapper.h:476
+
uint8_t _macAddr[6]
Definition: Wippersnapper.h:401
+
bool compareVersions(const char *currentVersion, const char *requiredVersion)
Compares two version strings.
Definition: Wippersnapper_AIRLIFT.h:207
+
Adafruit_MQTT * _mqtt
Definition: Wippersnapper.h:404
+
int32_t getRSSI()
Gets the current network RSSI value.
Definition: Wippersnapper_AIRLIFT.h:250
+
bool firmwareCheck()
Checks the version of an ESP32 module running nina-fw.
Definition: Wippersnapper_AIRLIFT.h:191
+
void getMacAddr()
Gets the ESP32&#39;s unique client identifier.
Definition: Wippersnapper_AIRLIFT.h:238
+
WiFiSSLClient * _mqtt_client
Definition: Wippersnapper_AIRLIFT.h:300
+
Wippersnapper_AnalogIO.cpp File Reference

Detailed Description

+
+ + + + +

+Functions

void calculateHysteresis (analogInputPin pin, uint16_t pinValRaw, uint16_t &pinValThreshHi, uint16_t &pinValThreshLow)
 Calculates the hysteresis for the pin value. More...
 
+

Detailed Description

This file provides an API for interacting with a board's analog IO pins.

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Copyright (c) Brent Rubell 2020-2023 for Adafruit Industries.

BSD license, all text here must be included in any redistribution.

-
+

Function Documentation

+ +

◆ calculateHysteresis()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void calculateHysteresis (analogInputPin pin,
uint16_t pinValRaw,
uint16_t & pinValThreshHi,
uint16_t & pinValThreshLow 
)
+
+ +

Calculates the hysteresis for the pin value.

+
Parameters
+ + + + + +
pinThe desired analog pin to calculate hysteresis for.
pinValRawThe pin's raw value.
pinValThreshHiThe pin's high threshold value.
pinValThreshLowThe pin's low threshold value.
+
+
+ +
+
+