Skip to content

Commit

Permalink
feat: add gps disable notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Feb 12, 2025
1 parent ac4aa5d commit a2a8a0c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
88 changes: 88 additions & 0 deletions firmware/main/general/general_notification/general_notification.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "general_notification.h"

#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "menus_module.h"
#include "oled_screen.h"

general_notification_ctx_t* notification_ctx = NULL;
static void free_ctx();

static void notification_handler(uint8_t button, uint8_t event) {
if (button != BUTTON_LEFT || event != BUTTON_PRESS_DOWN) {
return;
}
void (*exit_cb)() = notification_ctx->on_exit;
free_ctx();
if (exit_cb) {
exit_cb();
}
}

static void draw_notification() {
oled_screen_clear();
oled_screen_display_card_border();
int page = 2;
oled_screen_display_text_center(notification_ctx->head, page,
OLED_DISPLAY_NORMAL);
page++;
if (strlen(notification_ctx->body) > MAX_LINE_CHAR) {
oled_screen_display_text_splited(notification_ctx->body, &page,
OLED_DISPLAY_NORMAL);
oled_screen_display_show();
return;
}
oled_screen_display_text_center(notification_ctx->body, page,
OLED_DISPLAY_NORMAL);
oled_screen_display_show();
}

static void free_ctx() {
free(notification_ctx);
notification_ctx = NULL;
}

void general_notification(general_notification_ctx_t ctx) {
if (notification_ctx) {
free_ctx();
}
notification_ctx = calloc(1, sizeof(general_notification_ctx_t));
notification_ctx->head = ctx.head;
notification_ctx->body = ctx.body;
notification_ctx->on_enter = ctx.on_enter;
notification_ctx->on_exit = ctx.on_exit;
notification_ctx->duration_ms = ctx.duration_ms;

menus_module_disable_input();
if (notification_ctx->on_enter) {
notification_ctx->on_enter();
}
draw_notification();
vTaskDelay(pdMS_TO_TICKS(notification_ctx->duration_ms));
menus_module_enable_input();
void (*exit_cb)() = notification_ctx->on_exit;
free_ctx();
if (exit_cb) {
exit_cb();
}
}

void general_notification_handler(general_notification_ctx_t ctx) {
if (notification_ctx) {
free_ctx();
}
notification_ctx = calloc(1, sizeof(general_notification_ctx_t));
notification_ctx->head = ctx.head;
notification_ctx->body = ctx.body;
notification_ctx->on_enter = ctx.on_enter;
notification_ctx->on_exit = ctx.on_exit;
notification_ctx->duration_ms = ctx.duration_ms;

if (notification_ctx->on_enter) {
notification_ctx->on_enter();
}
draw_notification();
menus_module_set_app_state(true, notification_handler);
}
17 changes: 17 additions & 0 deletions firmware/main/general/general_notification/general_notification.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef _GENERAL_NOTIFICATION_H_
#define _GENERAL_NOTIFICATION_H_

#include <stdio.h>

typedef struct {
char* head;
char* body;
void (*on_enter)();
void (*on_exit)();
uint32_t duration_ms;
} general_notification_ctx_t;

void general_notification(general_notification_ctx_t ctx);
void general_notification_handler(general_notification_ctx_t ctx);

#endif // _GENERAL_NOTIFICATION_H_
23 changes: 23 additions & 0 deletions firmware/main/modules/gps/gps_module.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "esp_log.h"
#include "stdint.h"

#include "general_notification.h"
#include "gps_hw.h"
#include "gps_module.h"
#include "gps_screens.h"
#include "menus_module.h"
Expand Down Expand Up @@ -205,4 +207,25 @@ static void gps_module_general_data_input_cb(uint8_t button_name,
}
gps_module_stop_read();
menus_module_exit_app();
}

void gps_module_check_state() {
if (gps_hw_get_state()) {
return;
}

// gps_hw_on();

general_notification_ctx_t notification = {0};
notification.head = "GPS is Disabled";
notification.body = "Enable it from: Settings - System - GPS";
notification.on_exit = menus_module_exit_app;

general_notification_handler(notification);
}

void gps_module_reset_state() {
// if (gps_hw_get_state() && !preferences_get_bool(GPS_ENABLED_MEM, false)) {
// gps_hw_off();
// }
}
5 changes: 4 additions & 1 deletion firmware/main/modules/gps/gps_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ void gps_module_unregister_cb();
void gps_module_general_data_run();

char* get_full_date_time(gps_t* gps);
char* get_str_date_time(gps_t* gps);
char* get_str_date_time(gps_t* gps);

void gps_module_check_state();
void gps_module_reset_state();
4 changes: 2 additions & 2 deletions firmware/main/modules/menus_module/menus_include/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ menu_t menus[] = { //////////////////////////////////
.menu_idx = MENU_GPS,
.parent_idx = MENU_APPLICATIONS,
.last_selected_submenu = 0,
.on_enter_cb = NULL,
.on_exit_cb = NULL,
.on_enter_cb = gps_module_check_state,
.on_exit_cb = gps_module_reset_state,
.is_visible = true},
#ifdef CONFIG_GPS_APP_WARDRIVING
{.display_name = "Wardriving",
Expand Down

0 comments on commit a2a8a0c

Please sign in to comment.