Skip to content

Commit

Permalink
feat: Add screens
Browse files Browse the repository at this point in the history
  • Loading branch information
JahazielLem committed Oct 25, 2024
1 parent 52da943 commit 07e14ef
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 13 deletions.
15 changes: 12 additions & 3 deletions firmware/components/ble_scann/ble_scann.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
#include "uart_sender.h"

static TaskHandle_t ble_scan_timer_task = NULL;
static bluetooth_traker_scanner_cb_t display_records_cb = NULL;
static bluetooth_adv_scanner_cb_t display_records_cb = NULL;
static int ble_scan_duration = 0;
static bool ble_scanner_active = false;

static esp_ble_scan_filter_t ble_scan_filter = BLE_SCAN_FILTER_ALLOW_ALL;
static void task_scanner_timer();
static void handle_bt_gapc_events(esp_gap_ble_cb_event_t event_type,
esp_ble_gap_cb_param_t* param);

void set_filter_type(uint8_t filter_type) {
ble_scan_filter = filter_type;
}

void ble_scanner_begin() {
// #if !defined(CONFIG_TRACKERS_SCANNER_DEBUG)
// esp_log_level_set(TAG_BLE_CLIENT_MODULE, ESP_LOG_NONE);
Expand All @@ -25,6 +29,7 @@ void ble_scanner_begin() {
.remote_filter_char_uuid = bt_gattc_set_default_ble_filter_char_uuid(),
.notify_descr_uuid = bt_gattc_set_default_ble_notify_descr_uuid(),
.ble_scan_params = bt_gattc_set_default_ble_scan_params()};
scan_params.ble_scan_params.scan_filter_policy = ble_scan_filter;
bt_gattc_set_ble_scan_params(&scan_params);
bt_client_event_cb_t event_cb = {.handler_gattc_cb = NULL,
.handler_gapc_cb = handle_bt_gapc_events};
Expand All @@ -46,6 +51,9 @@ static void handle_bt_gapc_events(esp_gap_ble_cb_event_t event_type,
break;
}
uart_sender_send_packet_ble(UART_SENDER_PACKET_TYPE_BLE, scan_result);
if (display_records_cb != NULL) {
display_records_cb(scan_result);
}
ESP_LOGI(TAG_BLE_CLIENT_MODULE, "New ADV found");
break;
case ESP_GAP_SEARCH_INQ_CMPL_EVT:
Expand All @@ -59,7 +67,7 @@ static void handle_bt_gapc_events(esp_gap_ble_cb_event_t event_type,
}
}

