forked from jblanked/Hello-World-Flipper-Zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.hpp
More file actions
78 lines (73 loc) · 5.29 KB
/
Copy pathapp.hpp
File metadata and controls
78 lines (73 loc) · 5.29 KB
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
#pragma once
#include "font/font.h"
#include "easy_flipper/easy_flipper.h"
#include "flipper_http/flipper_http.h"
#include "run/run.hpp"
#include "settings/settings.hpp"
#include "about/about.hpp"
#define TAG "Hello World"
#define VERSION "1.0"
#define VERSION_TAG TAG " " VERSION
#define APP_ID "hello_world"
typedef enum
{
HelloWorldSubmenuRun = 0,
HelloWorldSubmenuAbout = 1,
HelloWorldSubmenuSettings = 2,
} HelloWorldSubmenuIndex;
typedef enum
{
HelloWorldViewMain = 0,
HelloWorldViewSubmenu = 1,
HelloWorldViewAbout = 2,
HelloWorldViewSettings = 3,
HelloWorldViewTextInput = 4,
} HelloWorldView;
class HelloWorldApp
{
private:
std::unique_ptr<HelloWorldAbout> about; // About class instance
FlipperHTTP *flipperHttp = nullptr; // FlipperHTTP instance for HTTP requests
std::unique_ptr<HelloWorldRun> run; // Run class instance
std::unique_ptr<HelloWorldSettings> settings; // Settings class instance
Submenu *submenu = nullptr; // Submenu for the app
FuriTimer *timer = nullptr; // Timer for run updates
//
static uint32_t callbackExitApp(void *context); // Callback to exit the app
void callbackSubmenuChoices(uint32_t index); // Callback for submenu choices
void createAppDataPath(); // Create the app data path in storage
void settingsItemSelected(uint32_t index); // Handle settings item selection
static void submenuChoicesCallback(void *context, uint32_t index); // Callback for submenu choices
static void timerCallback(void *context); // Timer callback for run updates
public:
HelloWorldApp();
~HelloWorldApp();
//
Gui *gui = nullptr; // GUI instance for the app
ViewDispatcher *viewDispatcher = nullptr; // ViewDispatcher for managing views
ViewPort *viewPort = nullptr; // ViewPort for drawing and input handling (run instance)
//
size_t getBytesReceived() const noexcept { return flipperHttp ? flipperHttp->bytes_received : 0; } // get the number of bytes received
size_t getContentLength() const noexcept { return flipperHttp ? flipperHttp->content_length : 0; } // get the content length of the last response
HTTPState getHttpState() const noexcept { return flipperHttp ? flipperHttp->state : INACTIVE; } // get the HTTP state
FuriString *httpRequest( // synchronous HTTP request
const char *url, // URL to send the request to
HTTPMethod method = GET, // HTTP method to use (GET, POST, etc.)
const char *headers = "{\"Content-Type\": \"application/json\"}", // Headers to include in the request
const char *payload = nullptr); // Payload to send with the request (for POST, PUT, etc.)
bool httpRequestAsync( // asynchronous HTTP request (check the HttpState to see if the request is finished)
const char *saveLocation, // location to save the response (filename)
const char *url, // URL to send the request to
HTTPMethod method = GET, // HTTP method to use (GET, POST, etc.)
const char *headers = "{\"Content-Type\": \"application/json\"}", // Headers to include in the request
const char *payload = nullptr); // Payload to send with the request (for POST, PUT, etc.)
bool isBoardConnected(); // check if the board is connected
bool loadChar(const char *path_name, char *value, size_t value_size); // load a string from storage
bool loadFileChunk(const char *filePath, char *buffer, size_t sizeOfChunk, uint8_t iteration); // Load a file chunk from storage
void runDispatcher(); // run the app's view dispatcher to handle views and events
bool saveChar(const char *path_name, const char *value); // save a string to storage
bool setHttpState(HTTPState state = IDLE) noexcept; // set the HTTP state
bool sendWiFiCredentials(const char *ssid, const char *password); // send WiFi credentials to the board
static void viewPortDraw(Canvas *canvas, void *context); // draw callback for the ViewPort (used in run instance)
static void viewPortInput(InputEvent *event, void *context); // input callback for the ViewPort (used in run instance)
};