mirror of
https://github.com/Lurkars/esp-ena.git
synced 2024-11-24 10:56:11 +01:00
improved interface with triggering, wifi enhancements
This commit is contained in:
parent
c352edbe48
commit
fd54320f7d
@ -21,47 +21,62 @@
|
||||
|
||||
#include "button-input.h"
|
||||
|
||||
static float button_states[INTERFACE_COMMANDS_SIZE];
|
||||
static int button_command_mapping[INTERFACE_COMMANDS_SIZE];
|
||||
static float input_states[INTERFACE_COMMANDS_SIZE];
|
||||
static float input_trigger_state[INTERFACE_COMMANDS_SIZE];
|
||||
static int input_command_mapping[INTERFACE_COMMANDS_SIZE];
|
||||
|
||||
void button_input_check(interface_command_t command)
|
||||
{
|
||||
int button_level = gpio_get_level(button_command_mapping[command]);
|
||||
int button_level = gpio_get_level(input_command_mapping[command]);
|
||||
|
||||
if (button_level == 0)
|
||||
{
|
||||
button_states[command] = button_states[command] + ((float)INTERFACE_INPUT_TICKS_MS / 1000);
|
||||
input_states[command] = input_states[command] + ((float)INTERFACE_INPUT_TICKS_MS / 1000);
|
||||
|
||||
if (command == INTERFACE_COMMAND_SET && button_states[command] > INTERFACE_LONG_STATE_SECONDS)
|
||||
if (command == INTERFACE_COMMAND_SET && input_states[command] > INTERFACE_LONG_STATE_SECONDS)
|
||||
{
|
||||
button_states[command] = 0;
|
||||
button_states[INTERFACE_COMMAND_SET_LONG] = button_states[INTERFACE_COMMAND_SET_LONG] + 1;
|
||||
input_states[command] = 0;
|
||||
input_states[INTERFACE_COMMAND_SET_LONG] = input_states[INTERFACE_COMMAND_SET_LONG] + 1;
|
||||
interface_execute_command(INTERFACE_COMMAND_SET_LONG);
|
||||
}
|
||||
else if (command == INTERFACE_COMMAND_RST && button_states[command] > INTERFACE_LONG_STATE_SECONDS)
|
||||
else if (command == INTERFACE_COMMAND_RST && input_states[command] > INTERFACE_LONG_STATE_SECONDS)
|
||||
{
|
||||
button_states[command] = 0;
|
||||
button_states[INTERFACE_COMMAND_RST_LONG] = button_states[INTERFACE_COMMAND_RST_LONG] + 1;
|
||||
input_states[command] = 0;
|
||||
input_states[INTERFACE_COMMAND_RST_LONG] = input_states[INTERFACE_COMMAND_RST_LONG] + 1;
|
||||
interface_execute_command(INTERFACE_COMMAND_RST_LONG);
|
||||
}
|
||||
else if (input_states[command] > input_trigger_state[command])
|
||||
{
|
||||
input_trigger_state[command] = input_trigger_state[command] - (input_trigger_state[command] / 8);
|
||||
if (input_trigger_state[command] <= ((float)INTERFACE_INPUT_TICKS_MS / 200))
|
||||
{
|
||||
input_trigger_state[command] = ((float)INTERFACE_INPUT_TICKS_MS / 200);
|
||||
}
|
||||
else if (button_level == 1 && button_states[command] > 0)
|
||||
{
|
||||
button_states[command] = 0;
|
||||
|
||||
if (command == INTERFACE_COMMAND_SET && button_states[INTERFACE_COMMAND_SET_LONG] > 0)
|
||||
{
|
||||
button_states[INTERFACE_COMMAND_SET_LONG] = 0;
|
||||
input_states[command] = 0;
|
||||
interface_execute_command_trigger(command);
|
||||
}
|
||||
else if (command == INTERFACE_COMMAND_RST && button_states[INTERFACE_COMMAND_RST_LONG] > 0)
|
||||
}
|
||||
else if (button_level == 1 && input_states[command] > 0)
|
||||
{
|
||||
button_states[INTERFACE_COMMAND_RST_LONG] = 0;
|
||||
input_states[command] = 0;
|
||||
input_trigger_state[command] = INTERFACE_LONG_STATE_SECONDS;
|
||||
if (command == INTERFACE_COMMAND_SET && input_states[INTERFACE_COMMAND_SET_LONG] > 0)
|
||||
{
|
||||
input_states[INTERFACE_COMMAND_SET_LONG] = 0;
|
||||
}
|
||||
else if (command == INTERFACE_COMMAND_RST && input_states[INTERFACE_COMMAND_RST_LONG] > 0)
|
||||
{
|
||||
input_states[INTERFACE_COMMAND_RST_LONG] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
interface_execute_command(command);
|
||||
}
|
||||
}
|
||||
else if (button_level == 1)
|
||||
{
|
||||
input_trigger_state[command] = INTERFACE_LONG_STATE_SECONDS;
|
||||
}
|
||||
}
|
||||
|
||||
void button_input_task(void *pvParameter)
|
||||
@ -96,13 +111,18 @@ void button_input_start(void)
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
|
||||
button_command_mapping[INTERFACE_COMMAND_RST] = BUTTON_RST;
|
||||
button_command_mapping[INTERFACE_COMMAND_SET] = BUTTON_SET;
|
||||
button_command_mapping[INTERFACE_COMMAND_MID] = BUTTON_MID;
|
||||
button_command_mapping[INTERFACE_COMMAND_RHT] = BUTTON_RHT;
|
||||
button_command_mapping[INTERFACE_COMMAND_LFT] = BUTTON_LFT;
|
||||
button_command_mapping[INTERFACE_COMMAND_DWN] = BUTTON_DWN;
|
||||
button_command_mapping[INTERFACE_COMMAND_UP] = BUTTON_UP;
|
||||
input_command_mapping[INTERFACE_COMMAND_RST] = BUTTON_RST;
|
||||
input_command_mapping[INTERFACE_COMMAND_SET] = BUTTON_SET;
|
||||
input_command_mapping[INTERFACE_COMMAND_MID] = BUTTON_MID;
|
||||
input_command_mapping[INTERFACE_COMMAND_RHT] = BUTTON_RHT;
|
||||
input_command_mapping[INTERFACE_COMMAND_LFT] = BUTTON_LFT;
|
||||
input_command_mapping[INTERFACE_COMMAND_DWN] = BUTTON_DWN;
|
||||
input_command_mapping[INTERFACE_COMMAND_UP] = BUTTON_UP;
|
||||
|
||||
for (int i = 0; i < INTERFACE_COMMANDS_SIZE; i++)
|
||||
{
|
||||
input_trigger_state[i] = INTERFACE_LONG_STATE_SECONDS;
|
||||
}
|
||||
|
||||
xTaskCreate(&button_input_task, "button_input_task", 4096, NULL, 5, NULL);
|
||||
}
|
@ -23,8 +23,8 @@
|
||||
|
||||
#include "m5-input.h"
|
||||
|
||||
static float old_input_states[INTERFACE_COMMANDS_SIZE];
|
||||
static float input_states[INTERFACE_COMMANDS_SIZE];
|
||||
static float input_trigger_state[INTERFACE_COMMANDS_SIZE];
|
||||
static int input_command_mapping[INTERFACE_COMMANDS_SIZE];
|
||||
static bool flipped = false;
|
||||
|
||||
@ -77,76 +77,28 @@ void button_input_check(interface_command_t command)
|
||||
}
|
||||
}
|
||||
|
||||
void accel_input_up(float axis)
|
||||
void accel_input(float axis, interface_command_t command, float tresh)
|
||||
{
|
||||
if (axis > tresh)
|
||||
{
|
||||
input_states[command] = input_states[command] + ((float)INTERFACE_INPUT_TICKS_MS / 1000);
|
||||
|
||||
input_states[INTERFACE_COMMAND_UP] = axis;
|
||||
if (axis < -0.3 && old_input_states[INTERFACE_COMMAND_UP] > -0.3 && old_input_states[INTERFACE_COMMAND_UP] + axis < -0.5)
|
||||
if (input_states[command] > input_trigger_state[command])
|
||||
{
|
||||
interface_execute_command(INTERFACE_COMMAND_UP);
|
||||
old_input_states[INTERFACE_COMMAND_UP] = axis;
|
||||
input_trigger_state[command] = input_trigger_state[command] - (input_trigger_state[command] / 8);
|
||||
if (input_trigger_state[command] <= ((float)INTERFACE_INPUT_TICKS_MS / 200))
|
||||
{
|
||||
input_trigger_state[command] = ((float)INTERFACE_INPUT_TICKS_MS / 200);
|
||||
}
|
||||
else if (axis > -0.3)
|
||||
{
|
||||
old_input_states[INTERFACE_COMMAND_UP] = 0;
|
||||
input_states[command] = 0;
|
||||
interface_execute_command_trigger(command);
|
||||
}
|
||||
}
|
||||
|
||||
void accel_input_left(float axis)
|
||||
{
|
||||
|
||||
input_states[INTERFACE_COMMAND_LFT] = axis;
|
||||
if (axis < -0.3 && old_input_states[INTERFACE_COMMAND_LFT] > -0.3 && old_input_states[INTERFACE_COMMAND_LFT] + axis < -0.5)
|
||||
{
|
||||
interface_execute_command(INTERFACE_COMMAND_LFT);
|
||||
old_input_states[INTERFACE_COMMAND_LFT] = axis;
|
||||
}
|
||||
else if (axis > -0.3)
|
||||
else if (input_states[command] > 0)
|
||||
{
|
||||
old_input_states[INTERFACE_COMMAND_LFT] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void accel_input_right(float axis)
|
||||
{
|
||||
input_states[INTERFACE_COMMAND_RHT] = axis;
|
||||
if (axis > 0.3 && old_input_states[INTERFACE_COMMAND_RHT] < 0.3 && old_input_states[INTERFACE_COMMAND_RHT] + axis > 0.5)
|
||||
{
|
||||
interface_execute_command(INTERFACE_COMMAND_RHT);
|
||||
old_input_states[INTERFACE_COMMAND_RHT] = axis;
|
||||
}
|
||||
else if (axis < 0.3)
|
||||
{
|
||||
old_input_states[INTERFACE_COMMAND_RHT] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void accel_input_down(float axis)
|
||||
{
|
||||
input_states[INTERFACE_COMMAND_DWN] = axis;
|
||||
if (axis > 0.3 && old_input_states[INTERFACE_COMMAND_DWN] < 0.3 && old_input_states[INTERFACE_COMMAND_DWN] + axis > 0.5)
|
||||
{
|
||||
interface_execute_command(INTERFACE_COMMAND_DWN);
|
||||
old_input_states[INTERFACE_COMMAND_DWN] = axis;
|
||||
}
|
||||
else if (axis < 0.3)
|
||||
{
|
||||
old_input_states[INTERFACE_COMMAND_DWN] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void gyro_input(float axis)
|
||||
{
|
||||
input_states[INTERFACE_COMMAND_MID] = axis;
|
||||
if (axis < -50 && old_input_states[INTERFACE_COMMAND_MID] > 50)
|
||||
{
|
||||
// interface_execute_command(INTERFACE_COMMAND_MID);
|
||||
old_input_states[INTERFACE_COMMAND_MID] = axis;
|
||||
ESP_LOGI(INTERFACE_LOG, "gyro: %f", axis);
|
||||
}
|
||||
else if (axis > 50)
|
||||
{
|
||||
old_input_states[INTERFACE_COMMAND_MID] = axis;
|
||||
input_states[command] = 0;
|
||||
input_trigger_state[command] = INTERFACE_LONG_STATE_SECONDS;
|
||||
interface_execute_command(command);
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,17 +116,18 @@ void m5_input_task(void *pvParameter)
|
||||
{
|
||||
button_input_check(INTERFACE_COMMAND_RST);
|
||||
mpu6886_get_accel_data(&ax, &ay, &az);
|
||||
accel_input_up(flipped ? -ax : ax);
|
||||
accel_input_left(flipped ? -ay : ay);
|
||||
accel_input_right(flipped ? -ay : ay);
|
||||
accel_input_down(flipped ? -ax : ax);
|
||||
|
||||
if (ax >= 1)
|
||||
accel_input(flipped ? ax : -ax, INTERFACE_COMMAND_UP, 0.3);
|
||||
accel_input(flipped ? ay : -ay, INTERFACE_COMMAND_LFT, 0.5);
|
||||
accel_input(flipped ? -ax : ax, INTERFACE_COMMAND_DWN, 0.5);
|
||||
accel_input(flipped ? -ay : ay, INTERFACE_COMMAND_RHT, 0.3);
|
||||
|
||||
if (ax >= 0.95)
|
||||
{
|
||||
flipped = false;
|
||||
interface_flipped(flipped);
|
||||
}
|
||||
else if (ax <= -1)
|
||||
else if (ax <= -0.95)
|
||||
{
|
||||
flipped = true;
|
||||
interface_flipped(flipped);
|
||||
@ -201,5 +154,10 @@ void m5_input_start(void)
|
||||
|
||||
mpu6886_start();
|
||||
|
||||
for (int i = 0; i < INTERFACE_COMMANDS_SIZE; i++)
|
||||
{
|
||||
input_trigger_state[i] = INTERFACE_LONG_STATE_SECONDS;
|
||||
}
|
||||
|
||||
xTaskCreate(&m5_input_task, "m5_input_task", 4096, NULL, 5, NULL);
|
||||
}
|
@ -7,9 +7,9 @@ elseif(ENA_INTERFACE_M5STICKC)
|
||||
elseif(ENA_INTERFACE_M5STICKC_PLUS)
|
||||
list(APPEND priv_requires "display-st7789" "rtc-bm8563" "imu-mpu6886" "pmu-axp192")
|
||||
else()
|
||||
list(APPEND priv_requires "display-ssd1306" "rtc-ds3231") # uncomment for custom device with SSD1306 und DS3231
|
||||
# list(APPEND priv_requires "display-ssd1306" "rtc-ds3231") # uncomment for custom device with SSD1306 und DS3231
|
||||
# list(APPEND priv_requires "display-st7735s" "rtc-bm8563" "imu-mpu6886" "pmu-axp192") # uncomment for M5StickC
|
||||
# list(APPEND priv_requires "display-st7789" "rtc-bm8563" "imu-mpu6886" "pmu-axp192") # uncomment for M5StickC PLUS
|
||||
list(APPEND priv_requires "display-st7789" "rtc-bm8563" "imu-mpu6886" "pmu-axp192") # uncomment for M5StickC PLUS
|
||||
endif()
|
||||
|
||||
idf_component_register(
|
||||
|
@ -212,6 +212,8 @@ void interface_data_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_MID, &interface_data_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_data_up);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_data_dwn);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(&interface_data_display);
|
||||
}
|
||||
|
@ -172,6 +172,8 @@ void interface_datetime_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_datetime_up);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_datetime_dwn);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET, &interface_datetime_set);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(&interface_datetime_display);
|
||||
interface_set_display_refresh_function(&interface_datetime_display_refresh);
|
||||
|
@ -130,6 +130,8 @@ void interface_debug_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_MID, &interface_debug_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_debug_up);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_debug_dwn);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(NULL);
|
||||
|
||||
|
@ -137,6 +137,8 @@ void interface_info_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_MID, &interface_info_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_info_up);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_info_dwn);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(&interface_info_display);
|
||||
}
|
||||
|
@ -288,13 +288,6 @@ void interface_input(interface_text_callback callback_rst, interface_text_callba
|
||||
|
||||
strcpy(current_char_set, char_set_uppercase);
|
||||
|
||||
printf("char_set_uppercase: %d %s\n", strlen(char_set_uppercase), char_set_uppercase);
|
||||
printf("char_set_lowercase: %d %s\n", strlen(char_set_lowercase), char_set_lowercase);
|
||||
printf("char_set_numeric: %d %s\n", strlen(char_set_numeric), char_set_numeric);
|
||||
printf("char_set_special1: %d %s\n", strlen(char_set_special1), char_set_special1);
|
||||
printf("char_set_special_uppercasecase: %d %s\n", strlen(char_set_special_uppercasecase), char_set_special_uppercasecase);
|
||||
printf("char_set_special_lowercase: %d %s\n", strlen(char_set_special_lowercase), char_set_special_lowercase);
|
||||
|
||||
current_char_index = 0;
|
||||
current_max_index = 0;
|
||||
if (current_limit == 0)
|
||||
@ -310,8 +303,11 @@ void interface_input(interface_text_callback callback_rst, interface_text_callba
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RHT, &interface_input_rht);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_MID, &interface_input_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_input_up);
|
||||
interface_command_callback_set_trigger(INTERFACE_COMMAND_UP);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_input_dwn);
|
||||
interface_command_callback_set_trigger(INTERFACE_COMMAND_DWN);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, &interface_input_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(&interface_input_display);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ void interface_init_label(void)
|
||||
interface_text_headline_debug.text[EN] = "DEBUG";
|
||||
|
||||
interface_text_wifi_scanning.text[EN] = "Scanning...";
|
||||
interface_text_wifi_nothing.text[EN] = "None...";
|
||||
|
||||
interface_text_settings_locale.text[EN] = "Language:";
|
||||
interface_text_settings_locales[EN].text[EN] = "EN";
|
||||
@ -104,6 +105,7 @@ void interface_init_label(void)
|
||||
interface_text_headline_debug.text[DE] = "DEBUG";
|
||||
|
||||
interface_text_wifi_scanning.text[DE] = "Scannen...";
|
||||
interface_text_wifi_nothing.text[DE] = "Keine...";
|
||||
|
||||
interface_text_settings_locale.text[DE] = "Sprache:";
|
||||
interface_text_settings_locales[EN].text[DE] = "EN";
|
||||
|
@ -139,6 +139,8 @@ void interface_main_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_MID, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(&interface_main_display);
|
||||
interface_set_display_refresh_function(&interface_main_display_refresh);
|
||||
|
@ -307,8 +307,11 @@ void interface_report_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_LFT, &interface_report_lft);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RHT, &interface_report_rht);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_report_up);
|
||||
interface_command_callback_set_trigger(INTERFACE_COMMAND_UP);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_report_dwn);
|
||||
interface_command_callback_set_trigger(INTERFACE_COMMAND_DWN);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, &interface_report_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(&interface_report_display);
|
||||
}
|
||||
|
@ -194,6 +194,8 @@ void interface_settings_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_MID, &interface_settings_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_settings_up);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_settings_dwn);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, NULL);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, NULL);
|
||||
|
||||
interface_set_display_function(&interface_settings_display);
|
||||
}
|
||||
|
@ -28,10 +28,11 @@
|
||||
|
||||
#define APS_TO_DISPLAY 3
|
||||
|
||||
wifi_ap_record_t ap_info[10];
|
||||
uint16_t ap_count = 0;
|
||||
int ap_index = 0;
|
||||
int ap_selected = 0;
|
||||
static wifi_ap_record_t ap_info[10];
|
||||
static uint16_t ap_count = 0;
|
||||
static int ap_index = 0;
|
||||
static int ap_selected = 0;
|
||||
static bool interface_wifi_working = false;
|
||||
|
||||
static wifi_config_t current_wifi_config;
|
||||
|
||||
@ -116,14 +117,10 @@ void interface_wifi_dwn(void)
|
||||
|
||||
void interface_wifi_display(void)
|
||||
{
|
||||
display_menu_headline(interface_get_label_text(&interface_text_headline_wifi), true, 0);
|
||||
}
|
||||
|
||||
void interface_wifi_display_refresh(void)
|
||||
{
|
||||
display_menu_headline(interface_get_label_text(&interface_text_headline_wifi), true, 0);
|
||||
if (ap_count > 0)
|
||||
{
|
||||
ena_eke_proxy_resume();
|
||||
display_clear_line(2, false);
|
||||
display_clear_line(4, false);
|
||||
display_clear_line(6, false);
|
||||
@ -171,6 +168,38 @@ void interface_wifi_display_refresh(void)
|
||||
}
|
||||
}
|
||||
|
||||
void interface_wifi_scan(void)
|
||||
{
|
||||
if (!interface_wifi_working)
|
||||
{
|
||||
interface_wifi_working = true;
|
||||
memset(ap_info, 0, sizeof(ap_info));
|
||||
ap_count = 0;
|
||||
ap_index = 0;
|
||||
ap_selected = 0;
|
||||
ena_eke_proxy_pause();
|
||||
|
||||
display_clear();
|
||||
display_menu_headline(interface_get_label_text(&interface_text_headline_wifi), true, 0);
|
||||
|
||||
display_text_line_column(interface_get_label_text(&interface_text_wifi_scanning), 4, 1, false);
|
||||
wifi_controller_scan(ap_info, &ap_count, interface_wifi_display);
|
||||
|
||||
ena_eke_proxy_resume();
|
||||
interface_wifi_working = false;
|
||||
}
|
||||
}
|
||||
|
||||
void interface_wifi_reconnect(void)
|
||||
{
|
||||
if (!interface_wifi_working)
|
||||
{
|
||||
interface_wifi_working = true;
|
||||
wifi_controller_reconnect(NULL);
|
||||
interface_wifi_working = false;
|
||||
}
|
||||
}
|
||||
|
||||
void interface_wifi_start(void)
|
||||
{
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET, &interface_wifi_set);
|
||||
@ -180,16 +209,11 @@ void interface_wifi_start(void)
|
||||
interface_register_command_callback(INTERFACE_COMMAND_UP, &interface_wifi_up);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_DWN, &interface_wifi_dwn);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST, &interface_wifi_mid);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_SET_LONG, &interface_wifi_scan);
|
||||
interface_register_command_callback(INTERFACE_COMMAND_RST_LONG, &interface_wifi_reconnect);
|
||||
|
||||
interface_set_display_function(&interface_wifi_display);
|
||||
interface_set_display_refresh_function(&interface_wifi_display_refresh);
|
||||
interface_set_display_refresh_function(NULL);
|
||||
|
||||
memset(ap_info, 0, sizeof(ap_info));
|
||||
ap_count = 0;
|
||||
ap_index = 0;
|
||||
ap_selected = 0;
|
||||
|
||||
ena_eke_proxy_pause();
|
||||
|
||||
wifi_controller_scan(ap_info, &ap_count);
|
||||
interface_wifi_scan();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "interface.h"
|
||||
|
||||
static interface_command_callback command_callbacks[INTERFACE_COMMANDS_SIZE];
|
||||
static bool command_callback_trigger[INTERFACE_COMMANDS_SIZE];
|
||||
static interface_display_function current_display_function;
|
||||
static interface_display_function current_display_refresh_function;
|
||||
|
||||
@ -39,6 +40,12 @@ bool interface_is_idle(void)
|
||||
void interface_register_command_callback(interface_command_t command, interface_command_callback callback)
|
||||
{
|
||||
command_callbacks[command] = callback;
|
||||
command_callback_trigger[command] = false;
|
||||
}
|
||||
|
||||
void interface_command_callback_set_trigger(interface_command_t command)
|
||||
{
|
||||
command_callback_trigger[command] = true;
|
||||
}
|
||||
|
||||
void interface_set_display_function(interface_display_function display_function)
|
||||
@ -89,6 +96,14 @@ void interface_execute_command(interface_command_t command)
|
||||
}
|
||||
}
|
||||
|
||||
void interface_execute_command_trigger(interface_command_t command)
|
||||
{
|
||||
if (command_callback_trigger[command])
|
||||
{
|
||||
interface_execute_command(command);
|
||||
}
|
||||
}
|
||||
|
||||
void interface_display_task(void *pvParameter)
|
||||
{
|
||||
xTimerStart(interface_idle_timer, 0);
|
||||
|
@ -31,7 +31,7 @@
|
||||
#define INTERFACE_IDLE_SECONDS CONFIG_ENA_INTERFACE_IDLE_TIME
|
||||
|
||||
#define INTERFACE_INPUT_TICKS_MS 20
|
||||
#define INTERFACE_LONG_STATE_SECONDS 1.0
|
||||
#define INTERFACE_LONG_STATE_SECONDS 0.6
|
||||
|
||||
/**
|
||||
* @brief available commands
|
||||
@ -99,6 +99,7 @@ interface_label_t interface_text_report_success;
|
||||
interface_label_t interface_text_report_fail;
|
||||
|
||||
interface_label_t interface_text_wifi_scanning;
|
||||
interface_label_t interface_text_wifi_nothing;
|
||||
|
||||
interface_label_t interface_text_data_del[6];
|
||||
|
||||
@ -181,6 +182,13 @@ void interface_set_timezone_offset(int timezone_offset);
|
||||
*/
|
||||
void interface_register_command_callback(interface_command_t command, interface_command_callback callback);
|
||||
|
||||
/**
|
||||
* @brief set if command is trigger
|
||||
*
|
||||
* @param[in] command id of the command to set as trigger
|
||||
*/
|
||||
void interface_command_callback_set_trigger(interface_command_t command);
|
||||
|
||||
/**
|
||||
* @brief execute a command
|
||||
*
|
||||
@ -188,6 +196,13 @@ void interface_register_command_callback(interface_command_t command, interface_
|
||||
*/
|
||||
void interface_execute_command(interface_command_t command);
|
||||
|
||||
/**
|
||||
* @brief execute a command as trigger
|
||||
*
|
||||
* @param[in] command id of the command to trigger
|
||||
*/
|
||||
void interface_execute_command_trigger(interface_command_t command);
|
||||
|
||||
/**
|
||||
* @brief set the display function
|
||||
*
|
||||
|
@ -37,7 +37,8 @@ static bool connecting = false;
|
||||
|
||||
static wifi_ap_record_t current_wifi_ap;
|
||||
|
||||
static wifi_connected_callback wifi_callback;
|
||||
static wifi_callback wifi_connected_callback;
|
||||
static wifi_callback wifi_scan_callback;
|
||||
|
||||
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
@ -52,16 +53,21 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_
|
||||
}
|
||||
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||
{
|
||||
|
||||
ESP_LOGD(WIFI_LOG, "Got Ip!");
|
||||
if (wifi_callback != NULL)
|
||||
if (wifi_connected_callback != NULL)
|
||||
{
|
||||
(*wifi_callback)();
|
||||
(*wifi_connected_callback)();
|
||||
}
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
connecting = false;
|
||||
heap_caps_check_integrity_all(true);
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE)
|
||||
{
|
||||
if (wifi_scan_callback != NULL)
|
||||
{
|
||||
(*wifi_scan_callback)();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGD(WIFI_LOG, "other wifi event: event base %s, event id %d", event_base, event_id);
|
||||
@ -92,16 +98,19 @@ void wifi_controller_init(void)
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void wifi_controller_scan(wifi_ap_record_t *ap_info, uint16_t *ap_count)
|
||||
void wifi_controller_scan(wifi_ap_record_t *ap_info, uint16_t *ap_count, wifi_callback callback)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
wifi_controller_init();
|
||||
}
|
||||
|
||||
wifi_scan_callback = callback;
|
||||
|
||||
uint16_t number = 10;
|
||||
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_wifi_stop());
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, true));
|
||||
@ -110,21 +119,21 @@ void wifi_controller_scan(wifi_ap_record_t *ap_info, uint16_t *ap_count)
|
||||
ESP_ERROR_CHECK(esp_wifi_stop());
|
||||
}
|
||||
|
||||
esp_err_t wifi_controller_connect(wifi_config_t wifi_config, wifi_connected_callback callback)
|
||||
esp_err_t wifi_controller_connect(wifi_config_t wifi_config, wifi_callback callback)
|
||||
{
|
||||
if (connecting)
|
||||
{
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
connecting = true;
|
||||
wifi_callback = callback;
|
||||
wifi_connected_callback = callback;
|
||||
if (!initialized)
|
||||
{
|
||||
wifi_controller_init();
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_wifi_stop());
|
||||
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id));
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
@ -159,7 +168,7 @@ esp_err_t wifi_controller_connect(wifi_config_t wifi_config, wifi_connected_call
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t wifi_controller_reconnect(wifi_connected_callback callback)
|
||||
esp_err_t wifi_controller_reconnect(wifi_callback callback)
|
||||
{
|
||||
if (connecting)
|
||||
{
|
||||
@ -167,13 +176,14 @@ esp_err_t wifi_controller_reconnect(wifi_connected_callback callback)
|
||||
}
|
||||
connecting = true;
|
||||
|
||||
wifi_callback = callback;
|
||||
wifi_connected_callback = callback;
|
||||
if (!initialized)
|
||||
{
|
||||
wifi_controller_init();
|
||||
}
|
||||
|
||||
esp_wifi_stop();
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_wifi_stop());
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id));
|
||||
@ -198,7 +208,7 @@ esp_err_t wifi_controller_reconnect(wifi_connected_callback callback)
|
||||
}
|
||||
else if (bits & WIFI_FAIL_BIT)
|
||||
{
|
||||
ESP_LOGI(WIFI_LOG, "Failed to reconnect to last ap");
|
||||
ESP_LOGD(WIFI_LOG, "Failed to reconnect to last ap");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
else
|
||||
|
@ -22,7 +22,7 @@
|
||||
/**
|
||||
* @brief callback function after successfull wifi connect
|
||||
*/
|
||||
typedef void (*wifi_connected_callback)(void);
|
||||
typedef void (*wifi_callback)(void);
|
||||
|
||||
/**
|
||||
* @brief scan for WiFis
|
||||
@ -30,7 +30,7 @@ typedef void (*wifi_connected_callback)(void);
|
||||
* @param[out] ap_info scanned APs
|
||||
* @param[out] ap_count number of scanned APs
|
||||
*/
|
||||
void wifi_controller_scan(wifi_ap_record_t ap_info[], uint16_t *ap_count);
|
||||
void wifi_controller_scan(wifi_ap_record_t ap_info[], uint16_t *ap_count, wifi_callback callback);
|
||||
|
||||
/**
|
||||
* @brief connect to wifi ap
|
||||
@ -41,7 +41,7 @@ void wifi_controller_scan(wifi_ap_record_t ap_info[], uint16_t *ap_count);
|
||||
* @return
|
||||
* esp_err_t connection status
|
||||
*/
|
||||
esp_err_t wifi_controller_connect(wifi_config_t wifi_config, wifi_connected_callback callback);
|
||||
esp_err_t wifi_controller_connect(wifi_config_t wifi_config, wifi_callback callback);
|
||||
|
||||
/**
|
||||
* @brief reconnect to previous wifi
|
||||
@ -51,7 +51,7 @@ esp_err_t wifi_controller_connect(wifi_config_t wifi_config, wifi_connected_call
|
||||
* @return
|
||||
* esp_err_t connection status
|
||||
*/
|
||||
esp_err_t wifi_controller_reconnect(wifi_connected_callback callback);
|
||||
esp_err_t wifi_controller_reconnect(wifi_callback callback);
|
||||
|
||||
/**
|
||||
* @brief disconnect wifi
|
||||
|
Loading…
Reference in New Issue
Block a user