mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-06-23 22:10:55 +02:00
fix: selftest button functionality (#653)
* auto set self_test 0 upon pass * setting NVS from the callback context was not working. added a semaphore for blocking in self_test.c --------- Co-authored-by: Benjamin Wilson <admin@opensourceminer.com> Co-authored-by: Skot <skot@bitnet.cx>
This commit is contained in:
parent
f1c0128f73
commit
40bf6b5ebc
@ -59,7 +59,7 @@ static lv_obj_t * create_scr_self_test() {
|
|||||||
lv_obj_set_width(self_test_finished_label, LV_HOR_RES);
|
lv_obj_set_width(self_test_finished_label, LV_HOR_RES);
|
||||||
lv_obj_add_flag(self_test_finished_label, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_add_flag(self_test_finished_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
lv_label_set_long_mode(self_test_finished_label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
lv_label_set_long_mode(self_test_finished_label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||||
lv_label_set_text(self_test_finished_label, "Self test finished. Press BOOT button for 2 seconds to reset self test status and reboot the device.");
|
lv_label_set_text(self_test_finished_label, "Hold BOOT button for 2 seconds to cancel self test, or press RESET to run again.");
|
||||||
|
|
||||||
return scr;
|
return scr;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
|
|
||||||
static const char * TAG = "self_test";
|
static const char * TAG = "self_test";
|
||||||
|
|
||||||
|
SemaphoreHandle_t BootSemaphore;
|
||||||
|
|
||||||
//local function prototypes
|
//local function prototypes
|
||||||
static void tests_done(GlobalState * GLOBAL_STATE, bool test_result);
|
static void tests_done(GlobalState * GLOBAL_STATE, bool test_result);
|
||||||
|
|
||||||
@ -64,9 +66,9 @@ bool should_test(GlobalState * GLOBAL_STATE) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void reset_self_test() {
|
static void reset_self_test() {
|
||||||
ESP_LOGI(TAG, "Long press detected, resetting self test flag and rebooting...");
|
ESP_LOGI(TAG, "Long press detected...");
|
||||||
nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0);
|
// Give the semaphore back
|
||||||
esp_restart();
|
xSemaphoreGive(BootSemaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_msg(char * msg, GlobalState * GLOBAL_STATE)
|
static void display_msg(char * msg, GlobalState * GLOBAL_STATE)
|
||||||
@ -314,6 +316,14 @@ void self_test(void * pvParameters)
|
|||||||
|
|
||||||
GLOBAL_STATE->SELF_TEST_MODULE.active = true;
|
GLOBAL_STATE->SELF_TEST_MODULE.active = true;
|
||||||
|
|
||||||
|
// Create a binary semaphore
|
||||||
|
BootSemaphore = xSemaphoreCreateBinary();
|
||||||
|
|
||||||
|
if (BootSemaphore == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create semaphore");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Run PSRAM test
|
//Run PSRAM test
|
||||||
if(test_psram(GLOBAL_STATE) != ESP_OK) {
|
if(test_psram(GLOBAL_STATE) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "NO PSRAM on device!");
|
ESP_LOGE(TAG, "NO PSRAM on device!");
|
||||||
@ -513,7 +523,7 @@ void self_test(void * pvParameters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests_done(GLOBAL_STATE, TESTS_PASSED);
|
tests_done(GLOBAL_STATE, TESTS_PASSED);
|
||||||
ESP_LOGI(TAG, "Self Tests Passed!!!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,10 +540,20 @@ static void tests_done(GlobalState * GLOBAL_STATE, bool test_result)
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test_result != TESTS_PASSED) {
|
if (test_result == TESTS_FAILED) {
|
||||||
ESP_LOGI(TAG, "SELF TESTS FAIL -- Press RESET to continue");
|
ESP_LOGI(TAG, "SELF TESTS FAIL -- Press RESET to continue");
|
||||||
//wait here for a long press to reboot
|
while (1) {
|
||||||
vTaskDelay(portMAX_DELAY);
|
// Wait here forever until reset_self_test() gives the BootSemaphore
|
||||||
|
if (xSemaphoreTake(BootSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||||
|
nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0);
|
||||||
|
//wait 100ms for nvs write to finish?
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0);
|
||||||
|
ESP_LOGI(TAG, "Self Tests Passed!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user