Skip to content

Commit 9fba546

Browse files
committed
Tue 25 Feb 2020 23:54:59 EST - working on favorites
1 parent 67627aa commit 9fba546

File tree

7 files changed

+136
-22
lines changed

7 files changed

+136
-22
lines changed

Assets/retro-esp32/icons/icons.gif

35 Bytes
Loading

Launchers/retro-esp32/main/includes/declarations.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ void has_save_file(char *save_name);
9898
/*
9999
Favorites
100100
*/
101-
void has_fav_file();
101+
void create_favorites();
102+
void read_favorites();
103+
void add_favorite(char *string);
104+
void delete_favorite(char *favorite);
105+
void is_favorite(char *string);
102106

103107

104108
/*

Launchers/retro-esp32/main/includes/definitions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434

3535
/*
3636
37+
*/
38+
#define FAVFILE "retro-esp32.txt"
39+
40+
/*
41+
3742
*/
3843
#define BUILD "Version 2 Build 1 (v.2.1)"
3944

Launchers/retro-esp32/main/includes/structures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef struct{
3232
char art[256];
3333
uint32_t crc;
3434
bool ready;
35+
bool favorite;
3536
} LOAD;
3637
LOAD ROM;
3738

Launchers/retro-esp32/main/main.c

Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
uint32_t currentDuty;
3434

3535
char** FILES;
36+
char** FAVORITES;
37+
char FAVORITE[256] = "";
38+
3639
char folder_path[256] = "";
3740

3841
DIR *directory;
@@ -130,7 +133,7 @@
130133

131134
// SD
132135
odroid_sdcard_open("/sd");
133-
has_fav_file();
136+
create_favorites();
134137

135138
// Theme
136139
get_theme();
@@ -906,7 +909,7 @@
906909

907910
void draw_launcher_options() {
908911
has_save_file(ROM.name);
909-
912+
is_favorite(ROM.name);
910913
int x = GAP/3 + 32;
911914
int y = POS.y + 48;
912915
int w = 5;
@@ -945,11 +948,22 @@
945948
i = 0;
946949
offset = 0;
947950
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
948-
buffer[i] = icons[r+offset][c] == WHITE ? WHITE : GUI.bg;i++;
951+
buffer[i] = icons[r+offset][c] == WHITE ? OPTION == 0 ? WHITE : GUI.fg : GUI.bg;i++;
949952
}}
950953
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
951-
draw_text(x+10,y,"Run",false,true, false);
954+
draw_text(x+10,y,"Run",false,OPTION == 0?true:false, false);
952955
}
956+
957+
// favorites
958+
y+=20;
959+
i = 0;
960+
offset = ROM.favorite?40:35;
961+
int option = SAVED ? 3 : 1;
962+
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
963+
buffer[i] = icons[r+offset][c] == WHITE ? OPTION == option ? WHITE : GUI.fg : GUI.bg;i++;
964+
}}
965+
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
966+
draw_text(x+10,y,ROM.favorite?"Unfavorite":"Favorite",false,OPTION == option?true:false, false);
953967
}
954968
//}#pragma endregion GUI
955969

@@ -1225,24 +1239,94 @@
12251239
//}#pragma endregion Files
12261240

12271241
//{#pragma region Favorites
1228-
void handle_line(char *line) {
1229-
printf("\n%s\n", line);
1230-
}
12311242

