diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e50314c..4cee09f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -38,12 +38,6 @@ jobs: - name: Install PlatformIO run: pip install --upgrade platformio - - name: Build release - run: pio run -e release - - - name: Run tests - run: pio test --environment native - - name: Determine next SemVer from PR labels id: semver run: bash .github/scripts/compute-semver.sh @@ -56,11 +50,19 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build release + run: pio run -e release + env: + LUMENLAB_VERSION: ${{ steps.semver.outputs.tag }} + + - name: Run tests + run: pio test --environment native + - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: ${{ steps.semver.outputs.tag }} - name: ${{ steps.pr_details.outputs.title }} + name: ${{ steps.semver.outputs.tag }} - ${{ steps.pr_details.outputs.title }} body: ${{ steps.pr_details.outputs.body }} files: | .pio/build/release/firmware.bin diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 342cb4f..70e6ec4 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -127,14 +127,8 @@ { "label": "LumenLab - Upload (release)", "type": "shell", - "command": "platformio", - "args": [ - "run", - "-e", - "release", - "--target", - "upload" - ], + "command": "export LUMENLAB_VERSION=v999.999.999 && platformio run -e release --target upload", + // Alternative command to align with prod releases: "export LUMENLAB_VERSION=$(git describe --tags --abbrev=0) && platformio run -e release --target upload", "problemMatcher": [ "$platformio" ], diff --git a/include/core/configuration.h b/include/core/configuration.h index 779a71f..ba283ff 100644 --- a/include/core/configuration.h +++ b/include/core/configuration.h @@ -1,16 +1,28 @@ #pragma once +#include +#include #include namespace SystemCore { - struct Configuration + class Configuration { - // REQUIRED: modify this address to match the mac address of your PS3 controller - static constexpr char macAddress[] = "00:1b:fb:8e:87:ac"; - static constexpr uint16_t numLeds = 327; - static constexpr uint32_t serialBaud = 921600; - static constexpr uint16_t recallBoundaries[4] = {0, 113, 168, 281}; - static constexpr uint8_t ledDimmerGpio = 34; + public: + static const String &version() { return _version; } + static const String &macAddress() { return _macAddress; } + static uint16_t numLeds() { return _numLeds; } + static uint32_t serialBaud() { return _serialBaud; } + static const std::array &recallBoundaries() { return _recallBoundaries; } + static constexpr uint8_t ledDimmerGpio = 34; // set from PCB design, should not be configurable + + static void load(::Preferences &memory); + + private: + static String _version; + static String _macAddress; + static uint16_t _numLeds; + static uint32_t _serialBaud; + static std::array _recallBoundaries; }; } \ No newline at end of file diff --git a/include/display/display.h b/include/display/display.h index e54e38f..4bb703e 100644 --- a/include/display/display.h +++ b/include/display/display.h @@ -38,7 +38,6 @@ namespace Display char selectedOption(uint8_t index, uint8_t selectedOptionIndex) { return index == selectedOptionIndex ? '>' : ' '; }; int16_t calculateCenterText(const char *text); - void drawLogo(); void drawHeader(const char *message); void drawBootScreen(); void drawMainMenu(); diff --git a/include/games/phase-evasion/driver.h b/include/games/phase-evasion/driver.h index 0a3f181..4643945 100644 --- a/include/games/phase-evasion/driver.h +++ b/include/games/phase-evasion/driver.h @@ -22,7 +22,7 @@ namespace Games::PhaseEvasion private: SystemCore::ContextManager *contextManager; - GameState &state = contextManager->stateManager.getPhaseEvasionGameState(); + GameState &state; Player player; FlareManager flareManager; diff --git a/include/games/phase-evasion/flare-manager.h b/include/games/phase-evasion/flare-manager.h index db986c7..4320333 100644 --- a/include/games/phase-evasion/flare-manager.h +++ b/include/games/phase-evasion/flare-manager.h @@ -28,6 +28,6 @@ namespace Games::PhaseEvasion private: SystemCore::ContextManager *contextManager; - std::array flarePool; + std::array flarePool; }; } \ No newline at end of file diff --git a/include/games/phase-evasion/gem.h b/include/games/phase-evasion/gem.h index 0d60774..96359e4 100644 --- a/include/games/phase-evasion/gem.h +++ b/include/games/phase-evasion/gem.h @@ -22,7 +22,7 @@ namespace Games::PhaseEvasion void spawn(const uint16_t pos) { bool isOutsideLeftRegion = pos < (width - 1); - bool isOutsideRightRegion = pos > SystemCore::Configuration::numLeds + (width - 1); + bool isOutsideRightRegion = pos > SystemCore::Configuration::numLeds() + (width - 1); if (isOutsideLeftRegion || isOutsideRightRegion) return; diff --git a/include/games/phase-evasion/state.h b/include/games/phase-evasion/state.h index 522e581..4427cfe 100644 --- a/include/games/phase-evasion/state.h +++ b/include/games/phase-evasion/state.h @@ -29,6 +29,7 @@ namespace Games::PhaseEvasion static constexpr const char *memoryKeyName = "phase-high"; void reset(); + void loadHighScore(); uint16_t calculateTotalScore() const; void checkHighScore(); void updateHighScore(); diff --git a/include/games/recall/driver.h b/include/games/recall/driver.h index bdf4509..89206af 100644 --- a/include/games/recall/driver.h +++ b/include/games/recall/driver.h @@ -18,7 +18,7 @@ namespace Games::Recall private: SystemCore::ContextManager *contextManager; - GameState &state = contextManager->stateManager.getRecallGameState(); + GameState &state; uint16_t gameplaySpeedIlluminated = 500; uint16_t gameplaySpeedPaused = gameplaySpeedIlluminated / 6; diff --git a/include/games/recall/state.h b/include/games/recall/state.h index 1cbf4b5..c57c0c9 100644 --- a/include/games/recall/state.h +++ b/include/games/recall/state.h @@ -22,13 +22,14 @@ namespace Games::Recall class GameState { public: - GameState(SystemCore::ContextManager *ctx); + GameState(SystemCore::ContextManager *ctx) : contextManager{ctx} {} uint16_t highScore; uint16_t round; Actions current = Actions::Startup; static constexpr const char *memoryKeyName = "recall-high"; void reset(); + void loadHighScore(); void incrementScore(); void updateHighScore(); diff --git a/include/lights/led-buffer.h b/include/lights/led-buffer.h index 67396ef..aee169f 100644 --- a/include/lights/led-buffer.h +++ b/include/lights/led-buffer.h @@ -9,7 +9,7 @@ namespace Lights class LedBuffer { public: - LedBuffer() : leds{new Color[SystemCore::Configuration::numLeds]} {} + LedBuffer() : leds{new Color[SystemCore::Configuration::numLeds()]} {} ~LedBuffer() { delete leds; } LedBuffer(LedBuffer &&other) = delete; LedBuffer &operator=(LedBuffer &&other) = delete; @@ -22,7 +22,7 @@ namespace Lights explicit operator Color *() { return leds; } explicit operator const Color *() const { return leds; } - uint16_t size() { return SystemCore::Configuration::numLeds; } + uint16_t size() { return SystemCore::Configuration::numLeds(); } private: Color *leds; diff --git a/include/lights/led-strip.h b/include/lights/led-strip.h index db2ffe6..4289f18 100644 --- a/include/lights/led-strip.h +++ b/include/lights/led-strip.h @@ -14,7 +14,7 @@ namespace Lights LedBuffer buffer; Color *getRawColors(); - static constexpr uint16_t size() { return SystemCore::Configuration::numLeds; } + static const uint16_t size() { return SystemCore::Configuration::numLeds(); } void reset(); void adjustLuminance(); diff --git a/include/player/controller.h b/include/player/controller.h index 42d7943..a05e0c1 100644 --- a/include/player/controller.h +++ b/include/player/controller.h @@ -36,7 +36,7 @@ namespace Player { public: Controller() { instance = this; } - void begin(const char *macAddress); + void begin(String macAddress); uint8_t cross() { return instance->controller.data.analog.button.cross; } uint8_t circle() { return instance->controller.data.analog.button.circle; } diff --git a/include/scenes/canvas/driver.h b/include/scenes/canvas/driver.h index 5e20db0..a3e2fa1 100644 --- a/include/scenes/canvas/driver.h +++ b/include/scenes/canvas/driver.h @@ -14,7 +14,7 @@ namespace Scenes::Canvas private: SystemCore::ContextManager *contextManager; - SceneState &state = contextManager->stateManager.getCanvasSceneState(); + SceneState &state; Lights::ColorHsl colorHsl; bool hasChange = false; bool controllerWasActive = false; diff --git a/platformio.ini b/platformio.ini index 6bf75eb..3db7412 100644 --- a/platformio.ini +++ b/platformio.ini @@ -40,10 +40,13 @@ build_flags = -g -DDEBUG -std=gnu++2a platform = espressif32 board = upesy_wroom framework = arduino -lib_ignore = debug-fastled build_type = release build_unflags = -std=gnu++11 -build_flags = -Os -DRELEASE -std=gnu++2a +build_flags = + -Os + -DRELEASE + -std=gnu++2a + -DLUMENLAB_VERSION=\"${sysenv.LUMENLAB_VERSION}\" [env:native] platform = native diff --git a/src/core/configuration.cpp b/src/core/configuration.cpp new file mode 100644 index 0000000..36137ac --- /dev/null +++ b/src/core/configuration.cpp @@ -0,0 +1,27 @@ +#include "core/configuration.h" +#include + +#ifndef LUMENLAB_VERSION +#define LUMENLAB_VERSION "v999.999.999" +#endif + +namespace SystemCore +{ + String Configuration::_version; + String Configuration::_macAddress; + uint16_t Configuration::_numLeds; + uint32_t Configuration::_serialBaud; + std::array Configuration::_recallBoundaries; + + void Configuration::load(::Preferences &memory) + { + _version = LUMENLAB_VERSION; + _macAddress = memory.getString("macAddress", "00:00:00:00:00:00"); + _numLeds = static_cast(memory.getString("numLeds", "300").toInt()); + _serialBaud = static_cast(memory.getString("serialBaud", "921600").toInt()); + + _recallBoundaries[0] = static_cast(memory.getString("boundary_1", "75").toInt()); + _recallBoundaries[1] = static_cast(memory.getString("boundary_2", "150").toInt()); + _recallBoundaries[2] = static_cast(memory.getString("boundary_3", "225").toInt()); + } +} \ No newline at end of file diff --git a/src/core/context-manager.cpp b/src/core/context-manager.cpp index 983f5b1..76823af 100644 --- a/src/core/context-manager.cpp +++ b/src/core/context-manager.cpp @@ -7,9 +7,16 @@ namespace SystemCore { - ContextManager::ContextManager() : display{this}, stateManager{this}, menuNav{this} {} + ContextManager::ContextManager() : display{this}, stateManager{this}, menuNav{this} + { +#ifdef RELEASE + memory.begin("lumenlab", false); +#else + memory.begin("lumenlab-dev", false); +#endif + } - ContextManager::~ContextManager() + ContextManager::~ContextManager() { if (application) { diff --git a/src/display/display.cpp b/src/display/display.cpp index caa508a..000f937 100644 --- a/src/display/display.cpp +++ b/src/display/display.cpp @@ -81,13 +81,10 @@ namespace Display display.print(message); } - void OledDisplay::drawLogo() - { - } - void OledDisplay::drawBootScreen() { display.clearDisplay(); + drawHeader("LumenLab"); display.drawBitmap(initLogo.xPos, initLogo.yPos, initLogo.rawValues, initLogo.width, initLogo.height, SSD1306_WHITE); diff --git a/src/display/menu-navigation.cpp b/src/display/menu-navigation.cpp index 03031fa..1188f4c 100644 --- a/src/display/menu-navigation.cpp +++ b/src/display/menu-navigation.cpp @@ -10,7 +10,7 @@ namespace Display Engine::MainMenuSelection modeSelected = contextManager->stateManager.getUserMenuChoice(); Engine::SystemState currentState = contextManager->stateManager.current(); - uint16_t displayIndex = SystemCore::Configuration::numLeds - 1; + uint16_t displayIndex = SystemCore::Configuration::numLeds() - 1; float inactiveSelectionDimmingScale = currentState == Engine::SystemState::MenuHome ? 1.0f : 0.6f; constexpr float center = (menuTileWidth - 1) / 2.0f; constexpr double sigma = 3.0f; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index d6af5bb..0e0a549 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -68,11 +68,15 @@ namespace Engine void GameEngine::initializeEngine() { - contextManager.controller.begin(SystemCore::Configuration::macAddress); + SystemCore::Configuration::load(contextManager.memory); + + contextManager.stateManager.getPhaseEvasionGameState().loadHighScore(); + contextManager.stateManager.getRecallGameState().loadHighScore(); + contextManager.controller.begin(SystemCore::Configuration::macAddress()); // If debugging, ensure serial connection is stable before setting up components #if defined(VIRTUALIZATION) || defined(DEBUG) - Serial.begin(SystemCore::Configuration::serialBaud); + Serial.begin(SystemCore::Configuration::serialBaud()); contextManager.leds.reset(); renderLedStrip(); log("Connecting to computer using a serial connection for debugging."); @@ -82,6 +86,14 @@ namespace Engine delay(100); } log("Serial connection established."); + log("Printing environment variables."); + logf("version = %s", SystemCore::Configuration::version()); + logf("macAddress = %s", SystemCore::Configuration::macAddress()); + logf("numLeds = %u", SystemCore::Configuration::numLeds()); + logf("serialBaud = %u", SystemCore::Configuration::serialBaud()); + logf("boundary_1 = %u", SystemCore::Configuration::recallBoundaries()[0]); + logf("boundary_2 = %u", SystemCore::Configuration::recallBoundaries()[1]); + logf("boundary_3 = %u", SystemCore::Configuration::recallBoundaries()[2]); #endif log("Connecting to PS3 controller"); @@ -110,12 +122,6 @@ namespace Engine log("Startup process completed. Transitioning to Main Menu"); } -#ifdef RELEASE - contextManager.memory.begin("lumenlab", false); -#else - contextManager.memory.begin("lumenlab-dev", false); -#endif - randomSeed(esp_random()); } @@ -133,14 +139,14 @@ namespace Engine return; } - for (uint16_t i = 0; i <= SystemCore::Configuration::numLeds; ++i) + for (uint16_t i = 0; i <= SystemCore::Configuration::numLeds(); ++i) { - float phase = std::cos((2 * M_PI * i / SystemCore::Configuration::numLeds) + (2 * M_PI * disconnectedLedPhaseShift / SystemCore::Configuration::numLeds)) * 127 + 128; + float phase = std::cos((2 * M_PI * i / SystemCore::Configuration::numLeds()) + (2 * M_PI * disconnectedLedPhaseShift / SystemCore::Configuration::numLeds())) * 127 + 128; contextManager.leds.buffer[i] = {static_cast(std::floor(phase)), 0, 0}; } disconnectedLedPhaseShift += 0.5; - if (disconnectedLedPhaseShift > SystemCore::Configuration::numLeds) + if (disconnectedLedPhaseShift > SystemCore::Configuration::numLeds()) disconnectedLedPhaseShift = 0; } @@ -153,7 +159,7 @@ namespace Engine #ifdef VIRTUALIZATION Serial.write(0xAA); // sync bytes Serial.write(0x55); - Serial.write(reinterpret_cast(contextManager.leds.getRawColors()), SystemCore::Configuration::numLeds * sizeof(Lights::Color)); + Serial.write(reinterpret_cast(contextManager.leds.getRawColors()), SystemCore::Configuration::numLeds() * sizeof(Lights::Color)); #endif } diff --git a/src/games/demo/player.cpp b/src/games/demo/player.cpp index bf9c82b..72894b0 100644 --- a/src/games/demo/player.cpp +++ b/src/games/demo/player.cpp @@ -10,7 +10,7 @@ namespace Games::Demo float center = (width + 1) / 2.0f; for (uint16_t i = 0; i <= width; ++i) { - uint16_t index = (getPosition() + i) % SystemCore::Configuration::numLeds; + uint16_t index = (getPosition() + i) % SystemCore::Configuration::numLeds(); float intensity = 1.0f - std::abs(i - center) / center; if (intensity < 0) intensity = 0; @@ -27,7 +27,7 @@ namespace Games::Demo float center = (width + 1) / 2.0f; for (uint16_t i = 0; i <= width; ++i) { - uint16_t index = (getPosition() + i) % SystemCore::Configuration::numLeds; + uint16_t index = (getPosition() + i) % SystemCore::Configuration::numLeds(); float intensity = 1.0f - std::abs(i - center) / center; if (intensity < 0) intensity = 0; diff --git a/src/games/phase-evasion/driver.cpp b/src/games/phase-evasion/driver.cpp index 71e9d68..e26e448 100644 --- a/src/games/phase-evasion/driver.cpp +++ b/src/games/phase-evasion/driver.cpp @@ -6,10 +6,10 @@ namespace Games::PhaseEvasion { Driver::Driver(SystemCore::ContextManager *ctx) : contextManager{ctx}, + state{contextManager->stateManager.getPhaseEvasionGameState()}, player{ctx, playerWidth}, flareManager{ctx} { - state = contextManager->stateManager.getPhaseEvasionGameState(); state.reset(); state.current = Actions::Startup; reset(); @@ -65,7 +65,7 @@ namespace Games::PhaseEvasion { for (uint16_t i = 0; i < player.width; ++i) { - uint16_t index = (player.getPosition() + i) % SystemCore::Configuration::numLeds; + uint16_t index = (player.getPosition() + i) % SystemCore::Configuration::numLeds(); contextManager->leds.buffer[index] = player.getColor(); } } @@ -84,7 +84,7 @@ namespace Games::PhaseEvasion } uint16_t flareHead = std::max(flare.getPosition() - flare.width, 0); - uint16_t flareTail = std::min(flare.getPosition(), SystemCore::Configuration::numLeds); + uint16_t flareTail = std::min(flare.getPosition(), SystemCore::Configuration::numLeds()); for (uint16_t i = flareHead; i < flareTail; ++i) { @@ -102,7 +102,7 @@ namespace Games::PhaseEvasion return; uint16_t gemLeft = std::max(gem.getPosition() - gem.width, 0); - uint16_t gemRight = std::min(gem.getPosition(), SystemCore::Configuration::numLeds); + uint16_t gemRight = std::min(gem.getPosition(), SystemCore::Configuration::numLeds()); for (uint16_t i = gemLeft; i < gemRight; ++i) { @@ -118,7 +118,7 @@ namespace Games::PhaseEvasion continue; uint16_t flareStart = std::max(flare.getPosition() - flare.width, 0); - uint16_t flareEnd = std::min(flare.getPosition(), SystemCore::Configuration::numLeds); + uint16_t flareEnd = std::min(flare.getPosition(), SystemCore::Configuration::numLeds()); bool isUnmatchingColor = player.getColor() != flare.getColor(); bool hasEnteredRegion = flareStart <= player.getPosition() + player.width; @@ -128,7 +128,7 @@ namespace Games::PhaseEvasion { flare.impacted = true; state.current = Actions::MuzzleFlash; - gameOverPhaseShift = static_cast(((SystemCore::Configuration::numLeds / 2) + player.getPosition()) % SystemCore::Configuration::numLeds); + gameOverPhaseShift = static_cast(((SystemCore::Configuration::numLeds() / 2) + player.getPosition()) % SystemCore::Configuration::numLeds()); wait(20); } } @@ -138,7 +138,7 @@ namespace Games::PhaseEvasion { if (!gem.isActive() && gem.isReady()) { - const auto randGemPosition = static_cast((esp_random() % static_cast(SystemCore::Configuration::numLeds)) + gem.width); + const auto randGemPosition = static_cast((esp_random() % static_cast(SystemCore::Configuration::numLeds())) + gem.width); gem.spawn(randGemPosition); gemTimeoutTimer.wait(gemCaptureDelay); } @@ -148,7 +148,7 @@ namespace Games::PhaseEvasion if (!gemTimeoutTimer.isReady()) { uint16_t gemStart = std::max(gem.getPosition() - gem.width, 0); - uint16_t gemEnd = std::min(gem.getPosition(), SystemCore::Configuration::numLeds); + uint16_t gemEnd = std::min(gem.getPosition(), SystemCore::Configuration::numLeds()); bool hasEnteredRegion = gemStart <= player.getPosition() + player.width; bool hasNotExitedRegion = gemEnd >= player.getPosition(); @@ -205,7 +205,7 @@ namespace Games::PhaseEvasion void Driver::muzzleFlash() { - for (uint16_t i = 0; i < SystemCore::Configuration::numLeds; ++i) + for (uint16_t i = 0; i < SystemCore::Configuration::numLeds(); ++i) { contextManager->leds.buffer[i] = Lights::Color::White; } @@ -219,9 +219,9 @@ namespace Games::PhaseEvasion void Driver::gameOver() { - for (uint16_t i = 0; i <= SystemCore::Configuration::numLeds; ++i) + for (uint16_t i = 0; i <= SystemCore::Configuration::numLeds(); ++i) { - float offset = std::cos((2.0f * M_PI * i / SystemCore::Configuration::numLeds) - (2.0f * M_PI * static_cast(gameOverPhaseShift) / SystemCore::Configuration::numLeds)); + float offset = std::cos((2.0f * M_PI * i / SystemCore::Configuration::numLeds()) - (2.0f * M_PI * static_cast(gameOverPhaseShift) / SystemCore::Configuration::numLeds())); float phase = offset * 127.5 + 127.5; contextManager->leds.buffer[i] = {static_cast(std::floor(phase) * 0.95), static_cast(std::floor(phase) * 0.15), @@ -231,7 +231,7 @@ namespace Games::PhaseEvasion gameOverPhaseShift += std::cos(gameOverPhaseOffset) / 16.0f; gameOverPhaseOffset += 1.0 / 32.0f; - if (gameOverPhaseShift > SystemCore::Configuration::numLeds) + if (gameOverPhaseShift > SystemCore::Configuration::numLeds()) gameOverPhaseShift = 0.0; if (contextManager->controller.wasPressed(::Player::ControllerButton::Start)) diff --git a/src/games/phase-evasion/flare.cpp b/src/games/phase-evasion/flare.cpp index 0927093..1234a0f 100644 --- a/src/games/phase-evasion/flare.cpp +++ b/src/games/phase-evasion/flare.cpp @@ -19,7 +19,7 @@ namespace Games::PhaseEvasion completedCycle = false; color = _color; speed = _speed; - positionFloat = static_cast(SystemCore::Configuration::numLeds + width); + positionFloat = static_cast(SystemCore::Configuration::numLeds() + width); } void Flare::deactivate() @@ -33,6 +33,6 @@ namespace Games::PhaseEvasion color = Lights::Color::WhiteSmoke; speed = 0.0f; impacted = false; - positionFloat = static_cast(SystemCore::Configuration::numLeds + width); + positionFloat = static_cast(SystemCore::Configuration::numLeds() + width); } } \ No newline at end of file diff --git a/src/games/phase-evasion/state.cpp b/src/games/phase-evasion/state.cpp index 4862784..f9f3981 100644 --- a/src/games/phase-evasion/state.cpp +++ b/src/games/phase-evasion/state.cpp @@ -7,7 +7,11 @@ namespace Games::PhaseEvasion void GameState::reset() { flaresEvaded = gemsCaptured = 0; - highScore = contextManager->memory.getUInt(memoryKeyName); + } + + void GameState::loadHighScore() + { + highScore = contextManager->memory.getUInt(memoryKeyName, 0); } uint16_t GameState::calculateTotalScore() const diff --git a/src/games/recall/driver.cpp b/src/games/recall/driver.cpp index e39b3cd..be2c80c 100644 --- a/src/games/recall/driver.cpp +++ b/src/games/recall/driver.cpp @@ -6,10 +6,10 @@ namespace Games::Recall { - Driver::Driver(SystemCore::ContextManager *ctx) : contextManager{ctx} + Driver::Driver(SystemCore::ContextManager *ctx) : contextManager{ctx}, + state{contextManager->stateManager.getRecallGameState()} { setupGameColors(); - state = contextManager->stateManager.getRecallGameState(); state.reset(); state.current = Actions::Startup; contextManager->stateManager.displayShouldUpdate = true; @@ -91,12 +91,12 @@ namespace Games::Recall auto boundaries = directionBoundaries(gameplayColors[sequenceIndex]); double mu = (boundaries.first + boundaries.second) / 2.0; - const auto &recallBoundary = SystemCore::Configuration::recallBoundaries; + const auto &boundary = SystemCore::Configuration::recallBoundaries(); double delta = ((gameplayColors[sequenceIndex] == Player::ControllerButton::Circle || gameplayColors[sequenceIndex] == Player::ControllerButton::Square) - ? recallBoundary[2] - recallBoundary[1] - : recallBoundary[1] - recallBoundary[0]) / + ? boundary[1] - boundary[0] + : boundary[0] - 0) / 5; for (uint16_t i = boundaries.first; i <= boundaries.second; ++i) @@ -196,18 +196,18 @@ namespace Games::Recall std::pair Driver::directionBoundaries(Player::ControllerButton button) { - const auto &boundary = SystemCore::Configuration::recallBoundaries; + const auto &boundary = SystemCore::Configuration::recallBoundaries(); switch (button) { case Player::ControllerButton::Triangle: - return {boundary[0], static_cast(boundary[1] - 1)}; + return {0, static_cast(boundary[0] - 1)}; case Player::ControllerButton::Circle: - return {boundary[1], static_cast(boundary[2] - 1)}; + return {boundary[0], static_cast(boundary[1] - 1)}; case Player::ControllerButton::Cross: - return {boundary[2], static_cast(boundary[3] - 1)}; + return {boundary[1], static_cast(boundary[2] - 1)}; case Player::ControllerButton::Square: - return {boundary[3], static_cast(SystemCore::Configuration::numLeds - 1)}; + return {boundary[2], static_cast(SystemCore::Configuration::numLeds() - 1)}; default: return {0, 0}; } @@ -251,14 +251,14 @@ namespace Games::Recall contextManager->stateManager.displayShouldUpdate = true; } - for (uint16_t i = 0; i <= SystemCore::Configuration::numLeds; ++i) + for (uint16_t i = 0; i <= SystemCore::Configuration::numLeds(); ++i) { - float phase = std::cos((2.0f * M_PI * i / SystemCore::Configuration::numLeds) + (2.0f * M_PI * gameOverLedPhaseShift / SystemCore::Configuration::numLeds)) * 127 + 128; + float phase = std::cos((2.0f * M_PI * i / SystemCore::Configuration::numLeds()) + (2.0f * M_PI * gameOverLedPhaseShift / SystemCore::Configuration::numLeds())) * 127 + 128; contextManager->leds.buffer[i] = {static_cast(std::floor(phase)), 0, 0}; } gameOverLedPhaseShift += 0.5f; - if (gameOverLedPhaseShift > SystemCore::Configuration::numLeds) + if (gameOverLedPhaseShift > SystemCore::Configuration::numLeds()) gameOverLedPhaseShift = 0.0f; } } \ No newline at end of file diff --git a/src/games/recall/state.cpp b/src/games/recall/state.cpp index 4506e43..57f9177 100644 --- a/src/games/recall/state.cpp +++ b/src/games/recall/state.cpp @@ -1,22 +1,21 @@ -#include "games/phase-evasion/state.h" +#include "games/recall/state.h" #include "core/context-manager.h" #include "logger.h" namespace Games::Recall { - GameState::GameState(SystemCore::ContextManager *ctx) : contextManager{ctx} - { - reset(); - } - void GameState::reset() { round = 0; - highScore = contextManager->memory.getUInt(memoryKeyName); contextManager->stateManager.displayShouldUpdate = true; } + void GameState::loadHighScore() + { + highScore = contextManager->memory.getUInt(memoryKeyName, 0); + } + void GameState::updateHighScore() { highScore = round; diff --git a/src/player/controller.cpp b/src/player/controller.cpp index 70e767e..d81336a 100644 --- a/src/player/controller.cpp +++ b/src/player/controller.cpp @@ -10,9 +10,9 @@ namespace Player // Following Singleton pattern. Only one instance of the game controller can exist Controller *Controller::instance = nullptr; - void Controller::begin(const char *macAddress) + void Controller::begin(String macAddress) { - instance->controller.begin(macAddress); + instance->controller.begin(macAddress.c_str()); instance->controller.attachOnConnect(&Controller::onConnect); } diff --git a/src/player/player.cpp b/src/player/player.cpp index 00ccc01..3b1aa3f 100644 --- a/src/player/player.cpp +++ b/src/player/player.cpp @@ -10,7 +10,7 @@ namespace Player float step = analogToSpeed(distance, speed); positionPrecise += step; - const float adjustedLedCount = static_cast(SystemCore::Configuration::numLeds - width); + const float adjustedLedCount = static_cast(SystemCore::Configuration::numLeds() - width); if (shouldWrap) { positionPrecise = std::fmod(positionPrecise, adjustedLedCount); diff --git a/src/scenes/canvas/driver.cpp b/src/scenes/canvas/driver.cpp index b96d55d..f5ffc47 100644 --- a/src/scenes/canvas/driver.cpp +++ b/src/scenes/canvas/driver.cpp @@ -6,7 +6,7 @@ namespace Scenes::Canvas { - Driver::Driver(SystemCore::ContextManager *ctx) : contextManager{ctx} + Driver::Driver(SystemCore::ContextManager *ctx) : contextManager{ctx}, state{contextManager->stateManager.getCanvasSceneState()} { reset(); } @@ -19,7 +19,7 @@ namespace Scenes::Canvas checkChangeOccured(); checkStableControllerForDisplay(); - for (uint16_t i; i < SystemCore::Configuration::numLeds; ++i) + for (uint16_t i; i < SystemCore::Configuration::numLeds(); ++i) { contextManager->leds.buffer[i] = contextManager->stateManager.getCanvasSceneState().currentColor; }