Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
26 changes: 19 additions & 7 deletions include/core/configuration.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
#pragma once

#include <Arduino.h>
#include <Preferences.h>
#include <cstdint>

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<uint16_t, 3> &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<uint16_t, 3> _recallBoundaries;
};
}
1 change: 0 additions & 1 deletion include/display/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion include/games/phase-evasion/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Games::PhaseEvasion

private:
SystemCore::ContextManager *contextManager;
GameState &state = contextManager->stateManager.getPhaseEvasionGameState();
GameState &state;

Player player;
FlareManager flareManager;
Expand Down
2 changes: 1 addition & 1 deletion include/games/phase-evasion/flare-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ namespace Games::PhaseEvasion

private:
SystemCore::ContextManager *contextManager;
std::array<Flare, 10> flarePool;
std::array<Flare, 20> flarePool;
};
}
2 changes: 1 addition & 1 deletion include/games/phase-evasion/gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions include/games/phase-evasion/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion include/games/recall/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion include/games/recall/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions include/lights/led-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/lights/led-strip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion include/player/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion include/scenes/canvas/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/core/configuration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "core/configuration.h"
#include <Preferences.h>

#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<uint16_t, 3> Configuration::_recallBoundaries;

void Configuration::load(::Preferences &memory)
{
_version = LUMENLAB_VERSION;
_macAddress = memory.getString("macAddress", "00:00:00:00:00:00");
_numLeds = static_cast<uint16_t>(memory.getString("numLeds", "300").toInt());
_serialBaud = static_cast<uint32_t>(memory.getString("serialBaud", "921600").toInt());

_recallBoundaries[0] = static_cast<uint16_t>(memory.getString("boundary_1", "75").toInt());
_recallBoundaries[1] = static_cast<uint16_t>(memory.getString("boundary_2", "150").toInt());
_recallBoundaries[2] = static_cast<uint16_t>(memory.getString("boundary_3", "225").toInt());
}
}
11 changes: 9 additions & 2 deletions src/core/context-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 1 addition & 4 deletions src/display/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/display/menu-navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 18 additions & 12 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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");
Expand Down Expand Up @@ -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());
}

Expand All @@ -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<uint8_t>(std::floor(phase)), 0, 0};
}
disconnectedLedPhaseShift += 0.5;

if (disconnectedLedPhaseShift > SystemCore::Configuration::numLeds)
if (disconnectedLedPhaseShift > SystemCore::Configuration::numLeds())
disconnectedLedPhaseShift = 0;
}

Expand All @@ -153,7 +159,7 @@ namespace Engine
#ifdef VIRTUALIZATION
Serial.write(0xAA); // sync bytes
Serial.write(0x55);
Serial.write(reinterpret_cast<uint8_t *>(contextManager.leds.getRawColors()), SystemCore::Configuration::numLeds * sizeof(Lights::Color));
Serial.write(reinterpret_cast<uint8_t *>(contextManager.leds.getRawColors()), SystemCore::Configuration::numLeds() * sizeof(Lights::Color));
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions src/games/demo/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading