From 57fd49b3d6bd6a44c077c2dd63e1dc2fb9f75d3e Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 25 Apr 2026 14:36:17 +0200 Subject: [PATCH] Reworked Error Code Printing --- main/bosch456.c | 58 ++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/main/bosch456.c b/main/bosch456.c index 91f18c4..96b2897 100644 --- a/main/bosch456.c +++ b/main/bosch456.c @@ -27,7 +27,7 @@ uint16_t int_status = 0; static void interrupt_callback(void *) { interrupt_status = 1; - //ESP_LOGI("INTERRUPT", "STEP DETECTED"); + // ESP_LOGI("INTERRUPT", "STEP DETECTED"); } /******************************************************************************/ @@ -86,30 +86,38 @@ void bma4_delay_us(uint32_t period, void *intf_ptr) { * @brief Prints the execution status of the APIs. */ void bma4_error_codes_print_result(const char api_name[], int8_t rslt) { - if (rslt != BMA4_OK) { - ESP_LOGI("BMA4_I2C", "%s\t", api_name); - if (rslt == BMA4_E_NULL_PTR) { - ESP_LOGI("BMA4_I2C", "Error [%d] : Null pointer\r\n", rslt); - } else if (rslt == BMA4_E_COM_FAIL) { - ESP_LOGI("BMA4_I2C", "Error [%d] : Communication failure\r\n", rslt); - } else if (rslt == BMA4_E_CONFIG_STREAM_ERROR) { - ESP_LOGI("BMA4_I2C", "Error [%d] : Invalid configuration stream\r\n", - rslt); - } else if (rslt == BMA4_E_SELF_TEST_FAIL) { - ESP_LOGI("BMA4_I2C", "Error [%d] : Self test failed\r\n", rslt); - } else if (rslt == BMA4_E_INVALID_SENSOR) { - ESP_LOGI("BMA4_I2C", "Error [%d] : Device not found\r\n", rslt); - } else if (rslt == BMA4_E_OUT_OF_RANGE) { - ESP_LOGI("BMA4_I2C", "Error [%d] : Out of Range\r\n", rslt); - } else if (rslt == BMA4_E_AVG_MODE_INVALID_CONF) { - ESP_LOGI("BMA4_I2C", - "Error [%d] : Invalid bandwidth and ODR combination in Accel " - "Averaging mode\r\n", - rslt); - } else { - /* For more error codes refer "*_defs.h" */ - ESP_LOGI("BMA4_I2C", "Error [%d] : Unknown error code\r\n", rslt); - } + if (rslt == BMA4_OK) { + return; + } + + ESP_LOGI("BMA4_I2C", "%s\t", api_name); + + switch (rslt) { + case BMA4_E_NULL_PTR: + ESP_LOGI("BMA4_I2C", "Error [%d] : Null pointer\r\n", rslt); + break; + case BMA4_E_COM_FAIL: + ESP_LOGI("BMA4_I2C", "Error [%d] : Communication failure\r\n", rslt); + break; + case BMA4_E_CONFIG_STREAM_ERROR: + ESP_LOGI("BMA4_I2C", "Error [%d] : Invalid configuration stream\r\n", rslt); + break; + case BMA4_E_SELF_TEST_FAIL: + ESP_LOGI("BMA4_I2C", "Error [%d] : Self test failed\r\n", rslt); + break; + case BMA4_E_INVALID_SENSOR: + ESP_LOGI("BMA4_I2C", "Error [%d] : Device not found\r\n", rslt); + break; + case BMA4_E_OUT_OF_RANGE: + ESP_LOGI("BMA4_I2C", "Error [%d] : Out of Range\r\n", rslt); + break; + case BMA4_E_AVG_MODE_INVALID_CONF: + ESP_LOGI("BMA4_I2C", "Error [%d] : Invalid bandwidth/ODR combination\r\n", + rslt); + break; + default: + ESP_LOGI("BMA4_I2C", "Error [%d] : Unknown error code\r\n", rslt); + break; } }