Skip to content

Commit

Permalink
Merge pull request #59 from esp-cpp/feature/metadata-modification-tra…
Browse files Browse the repository at this point in the history
…cking

Feature/metadata modification tracking
  • Loading branch information
finger563 authored Jan 23, 2024
2 parents e907832 + 7af0f96 commit 83abe8e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 6 deletions.
Binary file added boxart/batman-forever-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/batman-forever-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion components/box-emu-hal/src/video_setting.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "box_emu_hal.hpp"

static std::atomic<VideoSetting> video_setting_{VideoSetting::ORIGINAL};
static std::atomic<VideoSetting> video_setting_{VideoSetting::FIT};

VideoSetting hal::get_video_setting() {
return video_setting_;
Expand Down
8 changes: 8 additions & 0 deletions components/gui/include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Gui {
struct Config {
play_haptic_fn play_haptic;
set_waveform_fn set_waveform;
std::string metadata_filename = "metadata.csv";
std::shared_ptr<espp::Display> display;
size_t stack_size_bytes = 6 * 1024;
espp::Logger::Verbosity log_level{espp::Logger::Verbosity::WARN};
Expand All @@ -31,6 +32,7 @@ class Gui {
explicit Gui(const Config& config)
: play_haptic_(config.play_haptic),
set_waveform_(config.set_waveform),
metadata_filename_(config.metadata_filename),
display_(config.display),
logger_({.tag="Gui", .level=config.log_level}) {
init_ui();
Expand Down Expand Up @@ -254,6 +256,12 @@ class Gui {
set_waveform_fn set_waveform_;
std::atomic<int> haptic_waveform_{12};

// info for tracking when the metadata was changed last. Right now we use the
// last modified time of the metadata file, but we could also use a hash of
// the metadata file
std::string metadata_filename_;
std::filesystem::file_time_type metadata_last_modified_;

std::atomic<bool> ready_to_play_{false};
std::atomic<bool> paused_{false};
std::shared_ptr<espp::Display> display_;
Expand Down
21 changes: 20 additions & 1 deletion components/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,31 @@ void Gui::clear_rom_list() {
}

void Gui::update_rom_list() {
// only do this if the metadata has changed since the last time we updated. We
// do this by checking the last modified time of the metadata file.
std::filesystem::path metadata_path(std::string(MOUNT_POINT) + "/" + metadata_filename_);
std::error_code ec;
auto metadata_last_modified = std::filesystem::last_write_time(metadata_path, ec);
if (ec) {
logger_.error("Error getting last modified time for {}: {}", metadata_path, ec.message());
return;
}
auto t = std::chrono::file_clock::to_sys(metadata_last_modified);
logger_.info("Last modified: {:%Y-%m-%d %H:%M:%S}", t);
if (metadata_last_modified == metadata_last_modified_) {
logger_.info("Metadata has not changed since last update");
// no change
return;
}
logger_.info("Metadata changed since last update, updating rom list");
metadata_last_modified_ = metadata_last_modified;

// protect since this function is called from another thread context
std::lock_guard<std::recursive_mutex> lk(mutex_);
// // clear the rom list
clear_rom_list();
// get the roms from the metadata
auto roms = parse_metadata("metadata.csv");
auto roms = parse_metadata(metadata_filename_);
// iterate through the list and get the rom and index for each
for (const auto& rom : roms) {
add_rom(rom);
Expand Down
14 changes: 12 additions & 2 deletions metadata.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
sms/ghouls-n-ghosts.sms, boxart/ghouls-n-ghosts-sms.jpg, Ghouls'n Ghosts
sms/ninja-gaiden.sms, boxart/Ninja+Gaiden+(Europe)-sms.jpg, Ninja Gaiden
sms/out-run.sms, boxart/Out+Run+sms.jpg, Out Run
sms/r-type.sms, boxart/R-Type-sms.jpg, R-Type
sms/Sonic The Hedgehog.sms, boxart/sonic_1_sms.jpg, Sonic The Hedgehog
sms/Sonic The Hedgehog 2.sms, boxart/sonic-the-hedgehog-2-sms.jpg, Sonic The Hedgehog 2
gg/Sonic The Hedgehog.gg, boxart/sonic_game_gear_box.jpg, Sonic The Hedgehog
gg/Sonic The Hedgehog 2.gg, boxart/sonic-the-hedgehog-2-gg.jpg, Sonic The Hedgehog 2
sms/wonder-boy-iii-dragons-trap.sms, boxart/wonder-boy-iii-dragon-trap-sms.jpg, Wonder Boy III: The Dragon's Trap
gg/adventures-of-batman-and-robin.gg, boxart/The-Adventures-of-Batman-and-Robin-Game-Gear.jpg, The Adventures of Batman & Robin
gg/Aladdin.gg, boxart/aladdin-gg.jpg, Aladdin
gg/Batman Forever.gg, boxart/batman-forever-gg.jpg, Batman Forever
gg/Jurassic Park.gg, boxart/jurassic-park-gg.jpg, Jurassic Park
gg/out-run.gg, boxart/Out+Run+(Europe)-gg.jpg, Out Run
gg/road-rash.gg, boxart/Road+Rash+(USA)-gg.jpg, Road Rash
gg/Sonic The Hedgehog.gg, boxart/sonic_game_gear_box.jpg, Sonic The Hedgehog
gg/Sonic The Hedgehog 2.gg, boxart/sonic-the-hedgehog-2-gg.jpg, Sonic The Hedgehog 2
gg/Star Trek Generations - Beyond the Nexus.gg, boxart/Star-Trek-Generations-Beyond-the-Nexus-gg.jpg, Star Trek Generations Beyond The Nexus
gg/streets-of-rage-ii.gg, boxart/StreetsofRage2-gg.jpg, Streets of Rage II
gg/wonder-boy-the-dragons-trap.gg, boxart/wonder-boy-iii-dragon-trap-gg.jpg, Wonder Boy III: The Dragon's Trap
msx/metal_gear.rom, boxart/mg1msxartwork_front.jpg, Metal Gear
msx/metal_gear_2.rom, boxart/mg2msxartwork.jpg, Metal Gear 2: Solid Snake
nes/mario.nes, boxart/mario.jpg, Mario Bros.
Expand Down
5 changes: 3 additions & 2 deletions sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=y

CONFIG_LV_BUILD_EXAMPLES=n

# NOTE: this will need to be increased if more menu / UI elements are added, or if there are a _lot_ of roms...
CONFIG_LV_MEM_SIZE_KILOBYTES=50
# NOTE: this will need to be increased if more menu / UI elements are added, or
# if there are a _lot_ of roms.
CONFIG_LV_MEM_SIZE_KILOBYTES=60

#
# LVGL configuration - # Color settings
Expand Down

0 comments on commit 83abe8e

Please sign in to comment.