void ble_scanner_register_cb(bluetooth_traker_scanner_cb_t callback) {
void ble_scanner_register_cb(bluetooth_adv_scanner_cb_t callback) {
display_records_cb = callback;
}

Expand All @@ -71,6 +79,7 @@ static void task_scanner_timer() {
ESP_LOGI(TAG_BLE_CLIENT_MODULE, "Trackers task stopped");
ble_scanner_stop();
}
// ble_scan_duration++;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Expand Down
7 changes: 4 additions & 3 deletions firmware/components/ble_scann/ble_scann.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define SCANNER_PROFILE_NUM 1
#define SCANNER_PROFILE_A_APP_ID 0
#define SCANNER_INVALID_HANDLE 0
#define SCANNER_SCAN_DURATION 240
#define SCANNER_SCAN_DURATION 60

/**
* @brief Structure to store the tracker profile
Expand Down Expand Up @@ -44,14 +44,14 @@ typedef struct {
*
* @param record The tracker profile record
*/
typedef void (*bluetooth_traker_scanner_cb_t)(device_profile record);
typedef void (*bluetooth_adv_scanner_cb_t)(esp_ble_gap_cb_param_t* record);

/**
* @brief Register the callback to handle the bluetooth scanner
*
* @param cb The callback to handle the bluetooth scanner
*/
void ble_scanner_register_cb(bluetooth_traker_scanner_cb_t cb);
void ble_scanner_register_cb(bluetooth_adv_scanner_cb_t cb);

/**
* @brief Start the bluetooth scanner
Expand All @@ -72,4 +72,5 @@ void ble_scanner_stop();
* @return false The bluetooth scanner is not active
*/
bool ble_scanner_is_active();
void set_filter_type(uint8_t filter_type);
#endif // BLE_SCANNER_H
6 changes: 5 additions & 1 deletion firmware/components/minino_config/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,12 @@ config BLUETOOTH_APP_HID
default true
help
Enable or disable the Bluetooth HID application.
config BLUETOOTH_APP_ADV
bool "Enable ADV Scanner App"
default true
help
Enable or disable the Bluetooth ADV Scanner application.
endif # BLUETOOTH_APPS_ENABLE

################################# ZIGBEE ###################################

config ZIGBEE_APPS_ENABLE
Expand Down
70 changes: 70 additions & 0 deletions firmware/main/apps/ble/adv_scanner/adv_scan_module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "adv_scan_screens.h"
#include "ble_scann.h"
#include "esp_log.h"
#include "esp_mac.h"
#include "general_submenu.h"
#include "menus_module.h"

static uint16_t current_item = 0;

static void adv_scanner_module_cb_event(uint8_t button_name,
uint8_t button_event);

static void adv_scanner_module_reset_menu() {
current_item = 0;
adv_scanner_module_register_menu(GENERAL_TREE_APP_MENU);
adv_scanner_module_display_menu(current_item);
menus_module_set_app_state(true, adv_scanner_module_cb_event);
}

static void adv_filter_selection(uint8_t selection) {
set_filter_type(selection);
}

void adv_scanner_display_filter() {
general_submenu_menu_t adv_menu_filter;
adv_menu_filter.options = scan_filter_items;
adv_menu_filter.options_count = 4;
adv_menu_filter.select_cb = adv_filter_selection;
adv_menu_filter.exit_cb = adv_scanner_module_reset_menu;
general_submenu(adv_menu_filter);
}

static void adv_scanner_module_cb_event(uint8_t button_name,
uint8_t button_event) {
if (button_event != BUTTON_PRESS_DOWN) {
return;
}
switch (button_name) {
case BUTTON_UP:
current_item = current_item-- == 0 ? SCAN_MENU_COUNT - 1 : current_item;
adv_scanner_module_display_menu(current_item);
break;
case BUTTON_DOWN:
current_item = ++current_item > SCAN_MENU_COUNT - 1 ? 0 : current_item;
adv_scanner_module_display_menu(current_item);
break;
case BUTTON_RIGHT:
if (current_item == SCAN_TYPE) {
adv_scanner_display_filter();
} else if (current_item == SCAN_START) {
ESP_LOGI(TAG_BLE_CLIENT_MODULE, "Scan start");
ble_scanner_register_cb(adv_scanner_display_record);
ble_scanner_begin();
}
current_item = 0;

break;
case BUTTON_LEFT:
menus_module_restart();
break;
default:
break;
}
}

void adv_scanner_module_begin() {
adv_scanner_module_register_menu(GENERAL_TREE_APP_MENU);
adv_scanner_module_display_menu(current_item);
menus_module_set_app_state(true, adv_scanner_module_cb_event);
}
5 changes: 5 additions & 0 deletions firmware/main/apps/ble/adv_scanner/adv_scan_module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdint.h>
#ifndef ADV_SCAN_MODULE_H
#define ADV_SCAN_MODULE_H
void adv_scanner_module_begin();
#endif // ADV_SCAN_MODULE_H
69 changes: 69 additions & 0 deletions firmware/main/apps/ble/adv_scanner/adv_scan_screens.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "adv_scan_screens.h"
#include <stdint.h>
#include <string.h>
#include "animations_task.h"
#include "freertos/FreeRTOS.h"
#include "general/general_screens.h"
#include "led_events.h"
#include "oled_screen.h"

#define MAX_ITEMS_PER_SCREEN 5

static uint16_t hid_current_item = 0;
static esp_ble_gap_cb_param_t adv_list[MAX_ITEMS_PER_SCREEN];
static uint8_t adv_list_count = 0;

static const general_menu_t adv_menu_main = {
.menu_items = scan_menu_items,
.menu_count = SCAN_MENU_COUNT,
.menu_level = GENERAL_TREE_APP_MENU,
};

// static const general_menu_t adv_type = {
// .menu_items = scan_type_items,
// .menu_count = 2,
// .menu_level = GENERAL_TREE_APP_MENU,
// };

// static const general_menu_t adv_filter = {
// .menu_items = scan_filter_items,
// .menu_count = 4,
// .menu_level = GENERAL_TREE_APP_MENU,
// };

void adv_scanner_module_register_menu(menu_tree_t menu) {
switch (menu) {
case GENERAL_TREE_APP_MENU:
general_register_menu(&adv_menu_main);
break;
default:
general_register_menu(&adv_menu_main);
break;
}
}

void adv_scanner_display_record(esp_ble_gap_cb_param_t* record) {
if (adv_list_count >= MAX_ITEMS_PER_SCREEN) {
adv_list_count = 0;
}
adv_list[adv_list_count] = *record;

oled_screen_clear_buffer();
oled_screen_display_text("< Back", 0, 0, OLED_DISPLAY_NORMAL);
oled_screen_display_text("ADV Type | RSSI", 0, 1, OLED_DISPLAY_NORMAL);

char* row = (char*) malloc(17);
for (int i = 0; i < MAX_ITEMS_PER_SCREEN; i++) {
sprintf(row, "%s %d", evt_adv_type[adv_list[i].scan_rst.ble_evt_type],
adv_list[i].scan_rst.rssi);
oled_screen_display_text(row, 0, i + 2, OLED_DISPLAY_NORMAL);
}
oled_screen_display_show();
adv_list_count++;
}

void adv_scanner_module_display_menu(uint16_t current_item) {
led_control_run_effect(led_control_pulse_leds);
hid_current_item = current_item;
general_screen_display_menu(current_item);
}
26 changes: 26 additions & 0 deletions firmware/main/apps/ble/adv_scanner/adv_scan_screens.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdbool.h>
#include <stdint.h>
#include "esp_gap_ble_api.h"
#include "general/general_screens.h"
#ifndef ADV_SCAN_SCREENS_H
#define ADV_SCAN_SCREENS_H

enum {
SCAN_TYPE,
SCAN_FILTER,
SCAN_START,
SCAN_MENU_COUNT
} scan_menu_item = SCAN_FILTER;
char* scan_menu_items[SCAN_MENU_COUNT] = {"Scan Type", "ADV Filter", "Start"};

char* scan_type_items[2] = {"Active", "Passive"};
char* scan_filter_items[4] = {"Allow All", "Allow Only WLST", "Allow UND RPA",
"Allow WLST & RPA"};
char* evt_adv_type[5] = {"IND", "DIRECT_IND", "SCAN_IND", "NONCONN_IND",
"SCAN_RSP"};

void adv_scanner_module_register_menu(menu_tree_t menu);
void adv_scanner_clear_screen();
void adv_scanner_module_display_menu(uint16_t current_item);
void adv_scanner_display_record(esp_ble_gap_cb_param_t* record);
#endif // ADV_SCAN_SCREENS_H
10 changes: 6 additions & 4 deletions firmware/main/general/general_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#define MAX_LINE_CHAR 16

#ifdef CONFIG_RESOLUTION_128X64
#define ITEMOFFSET 2
#define ITEM_PAGE_OFFSET 2
#define ITEMOFFSET 2
#define ITEM_PAGE_OFFSET 2
#define MAX_ITEMS_PER_SCREEN 5
#else // CONFIG_RESOLUTION_128X32
#define ITEMOFFSET 1
#define ITEM_PAGE_OFFSET 1
#define ITEMOFFSET 1
#define ITEM_PAGE_OFFSET 1
#define MAX_ITEMS_PER_SCREEN 3
#endif
static uint8_t scrolling_option = 0;
static const general_menu_t* current_menu_ctx = NULL;
Expand Down
3 changes: 1 addition & 2 deletions firmware/main/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdio.h>
#include "apps/ble/hid_device/hid_module.h"
#include "apps/ble/trackers/trackers_module.h"
#include "ble_scann.h"

#include "buzzer.h"
#include "cat_console.h"
#include "esp_log.h"
Expand Down Expand Up @@ -36,7 +36,6 @@ void app_main() {
buzzer_begin(BUZZER_PIN);
sd_card_begin();
flash_fs_begin(flash_fs_screens_handler);
ble_scanner_begin();
keyboard_module_begin();
menus_module_begin();
leds_off();
Expand Down
11 changes: 11 additions & 0 deletions firmware/main/modules/menus_module/menus_include/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "trackers_module.h"
#include "z_switch_module.h"

#include "adv_scan_module.h"
#include "catdos_module.h"
#include "deauth_module.h"
#include "display_settings.h"
Expand Down Expand Up @@ -55,6 +56,7 @@ typedef enum {
MENU_BLUETOOTH_TRAKERS_SCAN,
MENU_BLUETOOTH_SPAM,
MENU_BLUETOOTH_HID,
MENU_BLUETOOTH_ADV,
/* Zigbee applications */
MENU_ZIGBEE_SPOOFING,
MENU_ZIGBEE_SWITCH,
Expand Down Expand Up @@ -280,6 +282,15 @@ menu_t menus[] = { //////////////////////////////////
.on_exit_cb = NULL,
.is_visible = true},
#endif
#ifdef CONFIG_BLUETOOTH_APP_ADV
{.display_name = "ADV Scanner",
.menu_idx = MENU_BLUETOOTH_ADV,
.parent_idx = MENU_BLUETOOTH_APPS,
.last_selected_submenu = 0,
.on_enter_cb = adv_scanner_module_begin,
.on_exit_cb = NULL,
.is_visible = true},
#endif
#endif
#ifdef CONFIG_ZIGBEE_APPS_ENABLE
{.display_name = "Zigbee",
Expand Down

0 comments on commit 07e14ef

Please sign in to comment.