Add charge status monitoring and LED control
- Add LED_0 pin definition and charge status GPIO pin - Implement charge status monitoring in main loop - Add LED visual indicators for charging state - Configure LVGL Montserrat 10 font and set as default - Reset GPIO pins to clear SPI configurations - Update COM port to COM14 in VSCode settings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
// Define keypad buttons
|
||||
#define PIN_NUM_BUTTON_0 36
|
||||
#define PIN_NUM_BUTTON_1 39
|
||||
#define PIN_NUM_LED_1 32
|
||||
#define PIN_NUM_LED_2 33
|
||||
#define PIN_NUM_LED_0 32
|
||||
#define PIN_NUM_LED_1 33
|
||||
#define PIN_NUM_LED_2 25
|
||||
#define PIN_NUM_nON 26
|
||||
#define PIN_NUM_CHARGE_STATUS 2
|
||||
|
||||
|
||||
// Define GPIO pins
|
||||
|
||||
58
main/main.c
58
main/main.c
@@ -104,26 +104,53 @@ static inline float LPF_Update(LowPassFilter *f, float input) {
|
||||
* STATIC FUNCTION DEFINITIONS
|
||||
********************************/
|
||||
|
||||
// Helper function to set LED with verification
|
||||
static void set_led_level(gpio_num_t pin, uint32_t level)
|
||||
{
|
||||
esp_err_t err = gpio_set_level(pin, level);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to set GPIO %d to %lu: %s", pin, level, esp_err_to_name(err));
|
||||
}
|
||||
}
|
||||
|
||||
static void init_gpio(void)
|
||||
{
|
||||
gpio_config_t io_conf;
|
||||
|
||||
// Reset GPIO peripheral to clear any SPI/peripheral configurations
|
||||
gpio_reset_pin(PIN_NUM_LED_0);
|
||||
gpio_reset_pin(PIN_NUM_LED_1);
|
||||
gpio_reset_pin(PIN_NUM_LED_2);
|
||||
|
||||
// Configure output GPIO
|
||||
io_conf.pin_bit_mask = (1ULL << PIN_NUM_LED_1) | (1ULL << PIN_NUM_LED_2);
|
||||
io_conf.pin_bit_mask = (1ULL << PIN_NUM_LED_0) | (1ULL << PIN_NUM_LED_1) | (1ULL << PIN_NUM_LED_2);
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
|
||||
// Set initial state
|
||||
gpio_set_level(PIN_NUM_LED_0, 0);
|
||||
gpio_set_level(PIN_NUM_LED_1, 0);
|
||||
gpio_set_level(PIN_NUM_LED_2, 0);
|
||||
|
||||
ESP_LOGI(TAG, "LED pins configured: %d, %d, %d", PIN_NUM_LED_0, PIN_NUM_LED_1, PIN_NUM_LED_2);
|
||||
|
||||
|
||||
// Configure charge status input GPIO
|
||||
io_conf.pin_bit_mask = (1ULL << PIN_NUM_CHARGE_STATUS);
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
|
||||
|
||||
|
||||
#if 1
|
||||
// Configure output power signal
|
||||
gpio_set_level(PIN_NUM_nON, 1);
|
||||
|
||||
|
||||
io_conf.pin_bit_mask = (1ULL << PIN_NUM_nON);
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
@@ -131,7 +158,7 @@ static void init_gpio(void)
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// Configure LCD Backlight GPIO
|
||||
@@ -286,6 +313,10 @@ void app_main(void)
|
||||
bt_app_init();
|
||||
print_heap_info("POST_BLUETOOTH");
|
||||
|
||||
gpio_set_level(PIN_NUM_LED_0, 1);
|
||||
gpio_set_level(PIN_NUM_LED_1, 1);
|
||||
gpio_set_level(PIN_NUM_LED_2, 1);
|
||||
|
||||
gui_start();
|
||||
print_heap_info("POST_GUI");
|
||||
gpio_set_level(PIN_NUM_LED_2, 1);
|
||||
@@ -326,8 +357,25 @@ void app_main(void)
|
||||
#else
|
||||
while (1)
|
||||
{
|
||||
// Read charge status and update system
|
||||
bool is_charging = gpio_get_level(PIN_NUM_CHARGE_STATUS);
|
||||
system_setChargeStatus(is_charging);
|
||||
|
||||
if (is_charging)
|
||||
{
|
||||
gpio_set_level(PIN_NUM_LED_0, 0);
|
||||
gpio_set_level(PIN_NUM_LED_1, 1);
|
||||
gpio_set_level(PIN_NUM_LED_2, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
gpio_set_level(PIN_NUM_LED_0, 1);
|
||||
gpio_set_level(PIN_NUM_LED_1, 0);
|
||||
gpio_set_level(PIN_NUM_LED_2, 0);
|
||||
}
|
||||
|
||||
system_processNvsRequests();
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user