Skip to content

Commit

Permalink
Change functions to reference rather than copy
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ-Koenig committed Nov 1, 2024
1 parent a3221f1 commit 769a17f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions Software/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ build_flags =
-D HTTPCLIENT_1_1_COMPATIBLE=0
; This flag is used for Stroke Engine.
-D DEBUG_TALKATIVE
targets = upload, monitor
extends = common
platform = espressif32
board = esp32dev
Expand Down
8 changes: 4 additions & 4 deletions Software/src/extensions/u8g2Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int getUTF8CharLength(const unsigned char c) {
* display.
*/
namespace drawStr {
static void centered(int y, String str) {
static void centered(int y, const String& str) {
// Convert the String object to a UTF-8 string.
// The c_str() function ensures we're passing a null-terminated string,
// which is required by getStrWidth().
Expand All @@ -54,7 +54,7 @@ namespace drawStr {
* @param y
* @param str
*/
static void multiLine(int x, int y, String string, int lineHeight = 12) {
static void multiLine(int x, int y, const String& string, int lineHeight = 12) {
const char *str = string.c_str();
// Set the font for the text to be displayed.
display.setFont(Config::Font::base);
Expand Down Expand Up @@ -162,9 +162,9 @@ namespace drawStr {
}
}

static void title(String str) {
static void title(const String& str) {
display.setFont(Config::Font::bold);
centered(8, std::move(str));
centered(8, str);
}
};

Expand Down
31 changes: 20 additions & 11 deletions Software/src/ossm/OSSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "constants/Menu.h"
#include "constants/Pins.h"
#include "services/tasks.h"
#include "structs/SettingPercents.h"
#include "structs/AdvancedConfigurationSettings.h"
#include "structs/SettingPercents.h"
#include "utils/RecusiveMutex.h"
#include "utils/StateLogger.h"
#include "utils/StrokeEngineHelper.h"
Expand Down Expand Up @@ -112,8 +112,12 @@ class OSSM {
o.stepper->disableOutputs();
};
auto drawHelp = [](OSSM &o) { o.drawHelp(); };
auto drawAdvancedConfiguration = [](OSSM &o) { o.drawAdvancedConfiguration(); };
auto drawAdvancedConfigurationEditing = [](OSSM &o) { o.drawAdvancedConfigurationEditing(); };
auto drawAdvancedConfiguration = [](OSSM &o) {
o.drawAdvancedConfiguration();
};
auto drawAdvancedConfigurationEditing = [](OSSM &o) {
o.drawAdvancedConfigurationEditing();
};
auto drawWiFi = [](OSSM &o) { o.drawWiFi(); };
auto drawUpdate = [](OSSM &o) { o.drawUpdate(); };
auto drawNoUpdate = [](OSSM &o) { o.drawNoUpdate(); };
Expand Down Expand Up @@ -144,8 +148,8 @@ class OSSM {
return o.isStrokeTooShort();
};

auto isOption = [](Menu option) {
return [option](OSSM &o) { return o.menuOption == option; };
auto isOption = [](const Menu &option) {
return [&option](OSSM &o) { return o.menuOption == option; };
};

auto isPreflightSafe = [](OSSM &o) {
Expand All @@ -167,7 +171,7 @@ class OSSM {
auto setNotHomed = [](OSSM &o) { o.isHomed = false; };

return make_transition_table(
// clang-format off
// clang-format off

//Always start by drawing the hello screen and then initializing settings
*"idle"_s + done / drawHello = "initialize"_s,
Expand Down Expand Up @@ -278,8 +282,10 @@ class OSSM {
.depth = 50,
.pattern = StrokePatterns::SimpleStroke};

AdvancedConfigurationSettingName activeAdvancedConfigurationSetting = AdvancedConfigurationSettingName::ReadMe;
AdvancedConfigurationSettings advancedConfigurationSettings = AdvancedConfigurationSettings();
AdvancedConfigurationSettingName activeAdvancedConfigurationSetting =
AdvancedConfigurationSettingName::ReadMe;
AdvancedConfigurationSettings advancedConfigurationSettings =
AdvancedConfigurationSettings();

unsigned long sessionStartTime = 0;
int sessionStrokeCount = 0;
Expand Down Expand Up @@ -368,10 +374,13 @@ class OSSM {

WiFiManager wm;

float getAdvancedSettingValue(AdvancedConfigurationSettingName settingName) {
for (auto& setting : advancedConfigurationSettings.settings) {
float getAdvancedSettingValue(
AdvancedConfigurationSettingName settingName) {
for (auto &setting : advancedConfigurationSettings.settings) {
if (setting.name == settingName) {
ESP_LOGD("Initialize", "Configuring setting %s with value %f", getSettingName(setting.name).c_str(), setting.currentValue());
ESP_LOGD("Initialize", "Configuring setting %s with value %f",
getSettingName(setting.name).c_str(),
setting.currentValue());
return setting.currentValue();
}
}
Expand Down

0 comments on commit 769a17f

Please sign in to comment.