Skip to content

Commit

Permalink
feat: Fix screens
Browse files Browse the repository at this point in the history
  • Loading branch information
JahazielLem committed Sep 19, 2024
1 parent 7d0cb37 commit 72f96d5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 54 deletions.
2 changes: 1 addition & 1 deletion firmware/components/wifi_captive/captive_portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ esp_err_t http_404_error_handler(httpd_req_t* req, httpd_err_code_t err) {
static httpd_handle_t start_webserver(void) {
httpd_handle_t server = NULL;
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
config.max_open_sockets = 10;
config.max_open_sockets = 7;
config.lru_purge_enable = true;

// Start the httpd server
Expand Down
13 changes: 10 additions & 3 deletions firmware/main/apps/ble/spam/spam_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ static void ble_screens_display_scanning_animation() {

void ble_screens_start_scanning_animation() {
oled_screen_clear();
oled_screen_display_text_center("BLE SPAM", 0, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center("< Back", 0, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center("BLE SPAM", 1, OLED_DISPLAY_NORMAL);
#ifdef CONFIG_RESOLUTION_128X64
animations_task_run(ble_screens_display_scanning_animation, 100, NULL);
#endif
}

void ble_screens_display_scanning_text(char* name) {
oled_screen_clear_line(0, 7, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center(name, 7, OLED_DISPLAY_INVERT);
int page = 7;
#ifdef CONFIG_RESOLUTION_128X32
page = 2;
#endif
oled_screen_clear_line(0, page, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center(name, page, OLED_DISPLAY_INVERT);
}
2 changes: 1 addition & 1 deletion firmware/main/apps/ble/trackers/trackers_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void module_update_tracker_name(char* tracker_name, uint16_t index) {

void module_display_scanning() {
led_control_run_effect(led_control_pulse_leds);
genera_screen_display_notify_information("Searching", "Looking for devices");
genera_screen_display_notify_information("Searching", "Devices");
}

void module_display_tracker_information(char* title, char* body) {
Expand Down
45 changes: 35 additions & 10 deletions firmware/main/apps/wifi/deauth/deauth_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
#include "animations_task.h"
#include "esp_wifi.h"
#include "general/bitmaps_general.h"
#include "general/general_screens.h"
#include "oled_screen.h"

#define ITEMOFFSET 2
#ifdef CONFIG_RESOLUTION_128X64
#define ITEMOFFSET 2
#define ITEMSPERSCREEN 4
#else // CONFIG_RESOLUTION_128X32
#define ITEMOFFSET 1
#define ITEMSPERSCREEN 2
#endif

static int ap_count = 0;

Expand Down Expand Up @@ -63,8 +70,10 @@ void deauth_display_menu(uint16_t current_item,
oled_screen_display_text("< Exit", 0, 0, OLED_DISPLAY_NORMAL);

int position = 1;
uint16_t start_item = (current_item / ITEMSPERSCREEN) * ITEMSPERSCREEN;

for (uint16_t i = 0; i < MENUCOUNT; i++) {
for (uint16_t i = start_item;
i < start_item + ITEMSPERSCREEN && i < MENUCOUNT; i++) {
if (deauth_menu[i] == NULL) {
break;
}
Expand Down Expand Up @@ -93,7 +102,7 @@ void deauth_display_menu(uint16_t current_item,
} else {
oled_screen_display_text(item, 0, position, OLED_DISPLAY_NORMAL);
}
position = position + 2;
position = position + ITEMOFFSET;
}
oled_screen_display_show();
}
Expand All @@ -111,16 +120,19 @@ void deauth_display_scanned_ap(wifi_ap_record_t* ap_records,
if (i >= scanned_records) {
break;
}
char ssid[MAX_LINE_CHAR];
general_screen_truncate_text((char*) ap_records[i].ssid, ssid);
if (i == current_option) {
char* prefix = "> ";
char item_text[strlen(prefix) + strlen((char*) ap_records[i].ssid) + 1];

char item_text[strlen(prefix) + strlen((char*) ssid) + 1];
strcpy(item_text, prefix);
strcat(item_text, (char*) ap_records[i].ssid);
strcat(item_text, (char*) ssid);
oled_screen_display_text(item_text, 0, (i + 1) - current_option,
OLED_DISPLAY_INVERT);
} else {
oled_screen_display_text((char*) ap_records[i].ssid, 0,
(i + 1) - current_option, OLED_DISPLAY_NORMAL);
oled_screen_display_text((char*) ssid, 0, (i + 1) - current_option,
OLED_DISPLAY_NORMAL);
}
}
oled_screen_display_show();
Expand All @@ -131,7 +143,11 @@ void deauth_display_attacks(uint16_t current_item,
oled_screen_clear_buffer();
oled_screen_display_text("< Back", 0, 0, OLED_DISPLAY_NORMAL);

for (uint16_t i = 0; i < ATTACKSCOUNT; i++) {
int position = 1;
uint16_t start_item = (current_item / ITEMSPERSCREEN) * ITEMSPERSCREEN;

for (uint16_t i = start_item;
i < start_item + ITEMSPERSCREEN && i < MENUCOUNT; i++) {
if (deauth_attacks[i] == NULL) {
break;
}
Expand All @@ -142,10 +158,11 @@ void deauth_display_attacks(uint16_t current_item,
snprintf(item, 18, "%s", deauth_attacks[i]);
}
if (i == current_item) {
deauth_display_selected_item(item, i + ITEMOFFSET);
deauth_display_selected_item(item, position);
} else {
oled_screen_display_text(item, 0, i + ITEMOFFSET, OLED_DISPLAY_NORMAL);
oled_screen_display_text(item, 0, position, OLED_DISPLAY_NORMAL);
}
position = position + ITEMOFFSET;
}
oled_screen_display_show();
}
Expand Down Expand Up @@ -182,6 +199,7 @@ void deauth_display_captive_waiting() {

void deauth_display_captive_portal_creds(char* ssid, char* user, char* pass) {
oled_screen_clear();
#ifdef CONFIG_RESOLUTION_128X64
oled_screen_display_text_center("Captive Portal", 0, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center("SSID", 1, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center(ssid, 2, OLED_DISPLAY_NORMAL);
Expand All @@ -191,4 +209,11 @@ void deauth_display_captive_portal_creds(char* ssid, char* user, char* pass) {
oled_screen_display_text_center("PASS", 5, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center(pass, 6, OLED_DISPLAY_INVERT);
}
#else // CONFIG_RESOLUTION_128X32
oled_screen_display_text_center(ssid, 0, OLED_DISPLAY_NORMAL);
oled_screen_display_text_center(user, 1, OLED_DISPLAY_INVERT);
if (strcmp(pass, "") != 0) {
oled_screen_display_text_center(pass, 2, OLED_DISPLAY_INVERT);
}
#endif
}
49 changes: 11 additions & 38 deletions firmware/main/general/general_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,18 @@ static const general_menu_t card_info_menu_ctx = {
.menu_level = GENERAL_TREE_APP_SUBMENU,
};

char** general_screen_truncate_text(char* p_text, int* num_lines) {
char** lines = NULL;
*num_lines = 0;

if (strlen(p_text) > MAX_LINE_CHAR) {
char temp[50];
strncpy(temp, p_text, 50);

char* token = strtok(temp, " ");
char current_line[MAX_LINE_CHAR] = "";

while (token != NULL) {
if (strlen(current_line) + strlen(token) + 1 <= MAX_LINE_CHAR) {
if (strlen(current_line) > 0) {
strcat(current_line, " ");
}
strcat(current_line, token);
} else {
lines = realloc(lines, sizeof(char*) * (*num_lines + 1));
lines[*num_lines] = strdup(current_line);
(*num_lines)++;

strcpy(current_line, token);
}
token = strtok(NULL, " ");
}

if (strlen(current_line) > 0) {
lines = realloc(lines, sizeof(char*) * (*num_lines + 1));
lines[*num_lines] = strdup(current_line);
(*num_lines)++;
}
} else {
lines = realloc(lines, sizeof(char*) * (*num_lines + 1));
lines[*num_lines] = strdup(p_text);
(*num_lines)++;
void general_screen_truncate_text(char* p_text, char* p_truncated_text) {
// Truncate the text if it is longer than the screen width and add 3 dots
char* p_truncated_text_ptr = p_truncated_text;
for (uint8_t i = 0; i < (MAX_LINE_CHAR - 3); i++) {
*p_truncated_text_ptr = *p_text;
p_text++;
p_truncated_text_ptr++;
}

return lines; // Regresar el array de líneas spliteadas
*p_truncated_text_ptr++ = '.';
*p_truncated_text_ptr++ = '.';
*p_truncated_text_ptr++ = '.';
*p_truncated_text_ptr = '\0';
}

static void general_screen_display_selected_item(char* item_text,
Expand Down
2 changes: 1 addition & 1 deletion firmware/main/general/general_screens.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void general_screen_display_card_information_handler(char* title,
void* callback_exit,
void* callback_restore);
void general_screen_display_scrolling_text_handler(void* callback_exit);
char** general_screen_truncate_text(char* p_text, int* num_lines);
void general_screen_truncate_text(char* p_text, char* p_truncated_text);
void general_screen_display_auto_card(char* lines,
int num_lines,
void* callback_exit);
Expand Down

0 comments on commit 72f96d5

Please sign in to comment.