Skip to content

Commit

Permalink
Mon 24 Feb 2020 14:13:37 EST - minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
32teeth committed Feb 24, 2020
1 parent 72f9f14 commit b86dcf1
Show file tree
Hide file tree
Showing 16 changed files with 1,817 additions and 733 deletions.
147 changes: 75 additions & 72 deletions Components/go-play/odroid-go-common/components/odroid/odroid_hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <math.h>
#include <dirent.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <ctype.h>
#include <errno.h>

/*
General
*/
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs_flash.h"
Expand Down Expand Up @@ -52,7 +52,7 @@

//{#pragma region Globals
#define WHITE 65535
#define BLACK 0
#define BLACK 0
int OPTION = 0;
extern int ACTION = 0;
int OPTIONS = 3;
Expand All @@ -61,7 +61,7 @@
int x, y, w, h, i, size;
uint16_t *buffer;
bool INIT = false;
bool SAVED = false;
bool SAVED = false;
bool forceConsoleReset;
//}#pragma endregion Globals

Expand All @@ -72,7 +72,7 @@
int w;
int h;
} SCR;
SCR SCREEN = {0,0,320,240};
SCR SCREEN = {0,0,320,240};

typedef struct{
char label[20];
Expand All @@ -91,9 +91,9 @@
{"Resume Game",0, 0},
{"Restart Game",1, 10},
{"Save Game",3, 25},
{"Exit Game",6, 20}
};
STATES STATE;
{"Exit Game",6, 20}
};
STATES STATE;

typedef struct{
int bg;
Expand Down Expand Up @@ -125,7 +125,7 @@
{29614,52857,"light"}
};
THEME GUI;
//}#pragma endregion Structs
//}#pragma endregion Structs

//{#pragma region Sprites
const uint16_t FONT_5x7[7][250] = {
Expand Down Expand Up @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = {

//{#pragma region Debounce
void debounce(int key) {
while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad);
while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad);
}
//}#pragma endregion Debounce

Expand All @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );
ESP_ERROR_CHECK( err );
nvs_handle handle;
nvs_open("storage", NVS_READWRITE, &handle);
nvs_set_i8(handle, "DELETE_SAVE", del);
nvs_commit(handle);
nvs_close(handle);
nvs_commit(handle);
nvs_close(handle);
}

void hud_delete_save(char *file_to_delete) {
Expand All @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );
ESP_ERROR_CHECK( err );

nvs_handle handle;
err = nvs_open("storage", NVS_READWRITE, &handle);
Expand All @@ -244,28 +244,28 @@ const uint16_t FONT_5x7[7][250] = {
break;
default :
DELETE_SAVE = 0;
}
nvs_close(handle);
printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE);
}
nvs_close(handle);
printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE);
if(DELETE_SAVE == 1) {
hud_prepare_delete(0);
struct stat st;
if (stat(file_to_delete, &st) == 0) {
if (stat(file_to_delete, &st) == 0) {
unlink(file_to_delete);
esp_restart();
}
}
}
}
}
}

void hud_check_saves(char *save_name) {
char * dir = strrchr(save_name, '.');
char save_dir[256] = "/sd/odroid/data/";
strcat(&save_dir[strlen(save_dir) - 1], dir+1);
char file_to_delete[256] = "";
strcat(&save_dir[strlen(save_dir) - 1], dir+1);
char file_to_delete[256] = "";
sprintf(file_to_delete, "%s/%s", save_dir, save_name);
strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav");
DIR *directory;
directory = opendir(save_dir);
strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav");
DIR *directory;
directory = opendir(save_dir);
if(directory == NULL) {
perror("opendir() error");
} else {
Expand All @@ -278,14 +278,14 @@ const uint16_t FONT_5x7[7][250] = {
gets(tmp);
if(strcmp(save_name, tmp) == 0) {
SAVED = true;
printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp);
printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp);
hud_delete_save(file_to_delete);
}
}
}
closedir(directory);
}
}
//}#pragma endregion Files
//}#pragma endregion Files

//{#pragma region Text
int hud_letter(char letter) {
Expand Down Expand Up @@ -346,7 +346,7 @@ const uint16_t FONT_5x7[7][250] = {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );
ESP_ERROR_CHECK( err );

nvs_handle handle;
err = nvs_open("storage", NVS_READWRITE, &handle);
Expand All @@ -360,10 +360,10 @@ const uint16_t FONT_5x7[7][250] = {
break;
default :
USER = 0;
}
}
nvs_close(handle);
}
//}#pragma endregion Theme
//}#pragma endregion Theme

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

void hud_progress(char *string, bool bar) {
hud_background();
hud_logo();
hud_logo();
w = strlen(string)*5;
x = (SCREEN.w/2)-(w/2);
y = (SCREEN.h/2)-(h/2);
y = (SCREEN.h/2)-(h/2);
hud_text(x,y,string,false,false);
if(bar) {
y+=10;
Expand All @@ -397,88 +397,91 @@ const uint16_t FONT_5x7[7][250] = {
}
ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer);
usleep(15000);
}
}
}
}
}

