Skip to content

Commit b86dcf1

Browse files
committed
Mon 24 Feb 2020 14:13:37 EST - minor fixes
1 parent 72f9f14 commit b86dcf1

File tree

16 files changed

+1817
-733
lines changed

16 files changed

+1817
-733
lines changed

Components/go-play/odroid-go-common/components/odroid/odroid_hud.c

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#include <math.h>
88
#include <dirent.h>
99
#include <unistd.h>
10-
#include <ctype.h>
11-
#include <errno.h>
10+
#include <ctype.h>
11+
#include <errno.h>
1212

1313
/*
1414
General
15-
*/
15+
*/
1616
#include "freertos/FreeRTOS.h"
1717
#include "freertos/task.h"
1818
#include "nvs_flash.h"
@@ -52,7 +52,7 @@
5252

5353
//{#pragma region Globals
5454
#define WHITE 65535
55-
#define BLACK 0
55+
#define BLACK 0
5656
int OPTION = 0;
5757
extern int ACTION = 0;
5858
int OPTIONS = 3;
@@ -61,7 +61,7 @@
6161
int x, y, w, h, i, size;
6262
uint16_t *buffer;
6363
bool INIT = false;
64-
bool SAVED = false;
64+
bool SAVED = false;
6565
bool forceConsoleReset;
6666
//}#pragma endregion Globals
6767

@@ -72,7 +72,7 @@
7272
int w;
7373
int h;
7474
} SCR;
75-
SCR SCREEN = {0,0,320,240};
75+
SCR SCREEN = {0,0,320,240};
7676

7777
typedef struct{
7878
char label[20];
@@ -91,9 +91,9 @@
9191
{"Resume Game",0, 0},
9292
{"Restart Game",1, 10},
9393
{"Save Game",3, 25},
94-
{"Exit Game",6, 20}
95-
};
96-
STATES STATE;
94+
{"Exit Game",6, 20}
95+
};
96+
STATES STATE;
9797

9898
typedef struct{
9999
int bg;
@@ -125,7 +125,7 @@
125125
{29614,52857,"light"}
126126
};
127127
THEME GUI;
128-
//}#pragma endregion Structs
128+
//}#pragma endregion Structs
129129

130130
//{#pragma region Sprites
131131
const uint16_t FONT_5x7[7][250] = {
@@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = {
206206

207207
//{#pragma region Debounce
208208
void debounce(int key) {
209-
while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad);
209+
while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad);
210210
}
211211
//}#pragma endregion Debounce
212212

@@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = {
217217
ESP_ERROR_CHECK(nvs_flash_erase());
218218
err = nvs_flash_init();
219219
}
220-
ESP_ERROR_CHECK( err );
220+
ESP_ERROR_CHECK( err );
221221
nvs_handle handle;
222222
nvs_open("storage", NVS_READWRITE, &handle);
223223
nvs_set_i8(handle, "DELETE_SAVE", del);
224-
nvs_commit(handle);
225-
nvs_close(handle);
224+
nvs_commit(handle);
225+
nvs_close(handle);
226226
}
227227

228228
void hud_delete_save(char *file_to_delete) {
@@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = {
231231
ESP_ERROR_CHECK(nvs_flash_erase());
232232
err = nvs_flash_init();
233233
}
234-
ESP_ERROR_CHECK( err );
234+
ESP_ERROR_CHECK( err );
235235

236236
nvs_handle handle;
237237
err = nvs_open("storage", NVS_READWRITE, &handle);
@@ -244,28 +244,28 @@ const uint16_t FONT_5x7[7][250] = {
244244
break;
245245
default :
246246
DELETE_SAVE = 0;
247-
}
248-
nvs_close(handle);
249-
printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE);
247+
}
248+
nvs_close(handle);
249+
printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE);
250250
if(DELETE_SAVE == 1) {
251251
hud_prepare_delete(0);
252252
struct stat st;
253-
if (stat(file_to_delete, &st) == 0) {
253+
if (stat(file_to_delete, &st) == 0) {
254254
unlink(file_to_delete);
255255
esp_restart();
256-
}
257-
}
258-
}
256+
}
257+
}
258+
}
259259

