Update UI icons & show more wifi status via LED
This commit is contained in:
@@ -288,9 +288,9 @@
|
||||
</div>
|
||||
|
||||
<div class="btn-group">
|
||||
<button id="resetBtn" class="secondary">Rst</button>
|
||||
<button id="wifiBtn" class="secondary">Wifi</button>
|
||||
<button id="powerOff" class="secondary">Off</button>
|
||||
<button title="Reset to default rate, attenuation & test settings" id="resetBtn" class="secondary">↺</button>
|
||||
<button title="Change wifi access point" id="wifiBtn" class="secondary">🛜</button>
|
||||
<button title="Power off the esp-scope" id="powerOff" class="secondary">⚡</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
63
main/main.c
63
main/main.c
@@ -24,11 +24,6 @@
|
||||
// Tag for logging
|
||||
static const char* TAG = "ESP-SCOPE";
|
||||
|
||||
#define ESP_MAXIMUM_RETRY 5
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
|
||||
|
||||
// Embedded index.html
|
||||
extern const uint8_t index_html_start[] asm("_binary_index_html_start");
|
||||
extern const uint8_t index_html_end[] asm("_binary_index_html_end");
|
||||
@@ -284,29 +279,37 @@ static void show_status_led() {
|
||||
int64_t reset_pressed_time = 0;
|
||||
while (true) {
|
||||
int64_t now = esp_timer_get_time() / 1000;
|
||||
#ifdef CONFIG_LED_BUILTIN
|
||||
vTaskDelay(pdMS_TO_TICKS(is_ap ? 500 : 100));
|
||||
gpio_set_level(CONFIG_LED_BUILTIN, 1);
|
||||
vTaskDelay(pdMS_TO_TICKS(s_ws_client_fd == -1 ? 900 : 200));
|
||||
gpio_set_level(CONFIG_LED_BUILTIN, 0);
|
||||
#else
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
#endif
|
||||
|
||||
// Check Reset Pin
|
||||
#ifdef CONFIG_BSP_CONFIG_GPIO
|
||||
if (!is_ap && gpio_get_level(CONFIG_BSP_CONFIG_GPIO) == 0) {
|
||||
if (now - reset_pressed_time > 1000) {
|
||||
ESP_LOGW(TAG, "Factory Reset Triggered via GPIO %d", CONFIG_BSP_CONFIG_GPIO);
|
||||
wifi_manager_erase_config();
|
||||
esp_restart();
|
||||
} else {
|
||||
reset_pressed_time = now;
|
||||
}
|
||||
#ifdef CONFIG_LED_BUILTIN
|
||||
if (is_ap) {
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
gpio_set_level(CONFIG_LED_BUILTIN, 1);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
} else {
|
||||
reset_pressed_time = 0;
|
||||
if (is_connected()) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
gpio_set_level(CONFIG_LED_BUILTIN, 1);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(s_ws_client_fd == -1 ? 900 : 200));
|
||||
}
|
||||
#endif
|
||||
gpio_set_level(CONFIG_LED_BUILTIN, 0);
|
||||
#else
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
#endif
|
||||
|
||||
// Check Reset Pin
|
||||
#ifdef CONFIG_BSP_CONFIG_GPIO
|
||||
if (!is_ap && gpio_get_level(CONFIG_BSP_CONFIG_GPIO) == 0) {
|
||||
if (now - reset_pressed_time > 1000) {
|
||||
ESP_LOGW(TAG, "Factory Reset Triggered via GPIO %d", CONFIG_BSP_CONFIG_GPIO);
|
||||
wifi_manager_erase_config();
|
||||
esp_restart();
|
||||
} else {
|
||||
reset_pressed_time = now;
|
||||
}
|
||||
} else {
|
||||
reset_pressed_time = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,14 +486,12 @@ static esp_err_t index_js_handler(httpd_req_t* req) {
|
||||
static const httpd_uri_t uri_index_js = {
|
||||
.uri = "/index.js", .method = HTTP_GET, .handler = index_js_handler, .user_ctx = NULL};
|
||||
|
||||
static esp_err_t power_handler(httpd_req_t* req) {
|
||||
#ifdef CONFIG_LED_BUILTIN
|
||||
gpio_set_level(CONFIG_LED_BUILTIN, 0);
|
||||
#endif
|
||||
static const char *bye = "<head></head><body style='font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\n background: #1a1a1a;\n color: #e0e0e0;'><h1>Bye!</h1>Press \"reset\" on your esp-scope to start it up again</body>";
|
||||
|
||||
static esp_err_t power_handler(httpd_req_t* req) {
|
||||
httpd_resp_set_type(req, "text/html");
|
||||
httpd_resp_set_hdr(req, "Content-Type", "text/html; charset=utf-8");
|
||||
httpd_resp_send(req, "<html><body><h1>Bye!</h1></body></html>", HTTPD_RESP_USE_STRLEN);
|
||||
httpd_resp_send(req, bye, HTTPD_RESP_USE_STRLEN);
|
||||
|
||||
// delay to ensure network is flushed
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
|
||||
@@ -22,7 +22,6 @@ static const char *TAG = "WIFI_MGR";
|
||||
// Event Group
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
// Server Handle for registering handlers
|
||||
static httpd_handle_t s_server_handle = NULL;
|
||||
@@ -44,6 +43,10 @@ static void wifi_init_station(const char* ssid, const char* pass);
|
||||
#define NVS_KEY_SSID "ssid"
|
||||
#define NVS_KEY_PASS "pass"
|
||||
|
||||
bool is_connected(void) {
|
||||
return xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT, pdFALSE, pdFALSE, 1) & WIFI_CONNECTED_BIT;
|
||||
}
|
||||
|
||||
// WiFi Event Handler
|
||||
static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data) {
|
||||
|
||||
@@ -13,4 +13,5 @@ void wifi_manager_register_uri(httpd_handle_t server);
|
||||
// Helper to erase NVS credentials (can be called by button handler)
|
||||
void wifi_manager_erase_config(void);
|
||||
|
||||
bool is_connected(void);
|
||||
#endif // WIFI_MANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user