diff --git a/components/MMC56x3/MMC56x3.c b/components/MMC56x3/MMC56x3.c index fbd124c..7dddec9 100644 --- a/components/MMC56x3/MMC56x3.c +++ b/components/MMC56x3/MMC56x3.c @@ -67,4 +67,26 @@ esp_err_t MMC56x3_reset(){ uint8_t set = 1 << DO_RESET; ESP_ERROR_CHECK(i2c_write_reg(IC0, &set, 1)); return ESP_OK; +} + +esp_err_t MMC56x3_get_bridge_offset(int32_t* x, int32_t* y, int32_t* z){ + MMC56x3_set(); + int32_t vbx, vby, vbz; + MMC56x3_get_mag_field(&vbx, &vby, &vbz); + *x=vbx; + *y=vby; + *z=vbz; + MMC56x3_reset(); + MMC56x3_get_mag_field(&vbx, &vby, &vbz); + *x=(*x+vbx)/2; + *y=(*y+vby)/2; + *z=(*z+vbz)/2; + return ESP_OK; +} + +esp_err_t MMC56x3_to_mG(int32_t x, int32_t y, int32_t z, float* rx, float* ry, float* rz){ + *rx = x*0.0625; + *ry = y*0.0625; + *rz = z*0.0625; + return ESP_OK; } \ No newline at end of file diff --git a/components/MMC56x3/include/MMC56x3.h b/components/MMC56x3/include/MMC56x3.h index dd6e13b..f85dad3 100644 --- a/components/MMC56x3/include/MMC56x3.h +++ b/components/MMC56x3/include/MMC56x3.h @@ -7,4 +7,8 @@ esp_err_t MMC56x3_get_temperature(uint8_t* temp); esp_err_t MMC56x3_get_mag_field(int32_t* x, int32_t* y, int32_t* z); esp_err_t MMC56x3_set(); -esp_err_t MMC56x3_reset(); \ No newline at end of file +esp_err_t MMC56x3_reset(); + +esp_err_t MMC56x3_get_bridge_offset(int32_t* x, int32_t* y, int32_t* z); + +esp_err_t MMC56x3_to_mG(int32_t x, int32_t y, int32_t z, float* rx, float* ry, float* rz); \ No newline at end of file diff --git a/main/CO2_Sense.c b/main/CO2_Sense.c index 90828c2..5549fef 100644 --- a/main/CO2_Sense.c +++ b/main/CO2_Sense.c @@ -68,8 +68,12 @@ void app_main(void){ MMC56x3_get_product_ID(&id); uint8_t temp; MMC56x3_get_temperature(&temp); + int32_t offx, offy, offz; + MMC56x3_get_bridge_offset(&offx, &offy, &offz); + MMC56x3_set(); ESP_LOGI("MAIN", "MMC5603 product id %d", id); ESP_LOGI("MAIN", "MMC measured temp is %d", temp); + ESP_LOGI("MAIN", "MMC bridge offset; x %ld, y %ld, z %ld", offx, offy, offz); init_scd4x(); scd4x_power_down(); @@ -89,9 +93,12 @@ void app_main(void){ } while(1){ - /*int32_t x,y,z; + int32_t x,y,z; MMC56x3_get_mag_field(&x, &y, &z); - ESP_LOGI("MAIN", "BField x %ld, y %ld, z %ld", x, y, z);*/ + float bx, by, bz; + MMC56x3_to_mG(x, y, z, &bx, &by, &bz); + ESP_LOGI("MAIN", "BField x %ld, y %ld, z %ld", x, y, z); + ESP_LOGI("MAIN", "BField x %f mG, y %f mG, z %f mG", bx, by, bz); vTaskDelay(1000 / portTICK_PERIOD_MS); } }