260260
void hud_check_saves(char *save_name) {
261261
char * dir = strrchr(save_name, '.');
262262
char save_dir[256] = "/sd/odroid/data/";
263-
strcat(&save_dir[strlen(save_dir) - 1], dir+1);
264-
char file_to_delete[256] = "";
263+
strcat(&save_dir[strlen(save_dir) - 1], dir+1);
264+
char file_to_delete[256] = "";
265265
sprintf(file_to_delete, "%s/%s", save_dir, save_name);
266-
strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav");
267-
DIR *directory;
268-
directory = opendir(save_dir);
266+
strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav");
267+
DIR *directory;
268+
directory = opendir(save_dir);
269269
if(directory == NULL) {
270270
perror("opendir() error");
271271
} else {
@@ -278,14 +278,14 @@ const uint16_t FONT_5x7[7][250] = {
278278
gets(tmp);
279279
if(strcmp(save_name, tmp) == 0) {
280280
SAVED = true;
281-
printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp);
281+
printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp);
282282
hud_delete_save(file_to_delete);
283283
}
284-
}
284+
}
285285
closedir(directory);
286286
}
287287
}
288-
//}#pragma endregion Files
288+
//}#pragma endregion Files
289289

290290
//{#pragma region Text
291291
int hud_letter(char letter) {
@@ -346,7 +346,7 @@ const uint16_t FONT_5x7[7][250] = {
346346
ESP_ERROR_CHECK(nvs_flash_erase());
347347
err = nvs_flash_init();
348348
}
349-
ESP_ERROR_CHECK( err );
349+
ESP_ERROR_CHECK( err );
350350

351351
nvs_handle handle;
352352
err = nvs_open("storage", NVS_READWRITE, &handle);
@@ -360,10 +360,10 @@ const uint16_t FONT_5x7[7][250] = {
360360
break;
361361
default :
362362
USER = 0;
363-
}
363+
}
364364
nvs_close(handle);
365365
}
366-
//}#pragma endregion Theme
366+
//}#pragma endregion Theme
367367

368368
//{#pragma region Display
369369
void hud_logo() {
@@ -376,18 +376,18 @@ const uint16_t FONT_5x7[7][250] = {
376376
for(int c = 0; c < w; c++) {
377377
buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg;
378378
i++;
379-
}
380-
}
381-
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
379+
}
380+
}
381+
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
382382
//hud_text(x,y+18,"In Game Menu",false,false);
383-
}
383+
}
384384

385385
void hud_progress(char *string, bool bar) {
386386
hud_background();
387-
hud_logo();
387+
hud_logo();
388388
w = strlen(string)*5;
389389
x = (SCREEN.w/2)-(w/2);
390-
y = (SCREEN.h/2)-(h/2);
390+
y = (SCREEN.h/2)-(h/2);
391391
hud_text(x,y,string,false,false);
392392
if(bar) {
393393
y+=10;
@@ -397,88 +397,91 @@ const uint16_t FONT_5x7[7][250] = {
397397
}
398398
ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer);
399399
usleep(15000);
400-
}
400+
}
401401
}
402-
}
402+
}
403403

404404
void hud_options() {
405405
x = 16;
406-
y = 28;
406+
y = 28;
407407
w = 5;
408408
h = 5;
409409
i = 0;
410410
int n;
411411
if(OPTIONS == 6) {
412-
for(n = 0; n < OPTIONS; n++) {
412+
for(n = 0; n < OPTIONS; n++) {
413413
STATE = WITHSAVE[n];
414414
y+=20;
415415
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
416416
buffer[i] = icons[r+STATE.offset][c] == WHITE ? OPTION == n ? WHITE : GUI.fg : GUI.bg;i++;
417417
}}
418418
if(n == OPTIONS-1) {y = 216;}
419419
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
420-
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
420+
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
421421
i = 0;
422422
}
423423
STATE = WITHSAVE[OPTION];
424424
} else {
425-
for(n = 0; n < OPTIONS; n++) {
425+
for(n = 0; n < OPTIONS; n++) {
426426
STATE = WITHOUTSAVE[n];
427427
y+=20;
428428
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
429429
buffer[i] = icons[r+STATE.offset][c] == WHITE ? OPTION == n ? WHITE : GUI.fg : GUI.bg;i++;
430430
}}
431431
if(n == OPTIONS-1) {y = 216;}
432432
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
433-
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
434-
i = 0;
435-
}
436-
STATE = WITHOUTSAVE[OPTION];
433+
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
434+
i = 0;
435+
}
436+
STATE = WITHOUTSAVE[OPTION];
437437
}
438438
}
439-
//}#pragma endregion Display
439+
//}#pragma endregion Display
440440

