forked from Omega-Numworks/Omega-External
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmain.cpp
More file actions
97 lines (77 loc) · 3.89 KB
/
Copy pathmain.cpp
File metadata and controls
97 lines (77 loc) · 3.89 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <extapp_api.h>
#include "inc/peripherals.h"
#include "inc/selector.h"
extern "C" void extapp_main(int argc, char *argv[]);
void extapp_main(int argc, char * argv[]) {
// Wait for the key to be released before starting the application
Peripherals::waitForKeyReleased();
// Draw a white background
Peripherals::init_display();
// Draw hello world message
extapp_drawTextLarge("Hello World !", 0, 20 * 1, 0x0000, 0xFFFF, false);
extapp_drawTextLarge("Press any key to continue", 0, 20 * 2, 0x0000, 0xFFFF, false);
// Just wait for a key to be pressed (defined in peripherals.c)
Peripherals::waitForKeyPressed();
Peripherals::waitForKeyReleased();
// Select a file (The code is in selector.c)
// The code is a bit more complicated, but you can see how to use the file system API to read a file
const char * filename = Selector::select_file("", 10);
// Wait for the key to be released
Peripherals::waitForKeyReleased();
// Clear the screen
Peripherals::init_display();
// If no file was selected, exit the application
if (filename == NULL) {
Peripherals::init_display();
extapp_drawTextLarge("No file selected !", 0, 20 * 1, 0x0000, 0xFFFF, false);
extapp_drawTextLarge("Press any key to exit", 0, 20 * 2, 0x0000, 0xFFFF, false);
Peripherals::waitForKeyPressed();
Peripherals::waitForKeyReleased();
return;
}
// Show the selected file name
extapp_drawTextLarge("You selected :", 0, 20 * 1, 0x0000, 0xFFFF, false);
extapp_drawTextLarge(filename, 0, 20 * 2, 0x0000, 0xFFFF, false);
extapp_drawTextLarge("Reading file...", 0, 20 * 4, 0x0000, 0xFFFF, false);
// Initialize the file len variable that will be written by the file read function
size_t file_len = 0;
// Read the file into filecontent variable
const char * filecontent = extapp_fileRead(filename, &file_len, EXTAPP_FLASH_FILE_SYSTEM);
extapp_drawTextLarge("Press any key to show file", 0, 20 * 5, 0x0000, 0xFFFF, false);
extapp_drawTextLarge("content", 0, 20 * 6, 0x0000, 0xFFFF, false);
// Wait for a key to be pressed (defined in peripherals.c)
Peripherals::waitForKeyPressed();
Peripherals::waitForKeyReleased();
// Clear the screen
Peripherals::init_display();
extapp_drawTextLarge("File content :", 0, 20 * 1, 0x0000, 0xFFFF, false);
// It crashes on simulator, because Built-In app content is NULL
if (filecontent != NULL) {
extapp_drawTextLarge(filecontent, 0, 20 * 2, 0x0000, 0xFFFF, false);
} else {
extapp_drawTextLarge("File content is NULL", 0, 20 * 2, 0x0000, 0xFFFF, false);
}
extapp_drawTextLarge("Press any key to continue", 0, 20 * 3, 0x0000, 0xFFFF, false);
// Wait for a key to be pressed
Peripherals::waitForKeyPressed();
Peripherals::waitForKeyReleased();
// Clear the screen
Peripherals::init_display();
extapp_drawTextLarge("Writing file into ram filesystem...", 0, 20 * 1, 0x0000, 0xFFFF, false);
// Initialize the filename to write to the ram filesystem
const char * filename_to_write = "hello_world.py";
// Initialize the file content to write to the ram filesystem, add three spaces at the beginning
// because the Python app use the first character to store the auto importation status
const char * filecontent_to_write = " hello world";
// Write the file into the ram filesystem
extapp_fileWrite(filename_to_write, filecontent_to_write, strlen(filecontent_to_write) + 1, EXTAPP_RAM_FILE_SYSTEM);
extapp_drawTextLarge("File written to ram filesystem", 0, 20 * 2, 0x0000, 0xFFFF, false);
extapp_drawTextLarge("Press any key to exit", 0, 20 * 3, 0x0000, 0xFFFF, false);
// Wait for a key to be pressed before exiting the application
Peripherals::waitForKeyPressed();
Peripherals::waitForKeyReleased();
return;
}