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
4 changes: 2 additions & 2 deletions src/FSHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class File {
size_t size() const { return m_File.size(); }
bool isDirectory() { return m_File.isDirectory(); }
bool seek(size_t pos) { return m_File.seek(pos); }
bool read(uint8_t* buffer, size_t size) { return m_File.read(buffer, size); }
bool write(const uint8_t* buffer, size_t size) {
size_t read(uint8_t* buffer, size_t size) { return m_File.read(buffer, size); }
size_t write(const uint8_t* buffer, size_t size) {
return m_File.write(buffer, size);
}
void close() { return m_File.close(); }
Expand Down
37 changes: 34 additions & 3 deletions src/configuration/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,41 @@ void Configuration::eraseSensors() {

void Configuration::loadSensors() {
SlimeVR::Utils::forEachFile(DIR_CALIBRATIONS, [&](SlimeVR::Utils::File f) {
SensorConfig sensorConfig;
f.read((uint8_t*)&sensorConfig, sizeof(SensorConfig));

uint8_t sensorId = strtoul(f.name(), nullptr, 10);

if (f.size() != sizeof(SensorConfig)) {
m_Logger.warn(
"Skipping incompatible sensor calibration file index %d (size=%u "
"expected=%u)",
sensorId,
static_cast<unsigned>(f.size()),
static_cast<unsigned>(sizeof(SensorConfig))
);
return;
}

SensorConfig sensorConfig{};
auto bytesRead = f.read((uint8_t*)&sensorConfig, sizeof(SensorConfig));
if (bytesRead != sizeof(SensorConfig)) {
m_Logger.warn(
"Skipping unreadable sensor calibration file index %d (read=%u "
"expected=%u)",
sensorId,
static_cast<unsigned>(bytesRead),
static_cast<unsigned>(sizeof(SensorConfig))
);
return;
}

if (sensorConfig.type > SensorConfigType::RUNTIME_CALIBRATION) {
m_Logger.warn(
"Skipping sensor calibration file index %d with invalid type=%d",
sensorId,
static_cast<int>(sensorConfig.type)
);
return;
}

m_Logger.debug(
"Found sensor calibration for %s at index %d",
calibrationConfigTypeToString(sensorConfig.type),
Expand Down