diff --git a/include/bar_graph.h b/include/bar_graph.h index 8cc80e0..ff8f36e 100644 --- a/include/bar_graph.h +++ b/include/bar_graph.h @@ -33,6 +33,7 @@ #include "esp_log.h" #include "esp_err.h" #include "pin_defs.h" +#include "motor_driver.h" /** * It will check for state of motor driver A, and accordingly init the free gpios. diff --git a/src/bar_graph.c b/src/bar_graph.c index 1e8942d..fd95fac 100644 --- a/src/bar_graph.c +++ b/src/bar_graph.c @@ -31,8 +31,8 @@ static int enabled_bar_graph_flag = 0; // pins IN1 - IN4 are usable in the bar graph, as pins IN5 - IN8 are connected to pins of motor driver B and these cannot be used. // So, bit mask sets bits of IN5 - IN8 as 0 and that of IN1 - IN4 as 1, because if we set pins used by mcpwm, esp32 will crash or behave oddly. // IN1 is the leftmost bit and IN8 is the rightmost bit -static const uint8_t bitmask[3] = {0xFF, 0xCF, 0x0F}; -// state 0 1 2 +static const uint8_t bitmask[3] = {0xFF, 0x0F}; +// state 0 1 // Just an array of pins used by bar graph led static const int pin_out[8] = {BG_LED_1, BG_LED_2, BG_LED_3, BG_LED_4, BG_LED_5, BG_LED_6, BG_LED_7, BG_LED_8}; @@ -40,22 +40,16 @@ esp_err_t enable_bar_graph() { uint64_t bit_mask = 0; // motor driver a is off so we can use IN1 - IN8 pins - if (read_motor_driver_mode(a) == 0) + if (get_motor_driver_status() == 0) { bit_mask = (1ULL << BG_LED_1) | (1ULL << BG_LED_2) | (1ULL << BG_LED_3) | (1ULL << BG_LED_4) | (1ULL << BG_LED_5) | (1ULL << BG_LED_6) | (1ULL << BG_LED_7) | (1ULL << BG_LED_8); enabled_bar_graph_flag = 0; } - // motor driver a is in parallel mode, so we can use IN1, IN2, IN5 - IN8 pins - else if (read_motor_driver_mode(a) == 1) - { - bit_mask = (1ULL << BG_LED_1) | (1ULL << BG_LED_2) | (1ULL << BG_LED_5) | (1ULL << BG_LED_6) | (1ULL << BG_LED_7) | (1ULL << BG_LED_8); - enabled_bar_graph_flag = 1; - } // motor driver a is in normal mode, so we can use IN5, IN6, IN7, IN8 pins - else if (read_motor_driver_mode(a) == 2) + else if (get_motor_driver_status() == 1) { bit_mask = (1ULL << BG_LED_5) | (1ULL << BG_LED_6) | (1ULL << BG_LED_7) | (1ULL << BG_LED_8); - enabled_bar_graph_flag = 2; + enabled_bar_graph_flag = 1; } gpio_config_t io_conf;