1232-
void has_fav_file() {
1233-
printf("\n----- %s -----\n", __func__);
1243+
void create_favorites() {
1244+
printf("\n----- %s START -----", __func__);
12341245
char file[256] = "/sd/odroid/data";
1235-
sprintf(file, "%s/%s", file, "retro_esp32.txt");
1246+
sprintf(file, "%s/%s", file, FAVFILE);
12361247

12371248
FILE *f;
12381249
f = fopen(file, "rb");
12391250
if(f == NULL) {
1240-
f = fopen(file, "wb");
1241-
fprintf(f, "Favorites List");
1251+
f = fopen(file, "w+");
1252+
printf("\nCREATING: %s", file);
1253+
/*
1254+
Castlevania Adventure, The (U).gb
1255+
Legend of Zelda, The - Oracle of Seasons (USA).gbc
1256+
Mega Man 2 (USA).nes
1257+
*/
12421258
} else {
1259+
read_favorites();
1260+
}
1261+
printf("\nCLOSING: %s", file);
1262+
fclose(f);
1263+
printf("\n----- %s END -----\n", __func__);
1264+
}
1265+
1266+
void read_favorites() {
1267+
printf("\n----- %s START -----", __func__);
1268+
1269+
char file[256] = "/sd/odroid/data";
1270+
sprintf(file, "%s/%s", file, FAVFILE);
1271+
1272+
FILE *f;
1273+
f = fopen(file, "rb");
1274+
if(f) {
1275+
printf("\nREADING: %s\n", file);
1276+
char line[256];
1277+
while (fgets(line, sizeof(line), f)) {
1278+
printf("%s", line);
1279+
}
1280+
}
1281+
fclose(f);
1282+
1283+
printf("\n----- %s END -----\n", __func__);
1284+
}
12431285

1286+
void add_favorite(char *favorite) {
1287+
printf("\n----- %s START -----", __func__);
1288+
char file[256] = "/sd/odroid/data";
1289+
sprintf(file, "%s/%s", file, FAVFILE);
1290+
1291+
FILE *f;
1292+
f = fopen(file, "a+");
1293+
if(f) {
1294+
printf("\nADDING: %s to %s", favorite, file);
1295+
fprintf(f, "%s\n", favorite);
1296+
}
1297+
fclose(f);
1298+
printf("\n----- %s END -----\n", __func__);
1299+
}
1300+
1301+
void delete_favorite(char *favorite) {
1302+
printf("\n----- %s START -----", __func__);
1303+
printf("\n----- %s END -----\n", __func__);
1304+
}
1305+
1306+
void is_favorite(char *favorite) {
1307+
printf("\n----- %s START -----", __func__);
1308+
ROM.favorite = false;
1309+
1310+
char file[256] = "/sd/odroid/data";
1311+
sprintf(file, "%s/%s", file, FAVFILE);
1312+
1313+
1314+
FILE *f;
1315+
f = fopen(file, "rb");
1316+
if(f) {
1317+
printf("\nCHECKING: %s\n", favorite);
1318+
char line[256];
1319+
while (fgets(line, sizeof(line), f)) {
1320+
char *ep = &line[strlen(line)-1];
1321+
while (*ep == '\n' || *ep == '\r'){*ep-- = '\0';}
1322+
printf("\nfavorite:%s line:%s match:%d", favorite, line, strcmp(favorite, line));
1323+
if(strcmp(favorite, line) == 0) {
1324+
ROM.favorite = true;
1325+
}
1326+
}
12441327
}
12451328
fclose(f);
1329+
printf("\n----- %s END -----\n", __func__);
12461330
}
12471331
//}#pragma endregion Favorites
12481332

@@ -1717,9 +1801,10 @@ void handle_line(char *line) {
17171801
seek_files();
17181802
}
17191803
} else {
1804+
int min = SAVED ? 3 : 1;
17201805
if(SAVED) {
17211806
OPTION--;
1722-
if( OPTION < 0 ) { OPTION = 2; }
1807+
if( OPTION < 0 ) { OPTION = min; }
17231808
draw_launcher_options();
17241809
}
17251810
}
@@ -1750,11 +1835,10 @@ void handle_line(char *line) {
17501835
seek_files();
17511836
}
17521837
} else {
1753-
if(SAVED) {
1754-
OPTION++;
1755-
if( OPTION > 2 ) { OPTION = 0; }
1756-
draw_launcher_options();
1757-
}
1838+
int max = SAVED ? 3 : 1;
1839+
OPTION++;
1840+
if( OPTION > max ) { OPTION = 0; }
1841+
draw_launcher_options();
17581842
}
17591843

17601844
usleep(200000);
@@ -1864,11 +1948,16 @@ void handle_line(char *line) {
18641948
SAVED ? rom_resume() : rom_run(false);
18651949
break;
18661950
case 1:
1867-
rom_run(true);
1951+
SAVED ? rom_run(true) : add_favorite(ROM.name);
1952+
if(!SAVED) {draw_launcher_options();}
18681953
break;
18691954
case 2:
18701955
rom_delete_save();
18711956
break;
1957+
case 3:
1958+
add_favorite(ROM.name);
1959+
draw_launcher_options();
1960+
break;
18721961
}
18731962
}
18741963
}

Launchers/retro-esp32/main/sprites/icons.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const uint16_t icons[30][5] = {
1+
const uint16_t icons[45][5] = {
22
{0,65535,65535,0,0},
33
{0,65535,65535,65535,0},
44
{0,65535,65535,65535,65535},
@@ -29,4 +29,19 @@ const uint16_t icons[30][5] = {
2929
{0,0,0,65535,0},
3030
{65535,0,65535,0,0},
3131
{0,65535,0,0,0},
32+
{0,65535,65535,65535,0},
33+
{65535,0,65535,0,65535},
34+
{65535,0,65535,65535,65535},
35+
{65535,0,0,0,65535},
36+
{0,65535,65535,65535,0},
37+
{0,65535,0,65535,0},
38+
{65535,65535,65535,65535,65535},
39+
{65535,65535,65535,65535,65535},
40+
{0,65535,65535,65535,0},
41+
{0,0,65535,0,0},
42+
{0,65535,0,65535,0},
43+
{65535,0,65535,0,65535},
44+
{65535,0,0,0,65535},
45+
{0,65535,0,65535,0},
46+
{0,0,65535,0,0},
3247
};

Odroid/odroid-go-firmware

0 commit comments

Comments
 (0)