void hud_options() {
x = 16;
y = 28;
y = 28;
w = 5;
h = 5;
i = 0;
int n;
if(OPTIONS == 6) {
for(n = 0; n < OPTIONS; n++) {
for(n = 0; n < OPTIONS; n++) {
STATE = WITHSAVE[n];
y+=20;
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
buffer[i] = icons[r+STATE.offset][c] == WHITE ? OPTION == n ? WHITE : GUI.fg : GUI.bg;i++;
}}
if(n == OPTIONS-1) {y = 216;}
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
i = 0;
}
STATE = WITHSAVE[OPTION];
} else {
for(n = 0; n < OPTIONS; n++) {
for(n = 0; n < OPTIONS; n++) {
STATE = WITHOUTSAVE[n];
y+=20;
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
buffer[i] = icons[r+STATE.offset][c] == WHITE ? OPTION == n ? WHITE : GUI.fg : GUI.bg;i++;
}}
if(n == OPTIONS-1) {y = 216;}
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
i = 0;
}
STATE = WITHOUTSAVE[OPTION];
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
i = 0;
}
STATE = WITHOUTSAVE[OPTION];
}
}
//}#pragma endregion Display
//}#pragma endregion Display

//{#pragma region Init
void hud_init() {
void hud_init() {
if(!INIT) {
size = 320 * 30 * sizeof(uint16_t);
buffer = (uint16_t *)malloc(size);
if (!buffer) abort();
OPTION = 0;
buffer = (uint16_t *)malloc(size);
if (!buffer) abort();
OPTION = 0;
OPTIONS = SAVED ? 6 : 4;
hud_theme();
GUI = THEMES[USER];
STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION];
STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION];
INIT = true;
}
}
}

void hud_deinit() {
size = 0;
buffer = realloc(buffer, size);
buffer = realloc(buffer, size);
free(buffer);
INIT = false;
}
//}#pragma endregion Init
//}#pragma endregion Init

//{#pragma region Menu
void hud_menu(void) {
int volume = odroid_audio_volume_get();
int volume = odroid_audio_volume_get();
#ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32
volume = 4;
#endif
odroid_audio_terminate();
hud_init();
hud_init();
hud_debug("HUD - MENU");
hud_background();
hud_logo();
hud_options();
while(1) {

odroid_input_gamepad_read(&gamepad);
odroid_input_gamepad_read(&gamepad);
/*
UP
*/
if (gamepad.values[ODROID_INPUT_UP]) {
OPTION--;
if( OPTION < 0 ) { OPTION = OPTIONS-1; }
if( OPTION < 0 ) { OPTION = OPTIONS-1; }
hud_options();
usleep(200000);
//debounce(ODROID_INPUT_UP);
Expand All @@ -488,10 +491,10 @@ const uint16_t FONT_5x7[7][250] = {
*/
if (gamepad.values[ODROID_INPUT_DOWN]) {
OPTION++;
if( OPTION >= OPTIONS ) { OPTION = 0; }
if( OPTION >= OPTIONS ) { OPTION = 0; }
hud_options();
usleep(200000);
//debounce(ODROID_INPUT_DOWN);
//debounce(ODROID_INPUT_DOWN);
}
/*
BUTTON B
Expand All @@ -500,13 +503,13 @@ const uint16_t FONT_5x7[7][250] = {
ACTION = 0;
debounce(ODROID_INPUT_B);
return 0;
}
}
/*
BUTTON A
*/
if (gamepad.values[ODROID_INPUT_A]) {
odroid_audio_volume_set(volume);
hud_debug(STATE.label);
odroid_audio_volume_set(volume);
hud_debug(STATE.label);
ACTION = STATE.action;
switch(ACTION) {
case 0: // "Resume Game"
Expand All @@ -516,7 +519,7 @@ const uint16_t FONT_5x7[7][250] = {
case 1: // "Restart Game"
odroid_settings_StartAction_set(1);
forceConsoleReset = true;
esp_restart();
esp_restart();
break;
case 2: // "Reload Game"
esp_restart();
Expand All @@ -530,16 +533,16 @@ const uint16_t FONT_5x7[7][250] = {
hud_progress("Deleting...", true);
hud_prepare_delete(1);
ili9341_clear(0);
esp_restart();
esp_restart();
//return 0;
break;
case 6: // "Exit Game"
odroid_system_application_set(0);
esp_restart();
break;
esp_restart();
break;
}
debounce(ODROID_INPUT_A);
}
}
}
//}#pragma endregion Menu
//}#pragma endregion Menu
Loading

0 comments on commit b86dcf1

Please sign in to comment.