generated from BrandonElectronic/ESP-COMPONENT-TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
123 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
idf_component_register(SRCS "main.c" | ||
INCLUDE_DIRS "." ) | ||
|
||
# Be aware this file should not be takes as inspiration on how to set up compilation with the CMake build system when using ESP-IDF, because it directly includes the implementation files. | ||
# This has to be done because the examples are build to test if they are still working and to automatically inform the library if a pull request would break examples. | ||
# To actually include the library in your ESP-IDF project read the documentation especially the Installation section | ||
set(srcs | ||
xgzf4000-poll-data.c | ||
../../../xgzf4000.c | ||
) | ||
|
||
idf_component_register( | ||
SRCS ${srcs} | ||
INCLUDE_DIRS "../../../include" | ||
PRIV_INCLUDE_DIRS "../../../priv_include" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
idf_component_register(SRCS "xgzf4000-poll-data.c" | ||
INCLUDE_DIRS "." ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,24 @@ | ||
menu "NTC Temperature" | ||
# menu "XGZF4000 Configuration" | ||
|
||
config RESISTANCE_VOLTAGE_DIVIDER_OHM | ||
int "Resistance of Voltage Divider in Ohm" | ||
default 4700 | ||
help "This resistance can be adjusted to output different voltage" | ||
|
||
config EXP_VOLTAGE | ||
string "EXP32 Voltage" | ||
default "3.3" | ||
help "This voltage is the supply voltage of the single-chip microcomputer" | ||
|
||
config BETA | ||
int "" "Maximum of the output ADC raw digital reading result" | ||
default 3950 | ||
help | ||
"This is 4095 under Single Read mode, 8191 under Continuous Read mode. | ||
2 ^ 12 - 1 = 4095, 2 ^ 13 - 1 = 8191" | ||
|
||
config COEFFICIENT_A | ||
string "HardwareA_coefficient" | ||
default "0.0007207995816" | ||
help | ||
"Coefficient A value for the Steinhart-Hart model of the NTC thermistor. | ||
This coefficient affects the temperature calculation." | ||
# config FLOW_RATE_UNIT | ||
# string "Unit for Flow Rate Measurement" | ||
# default "L/min" | ||
# option "L/min" if FLOW_RATE_UNIT_LMIN | ||
# option "m^3/h" if FLOW_RATE_UNIT_CMH | ||
# help | ||
# Choose the unit for measuring the flow rate: | ||
# - L/min: Liters per minute | ||
# - m^3/h: Cubic meters per hour | ||
|
||
config COEFFICIENT_B | ||
string "HardwareB_coefficient" | ||
default "0.0002171490624" | ||
help | ||
"Coefficient B value for the Steinhart-Hart model of the NTC thermistor. | ||
This coefficient affects the temperature calculation." | ||
# config FLOW_RATE_UNIT_LMIN | ||
# bool "Liters per minute (L/min)" | ||
# help | ||
# Select this option to measure the flow rate in liters per minute. | ||
|
||
config COEFFICIENT_C | ||
string "HardwareC_coefficient" | ||
default "0.00000008956835924" | ||
help | ||
" Coefficient C value for the Steinhart-Hart model of the NTC thermistor. | ||
This coefficient affects the temperature calculation." | ||
# config FLOW_RATE_UNIT_CMH | ||
# bool "Cubic meters per hour (m³/h)" | ||
# help | ||
# Select this option to measure the flow rate in cubic meters per hour. | ||
|
||
config CONSTANT_SAMPLING | ||
int "CONSTANT_SAMPLING" | ||
default 5 | ||
help | ||
"CONSTANT_SAMPLING represents the number of a constant sample. | ||
It plays a role in the NTC reading temperature." | ||
|
||
config SAMPLING_DELAY | ||
int "Time delay" | ||
default 300 | ||
help | ||
"Represents the delay time of the sample,can be used to set the delay time of a task." | ||
|
||
config SUPPORT_SIMULATION_TEMPERATURE_OFFSET | ||
bool "Offset Access" | ||
default n | ||
help | ||
"123456 SIMULATION_TEMPERATURE_OFFSET" | ||
|
||
config SIMULATION_TEMPERATURE_OFFSET_VALUE | ||
depends on SUPPORT_SIMULATION_TEMPERATURE_OFFSET | ||
int "Offset temperature" | ||
default 0 | ||
help | ||
"123456 SIMULATION_TEMPERATURE_OFFSET_VALUE" | ||
|
||
|
||
endmenu # NTC Temperature ADC | ||
# endmenu | ||
|
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "esp_log.h" | ||
#include "xgzf4000.h" | ||
|
||
static const char *TAG = "XGZF4000_APP"; | ||
|
||
#define I2C_XGZF4000_ADDR 0x50 // default I2C address of the XGZF4000 sensor | ||
#define I2C_MASTER_SCL_IO 19 // Assign the SCL pin number | ||
#define I2C_MASTER_SDA_IO 18 // Assign the SDA pin number | ||
#define I2C_MASTER_NUM I2C_NUM_0 | ||
#define I2C_MASTER_FREQ_HZ 100000 // I2C master frequency | ||
|
||
static xgzf4000_dev_handle_t xgzf4000; | ||
|
||
static void poll_air_flow_data(void) { | ||
uint32_t flow_rate_raw; | ||
float flow_rate; | ||
|
||
if (xgzf4000_read_air_flow(xgzf4000, &flow_rate_raw, &flow_rate) == ESP_OK) { | ||
// Convert raw flow rate based on the selected unit | ||
#ifdef CONFIG_FLOW_RATE_UNIT_LMIN | ||
flow_rate *= LITERS_PER_MINUTE_FACTOR; | ||
#elif CONFIG_FLOW_RATE_UNIT_CMH | ||
flow_rate *= CUBIC_METERS_PER_HOUR_FACTOR; | ||
#endif | ||
|
||
// Log the flow rate in the selected unit | ||
#ifdef CONFIG_FLOW_RATE_UNIT_LMIN | ||
ESP_LOGI(TAG, "Raw Flow Rate: %u, Flow Rate: %.2f L/min", flow_rate_raw, flow_rate); | ||
#elif CONFIG_FLOW_RATE_UNIT_CMH | ||
ESP_LOGI(TAG, "Raw Flow Rate: %u, Flow Rate: %.2f m³/h", flow_rate_raw, flow_rate); | ||
#endif | ||
} else { | ||
ESP_LOGE(TAG, "Failed to read air flow data"); | ||
} | ||
} | ||
|
||
void app_main(void) { | ||
int ret = ESP_OK; | ||
|
||
xgzf4000_i2c_config_t i2c_config = { | ||
.i2c_port = I2C_MASTER_NUM, | ||
.i2c_addr = I2C_XGZF4000_ADDR, | ||
}; | ||
|
||
ESP_ERROR_CHECK(xgzf4000_new_sensor(I2C_MASTER_NUM, I2C_SDA_PIN, I2C_SCL_PIN)); | ||
|
||
|
||
if (init_xgzf4000_sensor() != ESP_OK) { | ||
ESP_LOGE(TAG, "Failed to initialize XGZF4000 sensor"); | ||
return; | ||
} | ||
|
||
while (1) { | ||
poll_air_flow_data(); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
} | ||
|
||
// Clean up | ||
xgzf4000_del_sensor(xgzf4000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters