Skip to content

Commit

Permalink
Merge pull request #1 from dingpppp/main
Browse files Browse the repository at this point in the history
修复一部分宏定义以及代码格式问题,注释了init_xgzf4000_sensor()函数
  • Loading branch information
hayschan authored Jan 3, 2024
2 parents 99c3f5e + 1096a15 commit 925f2c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
18 changes: 9 additions & 9 deletions examples/default_example/main/xgzf4000-poll-data.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "esp_log.h"
#include "xgzf4000.h"

static const char *TAG = "XGZF4000_APP";
static const char *TAG_XGZF = "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
Expand All @@ -25,12 +25,12 @@ static void poll_air_flow_data(void) {

// 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);
ESP_LOGI(TAG_XGZF, "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);
ESP_LOGI(TAG_XGZF, "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");
ESP_LOGE(TAG_XGZF, "Failed to read air flow data");
}
}

Expand All @@ -42,13 +42,13 @@ void app_main(void) {
.i2c_addr = I2C_XGZF4000_ADDR,
};

ESP_ERROR_CHECK(xgzf4000_new_sensor(I2C_MASTER_NUM, I2C_SDA_PIN, I2C_SCL_PIN));
ESP_ERROR_CHECK(xgzf4000_new_sensor(I2C_MASTER_NUM, I2C_MASTER_SDA_IO, I2C_MASTER_SCL_IO));


if (init_xgzf4000_sensor() != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize XGZF4000 sensor");
return;
}
// if (init_xgzf4000_sensor() != ESP_OK) {
// ESP_LOGE(TAG_XGZF, "Failed to initialize XGZF4000 sensor");
// return;
// }

while (1) {
poll_air_flow_data();
Expand Down
2 changes: 1 addition & 1 deletion include/xgzf4000.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct {
} xgzf4000_i2c_config_t;


esp_err_t xgzf4000_new_sensor(i2c_port_t i2c_num, int sda_pin, int scl_pin)
esp_err_t xgzf4000_new_sensor(i2c_port_t i2c_num, int sda_pin, int scl_pin);

/**
* @brief Delete XGZF4000 device handle.
Expand Down
4 changes: 4 additions & 0 deletions xgzf4000.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "xgzf4000.h"
#include "xgzf4000_reg.h"

#define I2C_MASTER_FREQ_HZ 100000 // I2C master frequency
#define I2C_MASTER_RX_BUF_DISABLE 0
#define I2C_MASTER_TX_BUF_DISABLE 0

#define K_FACTOR 1000 // Proportionality factor for converting raw flow data to actual flow rate, either 1000 or 1000

static esp_err_t xgzf4000_read_flow_data(xgzf4000_dev_handle_t dev, uint8_t *data, size_t len)
Expand Down

0 comments on commit 925f2c8

Please sign in to comment.