441441
//{#pragma region Init
442-
void hud_init() {
442+
void hud_init() {
443443
if(!INIT) {
444444
size = 320 * 30 * sizeof(uint16_t);
445-
buffer = (uint16_t *)malloc(size);
446-
if (!buffer) abort();
447-
OPTION = 0;
445+
buffer = (uint16_t *)malloc(size);
446+
if (!buffer) abort();
447+
OPTION = 0;
448448
OPTIONS = SAVED ? 6 : 4;
449449
hud_theme();
450450
GUI = THEMES[USER];
451-
STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION];
451+
STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION];
452452
INIT = true;
453-
}
453+
}
454454
}
455455

456456
void hud_deinit() {
457457
size = 0;
458-
buffer = realloc(buffer, size);
458+
buffer = realloc(buffer, size);
459459
free(buffer);
460460
INIT = false;
461461
}
462-
//}#pragma endregion Init
462+
//}#pragma endregion Init
463463

464464
//{#pragma region Menu
465465
void hud_menu(void) {
466-
int volume = odroid_audio_volume_get();
466+
int volume = odroid_audio_volume_get();
467+
#ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32
468+
volume = 4;
469+
#endif
467470
odroid_audio_terminate();
468-
hud_init();
471+
hud_init();
469472
hud_debug("HUD - MENU");
470473
hud_background();
471474
hud_logo();
472475
hud_options();
473476
while(1) {
474477

475-
odroid_input_gamepad_read(&gamepad);
478+
odroid_input_gamepad_read(&gamepad);
476479
/*
477480
UP
478481
*/
479482
if (gamepad.values[ODROID_INPUT_UP]) {
480483
OPTION--;
481-
if( OPTION < 0 ) { OPTION = OPTIONS-1; }
484+
if( OPTION < 0 ) { OPTION = OPTIONS-1; }
482485
hud_options();
483486
usleep(200000);
484487
//debounce(ODROID_INPUT_UP);
@@ -488,10 +491,10 @@ const uint16_t FONT_5x7[7][250] = {
488491
*/
489492
if (gamepad.values[ODROID_INPUT_DOWN]) {
490493
OPTION++;
491-
if( OPTION >= OPTIONS ) { OPTION = 0; }
494+
if( OPTION >= OPTIONS ) { OPTION = 0; }
492495
hud_options();
493496
usleep(200000);
494-
//debounce(ODROID_INPUT_DOWN);
497+
//debounce(ODROID_INPUT_DOWN);
495498
}
496499
/*
497500
BUTTON B
@@ -500,13 +503,13 @@ const uint16_t FONT_5x7[7][250] = {
500503
ACTION = 0;
501504
debounce(ODROID_INPUT_B);
502505
return 0;
503-
}
506+
}
504507
/*
505508
BUTTON A
506509
*/
507510
if (gamepad.values[ODROID_INPUT_A]) {
508-
odroid_audio_volume_set(volume);
509-
hud_debug(STATE.label);
511+
odroid_audio_volume_set(volume);
512+
hud_debug(STATE.label);
510513
ACTION = STATE.action;
511514
switch(ACTION) {
512515
case 0: // "Resume Game"
@@ -516,7 +519,7 @@ const uint16_t FONT_5x7[7][250] = {
516519
case 1: // "Restart Game"
517520
odroid_settings_StartAction_set(1);
518521
forceConsoleReset = true;
519-
esp_restart();
522+
esp_restart();
520523
break;
521524
case 2: // "Reload Game"
522525
esp_restart();
@@ -530,16 +533,16 @@ const uint16_t FONT_5x7[7][250] = {
530533
hud_progress("Deleting...", true);
531534
hud_prepare_delete(1);
532535
ili9341_clear(0);
533-
esp_restart();
536+
esp_restart();
534537
//return 0;
535538
break;
536539
case 6: // "Exit Game"
537540
odroid_system_application_set(0);
538-
esp_restart();
539-
break;
541+
esp_restart();
542+
break;
540543
}
541544
debounce(ODROID_INPUT_A);
542545
}
543546
}
544547
}
545-
//}#pragma endregion Menu
548+
//}#pragma endregion Menu

0 commit comments

Comments
 (0)