From 8597391a41f13d7010cbbad0d63aa716d20a1dc4 Mon Sep 17 00:00:00 2001 From: WantClue Date: Wed, 9 Oct 2024 17:33:37 +0200 Subject: [PATCH 1/3] simplify screen and remove old code --- main/system.c | 237 ++++++++++++++++---------------------------------- 1 file changed, 74 insertions(+), 163 deletions(-) diff --git a/main/system.c b/main/system.c index 21058d4b..c6cd0118 100644 --- a/main/system.c +++ b/main/system.c @@ -43,14 +43,11 @@ QueueHandle_t user_input_queue; //local function prototypes static esp_err_t ensure_overheat_mode_config(); static void _show_overheat_screen(GlobalState * GLOBAL_STATE); -static void _update_hashrate(GlobalState * GLOBAL_STATE); -static void _update_shares(GlobalState * GLOBAL_STATE); static void _clear_display(GlobalState * GLOBAL_STATE); static void _init_connection(GlobalState * GLOBAL_STATE); static void _update_connection(GlobalState * GLOBAL_STATE); -static void _update_system_performance(GlobalState * GLOBAL_STATE); -static void _update_system_info(GlobalState * GLOBAL_STATE); -static void _update_esp32_info(GlobalState * GLOBAL_STATE); +static void _update_screen_one(GlobalState * GLOBAL_STATE); +static void _update_screen_two(GlobalState * GLOBAL_STATE); static void show_ap_information(const char * error, GlobalState * GLOBAL_STATE); static void _check_for_best_diff(GlobalState * GLOBAL_STATE, double diff, uint8_t job_id); @@ -168,6 +165,9 @@ void SYSTEM_task(void * pvParameters) _update_connection(GLOBAL_STATE); vTaskDelay(1000 / portTICK_PERIOD_MS); } + + int current_screen = 0; + TickType_t last_update_time = xTaskGetTickCount(); while (1) { // Check for overheat mode @@ -178,37 +178,45 @@ void SYSTEM_task(void * pvParameters) continue; // Skip the normal screen cycle } - // Automatically cycle through screens - for (int screen = 0; screen < 3; screen++) { - _clear_display(GLOBAL_STATE); - module->screen_page = screen; - - switch (module->screen_page) { - case 0: - _update_system_performance(GLOBAL_STATE); - break; - case 1: - _update_system_info(GLOBAL_STATE); - break; - case 2: - _update_esp32_info(GLOBAL_STATE); - break; - } + // Update the current screen + _clear_display(GLOBAL_STATE); + module->screen_page = current_screen; + + switch (current_screen) { + case 0: + _update_screen_one(GLOBAL_STATE); + break; + case 1: + _update_screen_two(GLOBAL_STATE); + break; + } - // Wait for 10 seconds or until a button press - for (int i = 0; i < 10; i++) { - if (xQueueReceive(user_input_queue, &input_event, pdMS_TO_TICKS(1000))) { - if (strcmp(input_event, "SHORT") == 0) { - ESP_LOGI(TAG, "Short button press detected, switching to next screen"); - screen = (screen + 1) % 3; // Move to next screen - break; - } else if (strcmp(input_event, "LONG") == 0) { - ESP_LOGI(TAG, "Long button press detected, toggling WiFi SoftAP"); - toggle_wifi_softap(); // Toggle AP - } + // Wait for user input or timeout + bool input_received = false; + TickType_t current_time = xTaskGetTickCount(); + TickType_t wait_time = pdMS_TO_TICKS(10000) - (current_time - last_update_time); + + if (wait_time > 0) { + if (xQueueReceive(user_input_queue, &input_event, wait_time) == pdTRUE) { + input_received = true; + if (strcmp(input_event, "SHORT") == 0) { + ESP_LOGI(TAG, "Short button press detected, switching to next screen"); + current_screen = (current_screen + 1) % 2; + } else if (strcmp(input_event, "LONG") == 0) { + ESP_LOGI(TAG, "Long button press detected, toggling WiFi SoftAP"); + toggle_wifi_softap(); } } } + + // If no input received and 10 seconds have passed, switch to the next screen + if (!input_received && (xTaskGetTickCount() - last_update_time) >= pdMS_TO_TICKS(10000)) { + current_screen = (current_screen + 1) % 2; + } + + last_update_time = xTaskGetTickCount(); + + } } @@ -230,14 +238,12 @@ void SYSTEM_notify_accepted_share(GlobalState * GLOBAL_STATE) SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; module->shares_accepted++; - _update_shares(GLOBAL_STATE); } void SYSTEM_notify_rejected_share(GlobalState * GLOBAL_STATE) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; module->shares_rejected++; - _update_shares(GLOBAL_STATE); } void SYSTEM_notify_mining_started(GlobalState * GLOBAL_STATE) @@ -299,7 +305,6 @@ void SYSTEM_notify_found_nonce(GlobalState * GLOBAL_STATE, double found_diff, ui module->current_hashrate = ((module->current_hashrate * 9) + rolling_rate) / 10; } - _update_hashrate(GLOBAL_STATE); // logArrayContents(historical_hashrate, HISTORY_LENGTH); // logArrayContents(historical_hashrate_time_stamps, HISTORY_LENGTH); @@ -341,128 +346,43 @@ static void _show_overheat_screen(GlobalState * GLOBAL_STATE) } } -static void _update_hashrate(GlobalState * GLOBAL_STATE) -{ - SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - - if (module->screen_page != 0) { - return; - } - - switch (GLOBAL_STATE->device_model) { - case DEVICE_MAX: - case DEVICE_ULTRA: - case DEVICE_SUPRA: - case DEVICE_GAMMA: - float efficiency = GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power / (module->current_hashrate / 1000.0); - OLED_clearLine(0); - memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, "Gh%s: %.1f J/Th: %.1f", module->historical_hashrate_init < HISTORY_LENGTH ? "*" : "", - module->current_hashrate, efficiency); - OLED_writeString(0, 0, module->oled_buf); - break; - default: - } -} - -static void _update_shares(GlobalState * GLOBAL_STATE) -{ - SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - - if (module->screen_page != 0) { - return; - } - switch (GLOBAL_STATE->device_model) { - case DEVICE_MAX: - case DEVICE_ULTRA: - case DEVICE_SUPRA: - case DEVICE_GAMMA: - OLED_clearLine(1); - memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, "A/R: %llu/%llu", module->shares_accepted, module->shares_rejected); - OLED_writeString(0, 1, module->oled_buf); - break; - default: - } -} - -static void _update_best_diff(GlobalState * GLOBAL_STATE) -{ - SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - - if (module->screen_page != 0) { - return; - } - - switch (GLOBAL_STATE->device_model) { - case DEVICE_MAX: - case DEVICE_ULTRA: - case DEVICE_SUPRA: - case DEVICE_GAMMA: - OLED_clearLine(3); - memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, module->FOUND_BLOCK ? "!!! BLOCK FOUND !!!" : "BD: %s", module->best_diff_string); - OLED_writeString(0, 3, module->oled_buf); - break; - default: - } -} - -static void _clear_display(GlobalState * GLOBAL_STATE) -{ - switch (GLOBAL_STATE->device_model) { - case DEVICE_MAX: - case DEVICE_ULTRA: - case DEVICE_SUPRA: - case DEVICE_GAMMA: - OLED_clearLine(0); - OLED_clearLine(1); - OLED_clearLine(2); - OLED_clearLine(3); - break; - default: - } -} - -static void _update_system_info(GlobalState * GLOBAL_STATE) +static void _update_screen_one(GlobalState * GLOBAL_STATE) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; PowerManagementModule * power_management = &GLOBAL_STATE->POWER_MANAGEMENT_MODULE; - switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: case DEVICE_ULTRA: case DEVICE_SUPRA: case DEVICE_GAMMA: if (OLED_status()) { + float efficiency = GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power / (module->current_hashrate / 1000.0); memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, " Fan: %d RPM", power_management->fan_rpm); + snprintf(module->oled_buf, 20, "Gh/s: %.2f", module->current_hashrate); OLED_writeString(0, 0, module->oled_buf); memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, "Temp: %.1f C", power_management->chip_temp_avg); + snprintf(module->oled_buf, 20, "J/Th: %.2f", efficiency); OLED_writeString(0, 1, module->oled_buf); memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, " Pwr: %.3f W", power_management->power); + snprintf(module->oled_buf, 20, module->FOUND_BLOCK ? "!!! BLOCK FOUND !!!" : "BD: %s", module->best_diff_string); OLED_writeString(0, 2, module->oled_buf); memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, " %i mV: %i mA", (int) power_management->voltage, (int) power_management->current); + snprintf(module->oled_buf, 20, "Temp: %.1f C", power_management->chip_temp_avg); OLED_writeString(0, 3, module->oled_buf); } break; default: + break; } } -static void _update_esp32_info(GlobalState * GLOBAL_STATE) +static void _update_screen_two(GlobalState * GLOBAL_STATE) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - uint32_t free_heap_size = esp_get_free_heap_size(); - - uint16_t vcore = VCORE_get_voltage_mv(GLOBAL_STATE); switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: @@ -470,15 +390,21 @@ static void _update_esp32_info(GlobalState * GLOBAL_STATE) case DEVICE_SUPRA: case DEVICE_GAMMA: if (OLED_status()) { - + // Pool URL memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, "FH: %lu bytes", free_heap_size); + snprintf(module->oled_buf, 20, "Pool: %.13s", module->pool_url); OLED_writeString(0, 0, module->oled_buf); + // Version (truncated to fit) memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, "vCore: %u mV", vcore); + const char* version = esp_app_get_description()->version; + snprintf(module->oled_buf, 20, "Ver: %.14s", version); + if (strlen(version) > 14) { + strncpy(module->oled_buf + 18, "..", 2); + } OLED_writeString(0, 1, module->oled_buf); + // IP Address esp_netif_get_ip_info(netif, &ip_info); char ip_address_str[IP4ADDR_STRLEN_MAX]; esp_ip4addr_ntoa(&ip_info.ip, ip_address_str, IP4ADDR_STRLEN_MAX); @@ -486,11 +412,26 @@ static void _update_esp32_info(GlobalState * GLOBAL_STATE) memset(module->oled_buf, 0, 20); snprintf(module->oled_buf, 20, "IP: %s", ip_address_str); OLED_writeString(0, 2, module->oled_buf); - - OLED_writeString(0, 3, esp_app_get_description()->version); } break; default: + break; + } +} + +static void _clear_display(GlobalState * GLOBAL_STATE) +{ + switch (GLOBAL_STATE->device_model) { + case DEVICE_MAX: + case DEVICE_ULTRA: + case DEVICE_SUPRA: + case DEVICE_GAMMA: + OLED_clearLine(0); + OLED_clearLine(1); + OLED_clearLine(2); + OLED_clearLine(3); + break; + default: } } @@ -543,36 +484,6 @@ static void _update_connection(GlobalState * GLOBAL_STATE) } } -static void _update_system_performance(GlobalState * GLOBAL_STATE) -{ - SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - // Calculate the uptime in seconds - double uptime_in_seconds = (esp_timer_get_time() - module->start_time) / 1000000; - int uptime_in_days = uptime_in_seconds / (3600 * 24); - int remaining_seconds = (int) uptime_in_seconds % (3600 * 24); - int uptime_in_hours = remaining_seconds / 3600; - remaining_seconds %= 3600; - int uptime_in_minutes = remaining_seconds / 60; - - switch (GLOBAL_STATE->device_model) { - case DEVICE_MAX: - case DEVICE_ULTRA: - case DEVICE_SUPRA: - case DEVICE_GAMMA: - if (OLED_status()) { - - _update_hashrate(GLOBAL_STATE); - _update_shares(GLOBAL_STATE); - _update_best_diff(GLOBAL_STATE); - - memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, "UT: %dd %ih %im", uptime_in_days, uptime_in_hours, uptime_in_minutes); - OLED_writeString(0, 2, module->oled_buf); - } - break; - default: - } -} static void show_ap_information(const char * error, GlobalState * GLOBAL_STATE) { From bbef32f1c18c039b260607fad753125943c7253c Mon Sep 17 00:00:00 2001 From: WantClue Date: Wed, 9 Oct 2024 19:50:09 +0200 Subject: [PATCH 2/3] update rebase, ip_info to local --- main/system.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/main/system.c b/main/system.c index 02cc8f67..b3b3fb14 100644 --- a/main/system.c +++ b/main/system.c @@ -30,7 +30,6 @@ #include "vcore.h" - static const char * TAG = "SystemModule"; static void _suffix_string(uint64_t, char *, size_t, int); @@ -400,7 +399,7 @@ static void _update_screen_one(GlobalState * GLOBAL_STATE) static void _update_screen_two(GlobalState * GLOBAL_STATE) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - + esp_netif_ip_info_t ip_info; switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: @@ -413,14 +412,6 @@ static void _update_screen_two(GlobalState * GLOBAL_STATE) snprintf(module->oled_buf, 20, "Pool: %.13s", module->pool_url); OLED_writeString(0, 0, module->oled_buf); - // Version (truncated to fit) - memset(module->oled_buf, 0, 20); - const char* version = esp_app_get_description()->version; - snprintf(module->oled_buf, 20, "Ver: %.14s", version); - if (strlen(version) > 14) { - strncpy(module->oled_buf + 18, "..", 2); - } - OLED_writeString(0, 1, module->oled_buf); // IP Address esp_netif_get_ip_info(netif, &ip_info); From 4010a0becea7f98865a2107fe82c2666a167d289 Mon Sep 17 00:00:00 2001 From: WantClue Date: Wed, 9 Oct 2024 20:58:14 +0200 Subject: [PATCH 3/3] add second line for longer pool url, switch to fallback if used --- main/system.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main/system.c b/main/system.c index b3b3fb14..93918b77 100644 --- a/main/system.c +++ b/main/system.c @@ -409,9 +409,20 @@ static void _update_screen_two(GlobalState * GLOBAL_STATE) if (OLED_status()) { // Pool URL memset(module->oled_buf, 0, 20); - snprintf(module->oled_buf, 20, "Pool: %.13s", module->pool_url); + if (module->is_using_fallback) { + snprintf(module->oled_buf, 20, "Pool: %.13s", module->fallback_pool_url); + } else { + snprintf(module->oled_buf, 20, "Pool: %.13s", module->pool_url); + } OLED_writeString(0, 0, module->oled_buf); - + // Second line of pool URL + memset(module->oled_buf, 0, 20); + if (module->is_using_fallback) { + snprintf(module->oled_buf, 20, "%.19s", module->fallback_pool_url + 13); + } else { + snprintf(module->oled_buf, 20, "%.19s", module->pool_url + 13); + } + OLED_writeString(0, 1, module->oled_buf); // IP Address esp_netif_get_ip_info(netif, &ip_info);