-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrcwl_0516.c
104 lines (78 loc) · 3.1 KB
/
rcwl_0516.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
#include "rcwl_0516.h"
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <gui/elements.h>
#include <input/input.h>
#include <notification/notification_messages.h>
static void rcwl_0516_draw_callback(Canvas* canvas, void* ctx) {
furi_assert(ctx);
Rcwl_0516* app = ctx;
canvas_clear(canvas);
canvas_set_font(canvas, FontPrimary);
elements_multiline_text_aligned(canvas, 60, 17, AlignCenter, AlignTop, "Motion Status");
canvas_set_font(canvas, FontSecondary);
if(app->input_value){
furi_hal_light_set(LightRed, 255);
furi_hal_light_set(LightBlue, 0);
furi_hal_light_set(LightGreen, 0);
elements_multiline_text_aligned(
canvas, 60, 32, AlignCenter, AlignTop,"Motion Detection");
notification_message(app->notifications, &sequence_display_backlight_on);
}else {
elements_multiline_text_aligned(
canvas, 60, 32, AlignCenter, AlignTop,"No Motion");
notification_message(app->notifications, &sequence_display_backlight_off);
furi_hal_light_set(LightBlue, 255);
furi_hal_light_set(LightRed, 0);
furi_hal_light_set(LightGreen, 0);
}
}
static void rcwl_0516_input_callback(InputEvent* input_event, void* ctx) {
furi_assert(ctx);
FuriMessageQueue* event_queue = ctx;
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
}
Rcwl_0516* rcwl_0516_alloc() {
Rcwl_0516* app = malloc(sizeof(Rcwl_0516));
app->view_port = view_port_alloc();
app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
view_port_draw_callback_set(app->view_port, rcwl_0516_draw_callback, app);
view_port_input_callback_set(app->view_port, rcwl_0516_input_callback, app->event_queue);
app->gui = furi_record_open(RECORD_GUI);
gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
app->notifications = furi_record_open(RECORD_NOTIFICATION);
app->input_pin = &gpio_ext_pa7;
app->output_pin = &gpio_ext_pa6;
furi_hal_gpio_init(app->input_pin, GpioModeInput, GpioPullUp, GpioSpeedLow);
furi_hal_gpio_init(app->output_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
furi_hal_gpio_write(app->output_pin, false);
return app;
}
void rcwl_0516_free(Rcwl_0516* app) {
furi_assert(app);
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_hal_light_set(LightBlue, 0);
furi_hal_light_set(LightRed, 0);
furi_hal_light_set(LightGreen, 0);
}
int32_t rcwl_0516(void* p) {
UNUSED(p);
Rcwl_0516* app = rcwl_0516_alloc();
InputEvent event;
while(1) {
app->input_value = furi_hal_gpio_read(app->input_pin);
if(furi_message_queue_get(app->event_queue, &event, 100) == FuriStatusOk) {
if(event.key == InputKeyBack) {
if(event.type == InputTypePress) break;
}
}
}
rcwl_0516_free(app);
return 0;
}