Fixed CCS811 config, flush log.

This commit is contained in:
imi415 2021-07-17 23:13:54 +08:00
parent e91919f06b
commit bc3dce3739
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
9 changed files with 42 additions and 10 deletions

View File

@ -24,4 +24,6 @@ ccs811_ret_t user_ccs811_impl_read_register_cb(user_ccs811_impl_t *impl,
ccs811_ret_t user_ccs811_impl_write_register_cb(user_ccs811_impl_t *impl,
uint8_t reg, uint8_t *data, uint8_t len);
ccs811_ret_t user_ccs811_impl_delay_ms_cb(user_ccs811_impl_t *impl, uint32_t delay_ms);
#endif

View File

@ -5,7 +5,7 @@ ccs811_ret_t _ccs811_app_start(ccs811_t *ccs);
ccs811_ret_t _ccs811_set_mode(ccs811_t *ccs, uint8_t mode);
ccs811_ret_t ccs811_init(ccs811_t *ccs, uint8_t addr, void *arg) {
ccs811_ret_t ccs811_init(ccs811_t *ccs) {
if(_ccs811_sw_reset(ccs) == CCS_FAIL) return CCS_FAIL;
ccs->cb.delay_ms_cb(ccs->user_data, 5);
if(_ccs811_app_start(ccs) == CCS_FAIL) return CCS_FAIL;

View File

@ -14,7 +14,6 @@ typedef struct {
} ccs811_result_t;
typedef struct {
ccs811_ret_t (*set_nwake_cb)(void *handle, uint8_t is_awake);
ccs811_ret_t (*delay_ms_cb)(void *handle, uint32_t msec);
ccs811_ret_t (*read_register_cb)(void *handle, uint8_t reg, uint8_t *data, uint8_t len);
ccs811_ret_t (*write_register_cb)(void *handle, uint8_t reg, uint8_t *data, uint8_t len);
@ -26,7 +25,7 @@ typedef struct {
ccs811_cb_t cb;
} ccs811_t;
ccs811_ret_t ccs811_init(ccs811_t *ccs, uint8_t addr, void *arg);
ccs811_ret_t ccs811_init(ccs811_t *ccs);
ccs811_ret_t ccs811_set_env_data(ccs811_t *ccs, double temperature, double humidity);
ccs811_ret_t ccs811_read_baseline(ccs811_t *ccs, uint8_t *baseline);
ccs811_ret_t ccs811_store_baseline(ccs811_t *ccs, uint8_t *baseline);

View File

@ -16,10 +16,10 @@ agent: {
tvoc: {
i2c: {
path = "/dev/i2c-1";
addr = 0x58;
addr = 0x5a;
};
nwake_pin: {
path = "/dev/i2c-1";
path = "/dev/gpiochip1";
line = 5;
};
};

View File

@ -15,10 +15,10 @@ agent: {
tvoc: {
i2c: {
path = "/dev/i2c-1";
addr = 0x58;
addr = 0x5a;
};
nwake_pin: {
path = "/dev/i2c-1";
path = "/dev/gpiochip1";
line = 5;
};
};

View File

@ -15,11 +15,11 @@ agent: {
tvoc: {
i2c: {
path = "/dev/i2c-1";
addr = 0x58;
addr = 0x5a;
};
nwake_pin: {
path = "/dev/i2c-1";
line = 5;
path = "/dev/gpiochip0";
line = 6;
};
};

View File

@ -99,6 +99,11 @@ ccs811_ret_t user_ccs811_impl_read_register_cb(user_ccs811_impl_t *impl,
return CCS_FAIL;
}
USER_LOG(USER_LOG_DEBUG, "I2C register read: reg=%d, len=%d", reg, len);
for(uint8_t i = 0; i < len; i++) {
USER_LOG(USER_LOG_DEBUG, "I2C register read: reg=%d, data=0x%02x", reg, data[i]);
}
return CCS_OK;
}
@ -120,6 +125,8 @@ ccs811_ret_t user_ccs811_impl_write_register_cb(user_ccs811_impl_t *impl,
ret = CCS_FAIL;
}
USER_LOG(USER_LOG_DEBUG, "I2C register write: reg=%d", reg);
free(tx_buf);
return ret;

View File

@ -23,11 +23,34 @@ int user_tvoc_task_deinit(void) {
}
void *user_tvoc_task(void *arguments) {
user_ccs811_impl_t impl;
user_ccs811_impl_init(&impl);
ccs811_t ccs = {
.cb =
{
.write_register_cb = (ccs811_ret_t (*)(void *, uint8_t, uint8_t *, uint8_t))user_ccs811_impl_write_register_cb,
.read_register_cb = (ccs811_ret_t(*)(void *, uint8_t, uint8_t *, uint8_t))user_ccs811_impl_read_register_cb,
.delay_ms_cb = (ccs811_ret_t (*)(void *, uint32_t))user_ccs811_impl_delay_ms_cb,
},
.user_data = &impl,
};
ccs811_init(&ccs);
ccs811_set_env_data(&ccs, 26.000, 40.000);
while(g_running && !g_lvgl_ready) {
sleep(1);
}
while(g_running) {
ccs811_result_t result;
ccs811_measure(&ccs, &result);
USER_LOG(USER_LOG_INFO, "CCS: %d, %d", result.eco2, result.tvoc);
sleep(1);
}
user_ccs811_impl_deinit(&impl);
}

View File

@ -45,6 +45,7 @@ void user_log_print(user_log_level_t level, char *fmt, ...) {
fprintf(stderr, "[% 9d]%s ", time(NULL), level_str);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
fflush(stderr);
va_end(args);
}