Implements a complete serial upload workflow that allows uploading and immediately testing Lua games via USB serial connection. New Components: - SerialUploader: Receives files via serial, writes to SD card - upload_game.py: Python tool for sending files from host computer - Protocol: Text-based with base64 encoding for reliability Key Features: - Uploads file to /games folder on SD card - Overwrites existing files (FA_CREATE_ALWAYS) - Auto-launches uploaded game immediately - Proper memory cleanup (prevents Lua state conflicts) SD Card Fixes: - Fixed SPI speed management (12.5MHz for SD, 32MHz for display) - Fixed SD write protocol (poll for data response token) - Added speed switching wrappers around all FatFS operations - Cleaned up excessive debug output Game Launcher Improvements: - Added clear_games() to prevent duplicate registrations - Added cleanup in select_game_by_name() to delete old instances - Added exact match priority in game selection - LuaGameLoader now has clear_factory_data() for memory cleanup Integration: - Added serial_uploader to CMakeLists.txt - Integrated into main loop in basic1.cpp - Re-scans games after upload to pick up new files Documentation: - UPLOAD_TOOL.md: Usage instructions - sd_card_best_practices.md: Critical lessons learned Known Issues: - Game launch after upload occasionally causes freeze (needs investigation) - Display may not refresh properly after upload Usage: python upload_game.py games/lua_examples/2048.lua /dev/tty.usbmodem101 Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
// ============================================================================
|
|
// LUA GAME LOADER - HEADER
|
|
// ============================================================================
|
|
// Scans SD card for .lua game scripts and registers them with GameLauncher
|
|
|
|
#ifndef LUA_GAME_LOADER_H
|
|
#define LUA_GAME_LOADER_H
|
|
|
|
#include "../lib/game_launcher.h"
|
|
|
|
/**
|
|
* @brief Lua Game Loader - discovers and registers Lua games from SD card
|
|
*/
|
|
class LuaGameLoader {
|
|
public:
|
|
/**
|
|
* @brief Scan SD card /games directory and register all .lua files
|
|
* @param launcher GameLauncher to register games with
|
|
* @return Number of Lua games found and registered
|
|
*/
|
|
static int register_all_games(GameLauncher* launcher);
|
|
|
|
/**
|
|
* @brief Clear all factory data (useful before re-scanning)
|
|
*/
|
|
static void clear_factory_data();
|
|
|
|
private:
|
|
/**
|
|
* @brief Parse metadata from Lua script comments
|
|
* @param script_path Path to .lua file
|
|
* @param name Output: game name (default: filename)
|
|
* @param description Output: game description (default: empty)
|
|
* @return true if file could be read
|
|
*/
|
|
static bool parse_metadata(const char* script_path, char* name, char* description);
|
|
|
|
/**
|
|
* @brief Factory function for creating LuaGame instances
|
|
*/
|
|
static Game* create_lua_game(const char* script_path, uint16_t width, uint16_t height,
|
|
LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager);
|
|
};
|
|
|
|
#endif // LUA_GAME_LOADER_H
|