Skip to content

Commit

Permalink
moved _init_system() out of the SYSTEM task so that main doesn't move…
Browse files Browse the repository at this point in the history
… on until it's done.
  • Loading branch information
skot committed Sep 20, 2024
1 parent 2aa98e4 commit ab5cdfc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void app_main(void)
vTaskDelay(60 * 60 * 1000 / portTICK_PERIOD_MS);
}

SYSTEM_init_system(&GLOBAL_STATE);
xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL);
xTaskCreate(POWER_MANAGEMENT_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL);

Expand Down
23 changes: 10 additions & 13 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
static const char * TAG = "SystemModule";

static void _suffix_string(uint64_t, char *, size_t, int);
static void getIPstring(char * ip_str);

static esp_netif_t * netif;
esp_netif_t * netif;
static esp_netif_ip_info_t ip_info;

QueueHandle_t user_input_queue;
Expand All @@ -56,7 +57,7 @@ static esp_err_t ensure_overheat_mode_config() {
return ESP_OK;
}

static void _init_system(GlobalState * GLOBAL_STATE)
void SYSTEM_init_system(GlobalState * GLOBAL_STATE)
{
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;

Expand Down Expand Up @@ -94,11 +95,6 @@ static void _init_system(GlobalState * GLOBAL_STATE)
// set the wifi_status to blank
memset(module->wifi_status, 0, 20);

// test the LEDs
// ESP_LOGI(TAG, "Init LEDs!");
// ledc_init();
// led_set();

// Init I2C
ESP_ERROR_CHECK(i2c_master_init());
ESP_LOGI(TAG, "I2C initialized successfully");
Expand Down Expand Up @@ -141,8 +137,6 @@ static void _init_system(GlobalState * GLOBAL_STATE)
break;
default:
}

netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
}

void SYSTEM_update_overheat_mode(GlobalState * GLOBAL_STATE)
Expand Down Expand Up @@ -317,10 +311,8 @@ static void _update_esp32_info(GlobalState * GLOBAL_STATE)
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);

getIPstring(ip_address_str);
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "IP: %s", ip_address_str);
OLED_writeString(0, 2, module->oled_buf);
Expand All @@ -332,6 +324,12 @@ static void _update_esp32_info(GlobalState * GLOBAL_STATE)
}
}

static void getIPstring(char * ip_str) {
esp_netif_t * netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
esp_netif_get_ip_info(netif, &ip_info);
esp_ip4addr_ntoa(&ip_info.ip, ip_str, IP4ADDR_STRLEN_MAX);
}

static void _init_connection(GlobalState * GLOBAL_STATE)
{
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;
Expand Down Expand Up @@ -535,7 +533,6 @@ void SYSTEM_task(void * pvParameters)
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;

_init_system(GLOBAL_STATE);
user_input_queue = xQueueCreate(10, sizeof(char[10])); // Create a queue to handle user input events

_clear_display(GLOBAL_STATE);
Expand Down
2 changes: 1 addition & 1 deletion main/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "global_state.h"

void SYSTEM_task(void * parameters);

void SYSTEM_init_system(GlobalState * GLOBAL_STATE);
void SYSTEM_notify_accepted_share(GlobalState * GLOBAL_STATE);
void SYSTEM_notify_rejected_share(GlobalState * GLOBAL_STATE);
void SYSTEM_notify_found_nonce(GlobalState * GLOBAL_STATE, double found_diff, uint8_t job_id);
Expand Down

0 comments on commit ab5cdfc

Please sign in to comment.