-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac4aa5d
commit a2a8a0c
Showing
5 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
firmware/main/general/general_notification/general_notification.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
firmware/main/general/general_notification/general_notification.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters