From ff3f404bb5d542139fd11d5c885cff96e5590ccc Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Fri, 15 May 2026 18:03:22 +0300 Subject: [PATCH] fix!: incorrect work address auto increment mode on 6 digits display --- README.md | 31 +++++++------------------------ include/zh_tm1637.h | 9 ++++----- version.txt | 2 +- zh_tm1637.c | 14 +++++++------- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index f27ac9d..a2b5a15 100644 --- a/README.md +++ b/README.md @@ -74,30 +74,13 @@ void app_main(void) config.dio_gpio = GPIO_NUM_26; zh_tm1637_init(&config, &tm1637_handle); zh_tm1637_set_brightness(&tm1637_handle, 7); // Set brightness. - uint8_t clear_symbols[4] = {0x00}; - zh_tm1637_print(&tm1637_handle, 0, clear_symbols, sizeof(clear_symbols)); // Clear LCD. - vTaskDelay(1000 / portTICK_PERIOD_MS); - for (;;) + for (uint8_t i = 0; i < 6; ++i) // Clear LCD. { - uint8_t symbol = 0x3F; - zh_tm1637_print(&tm1637_handle, 0, &symbol, sizeof(symbol)); // 0 on 0 position. - vTaskDelay(1000 / portTICK_PERIOD_MS); - zh_tm1637_print(&tm1637_handle, 1, &symbol, sizeof(symbol)); // 0 on 1 position. - vTaskDelay(1000 / portTICK_PERIOD_MS); - zh_tm1637_print(&tm1637_handle, 0, clear_symbols, sizeof(clear_symbols)); // Clear LCD. - vTaskDelay(1000 / portTICK_PERIOD_MS); - uint8_t symbols[] = {0x40, 0x06, 0x5B, 0x4F}; - zh_tm1637_print(&tm1637_handle, 0, symbols, sizeof(symbols)); // -123 start from 0 position. - vTaskDelay(1000 / portTICK_PERIOD_MS); - zh_tm1637_print(&tm1637_handle, 0, clear_symbols, sizeof(clear_symbols)); // Clear LCD. - vTaskDelay(1000 / portTICK_PERIOD_MS); - zh_tm1637_print(&tm1637_handle, 1, symbols, sizeof(symbols)); // -123 start from 1 position. - vTaskDelay(1000 / portTICK_PERIOD_MS); - zh_tm1637_print(&tm1637_handle, 0, clear_symbols, sizeof(clear_symbols)); // Clear LCD. - vTaskDelay(1000 / portTICK_PERIOD_MS); - const zh_tm1637_stats_t *stats = zh_tm1637_get_stats(); - printf("Number of RMT driver error: %ld.\n", stats->rmt_driver_error); - vTaskDelay(1000 / portTICK_PERIOD_MS); - } + zh_tm1637_print(&tm1637_handle, i, 0x00); + }; + vTaskDelay(1000 / portTICK_PERIOD_MS); + zh_tm1637_print(&tm1637_handle, 0, 0x4F); // 3 on C0H address. + vTaskDelay(1000 / portTICK_PERIOD_MS); + zh_tm1637_print(&tm1637_handle, 4, 0x87); // 7. on C4H address. } ``` diff --git a/include/zh_tm1637.h b/include/zh_tm1637.h index d62b4ad..574299b 100644 --- a/include/zh_tm1637.h +++ b/include/zh_tm1637.h @@ -77,16 +77,15 @@ extern "C" esp_err_t zh_tm1637_deinit(zh_tm1637_handle_t *handle); /** - * @brief Prints an symbols to the LED. + * @brief Prints a symbol to the LED. * * @param[in] handle Pointer to unique TM1637 handle. - * @param[in] position Initial print position (0-5). - * @param[in] symbols Pointer to symbols to be displayed. - * @param[in] size The symbols quantity to be displayed. + * @param[in] address Display address (0-5). + * @param[in] symbols Symbol to be displayed. * * @return ESP_OK if success or an error code otherwise. */ - esp_err_t zh_tm1637_print(zh_tm1637_handle_t *handle, uint8_t position, uint8_t *symbols, uint8_t size); + esp_err_t zh_tm1637_print(zh_tm1637_handle_t *handle, uint8_t address, uint8_t symbol); /** * @brief Set brightness of the LED. diff --git a/version.txt b/version.txt index afaf360..359a5b9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.0 \ No newline at end of file +2.0.0 \ No newline at end of file diff --git a/zh_tm1637.c b/zh_tm1637.c index eb79ebb..490ae7a 100644 --- a/zh_tm1637.c +++ b/zh_tm1637.c @@ -50,17 +50,17 @@ esp_err_t zh_tm1637_deinit(zh_tm1637_handle_t *handle) // -V2008 return ESP_OK; } -esp_err_t zh_tm1637_print(zh_tm1637_handle_t *handle, uint8_t position, uint8_t *symbols, uint8_t size) // -V2008 +esp_err_t zh_tm1637_print(zh_tm1637_handle_t *handle, uint8_t address, uint8_t symbol) // -V2008 { ZH_LOGI("Led drive printing started."); - ZH_ERROR_CHECK(handle != NULL && symbols != NULL && position <= 5 && size > 0, ESP_ERR_INVALID_ARG, NULL, "Led drive printing failed. Invalid argument."); + ZH_ERROR_CHECK(handle != NULL && address <= 5, ESP_ERR_INVALID_ARG, NULL, "Led drive printing failed. Invalid argument."); ZH_ERROR_CHECK(handle->is_initialized == true, ESP_FAIL, NULL, "Led drive printing failed. Led drive not initialized."); - uint8_t set_data_command = 0x40; + uint8_t set_data_command = 0x44; ZH_ERROR_CHECK(_zh_tm1637_send_data(handle, &set_data_command, 1) == ESP_OK, ESP_FAIL, NULL, "Led drive printing failed. RMT driver error."); - uint8_t print_symbols_command[size + 1]; - print_symbols_command[0] = position | 0xC0; - memcpy(&print_symbols_command[1], symbols, size); - ZH_ERROR_CHECK(_zh_tm1637_send_data(handle, print_symbols_command, size + 1) == ESP_OK, ESP_FAIL, NULL, "Led drive printing failed. RMT driver error."); + uint8_t print_symbols_command[2]; + print_symbols_command[0] = address | 0xC0; + memcpy(&print_symbols_command[1], &symbol, 1); + ZH_ERROR_CHECK(_zh_tm1637_send_data(handle, print_symbols_command, 2) == ESP_OK, ESP_FAIL, NULL, "Led drive printing failed. RMT driver error."); uint8_t control_display_command = (handle->brightness == -1) ? 0x80 : handle->brightness | 0x88; ZH_ERROR_CHECK(_zh_tm1637_send_data(handle, &control_display_command, 1) == ESP_OK, ESP_FAIL, NULL, "Led drive printing failed. RMT driver error."); ZH_LOGI("Led drive printing completed successfully.");