Skip to content

Commit

Permalink
feat: Fix Screen Sizes trackers
Browse files Browse the repository at this point in the history
- Start zigbee refactor
  • Loading branch information
JahazielLem committed Aug 21, 2024
1 parent a74ddbd commit 8d57540
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 57 deletions.
4 changes: 0 additions & 4 deletions firmware/components/zigbee_switch/zigbee_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ static void esp_zb_task(void* pvParameters) {
}

void zigbee_switch_init() {
#if !defined(CONFIG_ZIGBEE_SWITCH_DEBUG)
esp_log_level_set(TAG, ESP_LOG_NONE);
#endif

esp_zb_platform_config_t config = {
.radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(),
.host_config = ESP_ZB_DEFAULT_HOST_CONFIG(),
Expand Down
11 changes: 9 additions & 2 deletions firmware/main/apps/ble/hid_device/hid_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ static void hid_module_cb_event_volumen(uint8_t button_name,
uint8_t button_event);
static void hid_module_cb_connection_handler(bool connection);

static void hid_module_reset_menu() {
current_item = 0;
hid_module_register_menu(GENERAL_TREE_APP_MENU);
hid_module_display_menu(current_item);
menus_module_set_app_state(true, hid_module_cb_event);
}

static void hid_module_increment_item() {
current_item++;
}
Expand Down Expand Up @@ -98,7 +105,7 @@ static void hid_module_cb_event(uint8_t button_name, uint8_t button_event) {
char* hid_name[20];
ble_hid_get_device_name(&hid_name);
general_screen_display_card_information_handler(
"Device Name", &hid_name, hid_module_display_menu,
"Device Name", &hid_name, hid_module_reset_menu,
hid_module_cb_event);
} else if (current_item == HID_CONFIG_MAC) {
current_item = 0;
Expand All @@ -108,7 +115,7 @@ static void hid_module_cb_event(uint8_t button_name, uint8_t button_event) {
sprintf(mac_address, "%02X:%02X:%02X:%02X", hid_mac[2], hid_mac[3],
hid_mac[4], hid_mac[5]);
general_screen_display_card_information_handler(
"Device MAC", &mac_address, hid_module_display_menu,
"Device MAC", &mac_address, hid_module_reset_menu,
hid_module_cb_event);
} else if (current_item == HID_CONFIG_START) {
current_item = 0;
Expand Down
60 changes: 47 additions & 13 deletions firmware/main/apps/ble/trackers/trackers_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ static uint16_t current_item = 0;
static uint16_t trackers_count = 0;
static bool trackers_scanned = false;
static tracker_profile_t* scanned_airtags = NULL;
char* tracker_information[4] = {
NULL,
NULL,
"MAC ADDRS",
NULL,
};

static const general_menu_t trackers_information = {
.menu_items = tracker_information,
.menu_count = 4,
.menu_level = GENERAL_TREE_APP_INFORMATION,
};

static void module_main_cb_event(uint8_t button_name, uint8_t button_event);
static void module_list_cb_event(uint8_t button_name, uint8_t button_event);
Expand All @@ -20,6 +32,13 @@ static void module_decrement_item() {
current_item--;
}

static void module_reset_menu() {
current_item = 0;
module_register_menu(GENERAL_TREE_APP_SUBMENU);
module_display_menu(current_item);
menus_module_set_app_state(true, module_list_cb_event);
}

static void module_handle_trackers(tracker_profile_t record) {
int device_exists = trackers_scanner_find_profile_by_mac(
scanned_airtags, trackers_count, record.mac_address);
Expand Down Expand Up @@ -58,13 +77,6 @@ static void module_main_cb_event(uint8_t button_name, uint8_t button_event) {
module_display_menu(current_item);
break;
case BUTTON_RIGHT:
// if(trackers_scanned){
// trackers_scanned = false;
// module_update_scan_state(trackers_scanned);
// trackers_scanner_stop();
// module_display_menu(current_item);
// break;
// }
if (current_item == TRACKERS_SCAN && !trackers_scanned) {
trackers_scanned = true;
module_update_scan_state(trackers_scanned);
Expand All @@ -82,6 +94,7 @@ static void module_main_cb_event(uint8_t button_name, uint8_t button_event) {
if (current_item == TRACKERS_LIST) {
module_register_menu(GENERAL_TREE_APP_MENU);
module_display_menu(current_item);
menus_module_set_app_state(true, module_main_cb_event);
} else {
menus_module_exit_app();
}
Expand All @@ -95,6 +108,7 @@ static void module_list_cb_event(uint8_t button_name, uint8_t button_event) {
if (button_event != BUTTON_PRESS_DOWN) {
return;
}

switch (button_name) {
case BUTTON_UP:
module_decrement_item();
Expand All @@ -111,17 +125,37 @@ static void module_list_cb_event(uint8_t button_name, uint8_t button_event) {
module_display_menu(current_item);
break;
case BUTTON_RIGHT:
char tracker_information[45];
snprintf(tracker_information, sizeof(tracker_information),
"Tracker: %s RSSI: %d dBm MAC: %02X:%02X:%02X",
scanned_airtags[current_item].name,
scanned_airtags[current_item].rssi,
char tracker_mac[18];
snprintf(tracker_mac, sizeof(tracker_mac), "%02X:%02X:%02X:%02X:%02X",
scanned_airtags[current_item].mac_address[1],
scanned_airtags[current_item].mac_address[2],
scanned_airtags[current_item].mac_address[3],
scanned_airtags[current_item].mac_address[4],
scanned_airtags[current_item].mac_address[5]);
module_display_tracker_information("Information", tracker_information);
char tracker_rssi[18];
snprintf(tracker_rssi, sizeof(tracker_rssi), "RSSI: %d",
scanned_airtags[current_item].rssi);
char tracker_name[18];
snprintf(tracker_name, sizeof(tracker_name), "Name: %s",
scanned_airtags[current_item].name);
tracker_information[0] = malloc(strlen(tracker_name) + 1);
strcpy(tracker_information[0], tracker_name);
tracker_information[1] = malloc(strlen(tracker_rssi) + 1);
strcpy(tracker_information[1], tracker_rssi);
tracker_information[3] = malloc(strlen(tracker_mac) + 1);
strcpy(tracker_information[3], tracker_mac);
general_register_scrolling_menu(&trackers_information);
general_screen_display_scrolling_text_handler(module_reset_menu);
break;
case BUTTON_LEFT:
if (tracker_information[0] != NULL) {
free(tracker_information[0]);
free(tracker_information[1]);
free(tracker_information[3]);
tracker_information[0] = NULL;
tracker_information[1] = NULL;
tracker_information[3] = NULL;
}
menus_module_set_app_state(true, module_main_cb_event);
module_register_menu(GENERAL_TREE_APP_MENU);
module_display_menu(current_item);
Expand Down
3 changes: 2 additions & 1 deletion firmware/main/apps/ble/trackers/trackers_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static const general_menu_t main_menu = {
.menu_level = GENERAL_TREE_APP_MENU,
};

static const general_menu_t trackers_list = {
static general_menu_t trackers_list = {
.menu_items = list_trackers,
.menu_count = 20,
.menu_level = GENERAL_TREE_APP_SUBMENU,
Expand All @@ -41,6 +41,7 @@ void module_register_menu(menu_tree_t menu) {
void module_add_tracker_to_list(char* tracker_name) {
list_trackers[trackers_current_item] = tracker_name;
trackers_current_item++;
trackers_list.menu_count = trackers_current_item;
}

void module_update_scan_state(bool scanning) {
Expand Down
51 changes: 51 additions & 0 deletions firmware/main/apps/zigbee/z_switch/z_switch_module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "apps/zigbee/z_switch/z_switch_module.h"
#include "apps/zigbee/z_switch/z_switch_screens.h"
#include "esp_log.h"
#include "menus_module.h"

static uint16_t current_item = 0;

static void z_switch_module_cb_event(uint8_t button_name, uint8_t button_event);
static void z_switch_module_cb_connection_handler(bool connection);

static void module_reset_menu() {
current_item = 0;
menus_module_set_app_state(true, z_switch_module_cb_event);
}

static void module_increment_item() {
current_item++;
}

static void module_decrement_item() {
current_item--;
}

static void z_switch_module_cb_connection_handler(bool connection) {}

static void z_switch_module_cb_event(uint8_t button_name,
uint8_t button_event) {
if (button_event != BUTTON_PRESS_DOWN) {
return;
}
switch (button_name) {
case BUTTON_UP:
break;
case BUTTON_DOWN:
break;
case BUTTON_RIGHT:
break;
case BUTTON_LEFT:
menus_module_exit_app();
break;
default:
break;
}
}

void z_switch_module_begin() {
radio_selector_set_zigbee_switch();
zigbee_switch_set_display_status_cb(z_switch_handle_connection_status);
zigbee_switch_init();
menus_module_set_app_state(true, z_switch_module_cb_event);
}
5 changes: 5 additions & 0 deletions firmware/main/apps/zigbee/z_switch/z_switch_module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdint.h>
#ifndef Z_SWITCH_MODULE_H
#define Z_SWITCH_MODULE_H
void z_switch_module_begin();
#endif // Z_SWITCH_MODULE_H
43 changes: 43 additions & 0 deletions firmware/main/apps/zigbee/z_switch/z_switch_screens.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "z_switch_screens.h"
#include <stdint.h>
#include <string.h>
#include "animations_task.h"
#include "freertos/FreeRTOS.h"
#include "general/bitmaps_general.h"
#include "led_events.h"
#include "oled_screen.h"

static uint16_t hid_current_item = 0;

static void z_switch_display_creating_network() {
oled_screen_clear();
oled_screen_display_text_center("Creating network", 2, OLED_DISPLAY_NORMAL);
}

static void z_switch_display_waiting_device() {
oled_screen_clear();
oled_screen_display_text_center("Waiting for devices", 2,
OLED_DISPLAY_NORMAL);
}

void z_switch_handle_connection_status(uint8_t status) {
switch (status) {
case CREATING_NETWORK:
z_switch_display_creating_network();
break;
case CREATING_NETWORK_FAILED:
break;
case WAITING_FOR_DEVICES:
z_switch_display_waiting_device();
break;
case NO_DEVICES_FOUND:
break;
case CLOSING_NETWORK:
break;
case LIGHT_PRESSED:
break;
case LIGHT_RELASED:
default:
break;
}
}
10 changes: 10 additions & 0 deletions firmware/main/apps/zigbee/z_switch/z_switch_screens.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdbool.h>
#include <stdint.h>
#include "general/general_screens.h"
#include "radio_selector.h"
#include "zigbee_switch.h"
#ifndef Z_SWITCH_SCREENS_H
#define Z_SWITCH_SCREENS_H

void z_switch_handle_connection_status(uint8_t status);
#endif // Z_SWITCH_SCREENS_H
15 changes: 12 additions & 3 deletions firmware/main/drivers/oled_driver/oled_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,20 @@ void oled_driver_draw_custom_box(oled_driver_t* dev) {
void oled_driver_draw_modal_box(oled_driver_t* dev,
int pos_x,
int modal_height) {
int page = 2;
#ifdef CONFIG_RESOLUTION_128X64
int initial_page = 2;
int height_offset = 35;
int y_offset = 3;
#else
int initial_page = 1;
int height_offset = 18;
int y_offset = 1;
#endif
int page = initial_page;
int x = pos_x;
int y = page * 8 - 3; // 13
int y = page * 8 - y_offset; // 13
int width = x + dev->_width - 4;
int height = y + 35; //- 6; // 15
int height = y + height_offset; //- 6; // 15

oled_driver_draw_rect(dev, x, y, width, height, 0);
oled_driver_draw_rect(dev, x, y, width - 1, height - 1, 0);
Expand Down
Loading

0 comments on commit 8d57540

Please sign in to comment.