simplify screen and remove old code

This commit is contained in:
WantClue 2024-10-09 17:33:37 +02:00
parent 7dbc70bcb8
commit 8597391a41

View File

@ -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;
// Update the current screen
_clear_display(GLOBAL_STATE);
module->screen_page = current_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;
}
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,70 +346,76 @@ static void _show_overheat_screen(GlobalState * GLOBAL_STATE)
}
}
static void _update_hashrate(GlobalState * GLOBAL_STATE)
static void _update_screen_one(GlobalState * GLOBAL_STATE)
{
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;
if (module->screen_page != 0) {
return;
}
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:
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);
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, "Gh/s: %.2f", module->current_hashrate);
OLED_writeString(0, 0, module->oled_buf);
memset(module->oled_buf, 0, 20);
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, 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, "Temp: %.1f C", power_management->chip_temp_avg);
OLED_writeString(0, 3, module->oled_buf);
}
break;
default:
break;
}
}
static void _update_shares(GlobalState * GLOBAL_STATE)
static void _update_screen_two(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);
if (OLED_status()) {
// Pool URL
memset(module->oled_buf, 0, 20);
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);
char ip_address_str[IP4ADDR_STRLEN_MAX];
esp_ip4addr_ntoa(&ip_info.ip, ip_address_str, IP4ADDR_STRLEN_MAX);
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "IP: %s", ip_address_str);
OLED_writeString(0, 2, module->oled_buf);
}
break;
default:
break;
}
}
@ -424,76 +435,6 @@ static void _clear_display(GlobalState * GLOBAL_STATE)
}
}
static void _update_system_info(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()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, " Fan: %d RPM", power_management->fan_rpm);
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);
OLED_writeString(0, 1, module->oled_buf);
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, " Pwr: %.3f W", power_management->power);
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);
OLED_writeString(0, 3, module->oled_buf);
}
break;
default:
}
}
static void _update_esp32_info(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:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
case DEVICE_GAMMA:
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "FH: %lu bytes", free_heap_size);
OLED_writeString(0, 0, module->oled_buf);
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "vCore: %u mV", vcore);
OLED_writeString(0, 1, module->oled_buf);
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);
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:
}
}
static void _init_connection(GlobalState * GLOBAL_STATE)
{
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;
@ -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)
{