Open 32teeth opened 10 months ago
Introducing the Retro ESP32 X, the latest iteration of our Retro ESP32 series! 🚀🕹️
Open Source Hardware Certifications
Key Features
Updated Features
Authors: Eugene Yevhen Andruszczenko - 32teeth
License: This project is licensed under the Creative Commons Attribution Share Alike 4.0 International - see the LICENSE.md file for details.
Support: Although we do this for the love of gaming 🕹️, we also like coffee! Please consider supporting us through various sponsorship tiers with different rewards.
You should be able to use the menu struct
typedef struct MENU_ITEM_T
{
char label[30];
void (*action)();
struct MENU *submenu;
enum MenuItemType type;
bool selected;
int value;
} MENU_ITEM;
typedef struct MENU_T
{
MENU_ITEM *items;
bool locked;
int count;
} MENU;
#pragma region File
void file_paths()
{
sprintf(settings_file, "%s/%s/%s/%s", MOUNT_POINT, RETRO_ESP32X_FOLDER, USER_FOLDER, SETTINGS_FILE);
sprintf(favorites_file, "%s/%s/%s/%s", MOUNT_POINT, RETRO_ESP32X_FOLDER, USER_FOLDER, FAVORITES_FILE);
sprintf(recents_file, "%s/%s/%s/%s", MOUNT_POINT, RETRO_ESP32X_FOLDER, USER_FOLDER, RECENTS_FILE);
}
bool open_file(char file[256], char *mode)
{
f = fopen(file, mode);
if (f == NULL)
{
ESP_LOGE(MGB_TAG_DISK, "%s file not found!", file);
return false;
}
else
{
return true;
}
return false;
}
bool create_file(char file[256])
{
if (!open_file(file, "w+"))
{
ESP_LOGE(MGB_TAG_DISK, "%s file not created!", file);
return false;
}
else
{
ESP_LOGI(MGB_TAG_DISK, "%s file created!", file);
return true;
}
return false;
}
bool delete_file(char file[256])
{
return create_file(file);
}
bool check_file(char file[256])
{
if (!open_file(file, "rb"))
{
return create_file(file);
}
else
{
return true;
}
return false;
}
bool file_setup()
{
draw_progress(LOADING, 70);
bool settings_complete = check_file(settings_file);
draw_progress(LOADING, 80);
bool favorites_complete = check_file(favorites_file);
draw_progress(LOADING, 90);
bool recents_complete = check_file(recents_file);
return settings_complete && favorites_complete && recents_complete;
}
#pragma endregion File
#pragma region Read
void read_file(char file[256], char **ENTRIES)
{
free(ENTRIES);
ENTRIES = (char **)malloc((MAX_FILES_LIST) * sizeof(void *));
if (!open_file(file, "rb"))
{
if (create_file(file))
{
read_file(file, ENTRIES);
}
}
else
{
int count = 0;
char line[256];
while (fgets(line, sizeof(line), f))
{
char *row = &line[strlen(line) - 1];
while (*row == '\n' || *row == '\r')
{
*row-- = '\0';
}
size_t len = strlen(line);
ENTRIES[count] = (char *)malloc(len + 1);
strcpy(ENTRIES[count], line);
count++;
}
free(ENTRIES);
}
fclose(f);
}
#pragma endregion Read
#pragma region Add Entry
void add_entry(char file[256], char *entry, char **ENTRIES)
{
if (!open_file(file, "a+"))
{
if (create_file(file))
{
read_file(file, ENTRIES);
}
}
else
{
fprintf(f, "%s\n", entry);
}
fclose(f);
}
#pragma endregion Add Entry
#pragma region Remove Entry
void remove_entry(char file[256], char *entry, char **ENTRIES)
{
int n = 0;
int count = 0;
char line[256];
if (!open_file(file, "rb"))
{
if (create_file(file))
{
read_file(file, ENTRIES);
}
}
else
{
while (fgets(file, sizeof(line), f))
{
char *ep = &line[strlen(line) - 1];
while (*ep == '\n' || *ep == '\r')
{
*ep-- = '\0';
}
if (strcmp(entry, line) != 0)
{
size_t len = strlen(line);
ENTRIES[n] = (char *)malloc(len + 1);
strcpy(ENTRIES[n], line);
n++;
count++;
}
}
}
fclose(f);
struct stat st;
if (stat(file, &st) == 0)
{
unlink(file);
create_file(file);
for (n = 0; n < count; n++)
{
size_t len = strlen(ENTRIES[n]);
if (len > 0)
{
remove_entry(file, ENTRIES[n], ENTRIES);
}
}
}
}
#pragma endregion Remove Entry
Hype is REAL
#23
Description
in the settings section under themes in addition to being able to select one of the existing themes we should have a 'custom' theme when the use selects it is presented with an RGB slider. On changing the RGB slider we update the current theme.
AC