From 268d942a566c7d9fd6170307d6445f6eb5854929 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Thu, 7 Mar 2024 11:57:16 -0800 Subject: [PATCH] It turns out that our templated storage().get() method silently fails when handed an untyped pointer, so we're going to have to end up with a templated method for this. --- .../kaleidoscope/plugin/EEPROM-Settings.cpp | 18 ---------------- .../src/kaleidoscope/plugin/EEPROM-Settings.h | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.cpp b/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.cpp index 240c49f900..0854354058 100644 --- a/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.cpp +++ b/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.cpp @@ -160,24 +160,6 @@ void EEPROMSettings::update() { is_valid_ = true; } -// get a settings slice from the storage and stick it in the untyped struct -// startAddress is the address of the start of the slice -// Returns true if the load was successful and false otherwise. -// Takes the size of storage we want, a pointer to the start address, and a pointer to the data structure for settings - - -bool EEPROMSettings::requestSliceAndLoadData(size_t size, uint16_t *startAddress, void *data) { - // Request the slice for the struct from storage - uint16_t start = requestSlice(size); - *startAddress = start; - - if (!Runtime.storage().isSliceUninitialized(start, size)) { - Runtime.storage().get(start, data); - return true; // Data was loaded successfully - } else { - } - return false; // Data was not loaded -} bool EEPROMSettings::isSliceValid(uint16_t start, size_t size) { diff --git a/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.h b/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.h index d6a06ab2b7..162a8110be 100644 --- a/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.h +++ b/plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.h @@ -21,6 +21,7 @@ #include // for size_t #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/plugin.h" // for Plugin +#include "kaleidoscope/Runtime.h" // for Runtime namespace kaleidoscope { namespace plugin { @@ -73,7 +74,25 @@ class EEPROMSettings : public kaleidoscope::Plugin { bool ignoreHardcodedLayers() { return settings_.ignore_hardcoded_layers; } - bool requestSliceAndLoadData(size_t size, uint16_t *startAddress, void *data); + // get a settings slice from the storage and stick it in the settings struct + // Takes a pointer to the start address, and a pointer to the data structure for settings + // startAddress is the address of the start of the slice, to be returned to the caller + // Returns true if the slice is initialized and false otherwise. + + + template + bool requestSliceAndLoadData(size_t size, uint16_t *startAddress, T *data) { + uint16_t start = requestSlice(size); + *startAddress = start; + + // Load the data if the slice is initialized + Runtime.storage().get(start, *data); // Directly load data into the provided address + if (!Runtime.storage().isSliceUninitialized(start, size)) { + return true; + } + + return false; + } bool isSliceValid(uint16_t start, size_t size);