diff --git a/include/defines.h b/include/defines.h index bf42e2e..2701c4f 100644 --- a/include/defines.h +++ b/include/defines.h @@ -41,6 +41,6 @@ #define servoLEDCChannel LEDC_CHANNEL_0 #define servoSwitch GPIO_NUM_17 -#define debugLED GPIO_NUM_22 // d4 +#define debugLED GPIO_NUM_18 // d10 #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 93031fc..396b5d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,5 +56,5 @@ void pm_init() { extern "C" void app_main() { // pm_init(); // mainApp(); - bms_test_app(); + bms_test_LED(); } \ No newline at end of file diff --git a/test/bms_test.cpp b/test/bms_test.cpp index fddc45c..ffdb2a6 100644 --- a/test/bms_test.cpp +++ b/test/bms_test.cpp @@ -1,8 +1,55 @@ #include "bms_test.hpp" #include "i2c.h" #include "max17048.h" +#include "defines.h" -void bms_test_app() { +void bms_test_LED() { + vTaskDelay(pdMS_TO_TICKS(5000)); + i2c_init(); + + gpio_config_t led_conf = { + .pin_bit_mask = (1ULL << debugLED), + .mode = GPIO_MODE_OUTPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, + .intr_type = GPIO_INTR_DISABLE, + }; + gpio_config(&led_conf); + + bms_set_alert_bound_voltages(3.8f, 3.9f); + bms_clear_status(); + bms_clear_alrt(); + + while (true) { + uint8_t msb, lsb; + if (max17048_read_reg(MAX17048_REG_STATUS, &msb, &lsb) == ESP_OK) { + bool vh = !!(msb & VHbit); + bool vl = !!(msb & VLbit); + + bms_clear_status(); + bms_clear_alrt(); + if (vl) { + // Under-voltage: LED off + gpio_set_level(debugLED, 0); + vTaskDelay(pdMS_TO_TICKS(1000)); + } else if (vh) { + // Over-voltage: rapid blink + gpio_set_level(debugLED, 1); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(debugLED, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + } else { + // Normal: LED on + gpio_set_level(debugLED, 1); + vTaskDelay(pdMS_TO_TICKS(1000)); + } + } else { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + } +} + +void bms_test() { vTaskDelay(pdMS_TO_TICKS(5000)); esp_err_t err = i2c_init(); diff --git a/test/bms_test.hpp b/test/bms_test.hpp index 2553ddc..ee93ecb 100644 --- a/test/bms_test.hpp +++ b/test/bms_test.hpp @@ -1,6 +1,7 @@ #ifndef BMS_TEST_H #define BMS_TEST_H -void bms_test_app(); +void bms_test(); +void bms_test_LED(); #endif \ No newline at end of file