-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF0App.c
118 lines (105 loc) · 4.16 KB
/
F0App.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "F0App.h"
F0App* FApp = 0;
static void F0App_timer_callback(void* ctx) {
InputEvent event = {.type = InputTypeMAX, .key = 255};
furi_message_queue_put((FuriMessageQueue*)ctx, &event, 0);
}
static void F0App_draw_callback(Canvas* canvas, void* ctx) {
if(furi_mutex_acquire(FApp->mutex, 200) != FuriStatusOk) return;
Draw(canvas, ctx);
furi_mutex_release(FApp->mutex);
}
static void F0App_input_callback(InputEvent* input_event, void* ctx) {
furi_assert(ctx);
furi_message_queue_put((FuriMessageQueue*)ctx, input_event, FuriWaitForever);
}
int32_t F0App_entry(void* p) {
UNUSED(p);
F0App* app = malloc(sizeof(F0App));
app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
if(app->event_queue == NULL) return 255;
app->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(app->mutex == NULL) {
furi_message_queue_free(app->event_queue);
return 255;
}
app->timer = furi_timer_alloc(F0App_timer_callback, FuriTimerTypePeriodic, app->event_queue);
if(app->timer == NULL) {
furi_mutex_free(app->mutex);
furi_message_queue_free(app->event_queue);
return 255;
}
furi_timer_start(app->timer, furi_kernel_get_tick_frequency());
app->view_port = view_port_alloc();
view_port_draw_callback_set(app->view_port, F0App_draw_callback, NULL);
view_port_input_callback_set(app->view_port, F0App_input_callback, app->event_queue);
app->gui = furi_record_open(RECORD_GUI);
app->Notificator = furi_record_open(RECORD_NOTIFICATION);
gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
FApp = app;
app->SystemScreenBrightness = app->Notificator->settings.display_brightness;
app->SystemLedBrightness = app->Notificator->settings.led_brightness;
AppInit();
InputEvent event;
while(1) {
AppWork();
if(furi_message_queue_get(app->event_queue, &event, 100) == FuriStatusOk) {
if(furi_mutex_acquire(app->mutex, FuriWaitForever) != FuriStatusOk) continue;
if(KeyProc(event.type, event.key) == 255)
break;
else
UpdateView();
furi_mutex_release(app->mutex);
}
}
furi_timer_stop(app->timer);
AppDeinit();
view_port_enabled_set(app->view_port, false);
gui_remove_view_port(app->gui, app->view_port);
view_port_free(app->view_port);
furi_message_queue_free(app->event_queue);
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION);
furi_timer_free(app->timer);
furi_mutex_free(app->mutex);
free(app);
return 0;
}
void SetLED(int r, int g, int b, float br) {
NotificationMessage notification_led_message_1;
notification_led_message_1.type = NotificationMessageTypeLedRed;
NotificationMessage notification_led_message_2;
notification_led_message_2.type = NotificationMessageTypeLedGreen;
NotificationMessage notification_led_message_3;
notification_led_message_3.type = NotificationMessageTypeLedBlue;
notification_led_message_1.data.led.value = r;
notification_led_message_2.data.led.value = g;
notification_led_message_3.data.led.value = b;
const NotificationSequence notification_sequence = {
¬ification_led_message_1,
¬ification_led_message_2,
¬ification_led_message_3,
&message_do_not_reset,
NULL,
};
FApp->Notificator->settings.led_brightness = br;
notification_message(FApp->Notificator, ¬ification_sequence);
furi_thread_flags_wait(0, FuriFlagWaitAny, 10);
}
void ResetLED() {
FApp->Notificator->settings.led_brightness = FApp->SystemLedBrightness;
notification_message(FApp->Notificator, &sequence_reset_rgb);
furi_thread_flags_wait(
0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
}
/*brightness in % (0-100)*/
void SetScreenBacklightBrightness(int brightness) {
FApp->Notificator->settings.display_brightness = (float)(brightness / 100.f);
notification_message(FApp->Notificator, &sequence_display_backlight_on);
}
void UpdateView() {
view_port_update(FApp->view_port);
}
bool PinRead(GpioPin pin) {
return furi_hal_gpio_read(&pin);
}