mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-03-17 21:32:52 +01:00
Merge pull request #396 from WantClue/simplify_i2c_screen
simplify screen and remove old code
This commit is contained in:
commit
fefd29d982
270
main/system.c
270
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);
|
||||
@ -42,14 +41,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);
|
||||
@ -184,6 +180,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
|
||||
@ -194,37 +193,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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,14 +253,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)
|
||||
@ -315,7 +320,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);
|
||||
@ -358,70 +362,80 @@ 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;
|
||||
}
|
||||
esp_netif_ip_info_t ip_info;
|
||||
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -441,78 +455,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;
|
||||
|
||||
esp_netif_ip_info_t ip_info;
|
||||
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;
|
||||
@ -562,36 +504,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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user