Skip to content

Commit

Permalink
It turns out that our templated storage().get() method silently fails
Browse files Browse the repository at this point in the history
when handed an untyped pointer, so we're going to have to end up
with a templated method for this.
  • Loading branch information
obra committed Mar 7, 2024
1 parent d2a79b0 commit 268d942
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stddef.h> // 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 {
Expand Down Expand Up @@ -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<typename T>
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);

Expand Down

0 comments on commit 268d942

Please sign in to comment.