-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.c
86 lines (74 loc) · 2.53 KB
/
app.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
// app.c
#include <flip_social.h> // Include the FlipSocialApp structure
#include <alloc/flip_social_alloc.h> // Include the allocation functions
/**
* @brief Entry point for the Hello World application.
* @details Initializes the app, runs the view dispatcher, and cleans up upon exit.
* @param p Input parameter - unused
* @return 0 to indicate success, -1 on failure
*/
int32_t main_flip_social(void *p)
{
UNUSED(p);
// Initialize the Hello World application
app_instance = flip_social_app_alloc();
if (!app_instance)
{
// Allocation failed
FURI_LOG_E(TAG, "Failed to allocate FlipSocialApp");
return -1; // Indicate failure
}
// check if board is connected (Derek Jamison)
uint8_t counter = 10;
// initialize the http
if (flipper_http_init(flipper_http_rx_callback, app_instance))
{
fhttp.state = INACTIVE; // set inactive for the ping
if (!flipper_http_ping())
{
FURI_LOG_E(TAG, "Failed to ping the device");
return -1;
}
// Try to wait for pong response.
while (fhttp.state == INACTIVE && --counter > 0)
{
FURI_LOG_D(TAG, "Waiting for PONG");
furi_delay_ms(100);
}
if (counter == 0)
{
easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
}
else
{
save_char("is_connected", "true");
}
flipper_http_deinit();
}
else
{
easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
}
// if counter is not 0, check notifications
if (counter != 0)
{
char is_connected[5];
char is_logged_in[5];
char is_notifications[5];
load_char("is_connected", is_connected, 5);
load_char("is_logged_in", is_logged_in, 5);
load_char("user_notifications", is_notifications, 5);
if (strcmp(is_connected, "true") == 0 &&
strcmp(is_notifications, "on") == 0 &&
strcmp(is_logged_in, "true") == 0)
{
flip_social_home_notification();
}
}
// Run the view dispatcher
view_dispatcher_run(app_instance->view_dispatcher);
// Free the resources used by the Hello World application
flip_social_app_free(app_instance);
// Return 0 to indicate success
return 0;
}