cleanup in logger code

This commit is contained in:
dario
2024-06-04 22:05:23 +02:00
parent 33e034a429
commit d378bda62c
2 changed files with 20 additions and 8 deletions

View File

@@ -115,15 +115,13 @@ namespace sta
}
template <typename T>
T Logger<T>::operator[](std::size_t idx)
T Logger<T>::get(std::size_t i)
{
uint32_t address = start_ * W25QXX_SECTOR_SIZE + idx * sizeof(T);
STA_DEBUG_PRINTF("Reading from address %d\n", address);
uint32_t address = start_ * W25QXX_SECTOR_SIZE + i * sizeof(T);
// If the requested element is in the cache, read it from there.
if (address / W25QXX_PAGE_SIZE == address_ / W25QXX_PAGE_SIZE)
{
STA_DEBUG_PRINTLN("Reading data from buffer!");
uint8_t * ptr = buffer_ + address % W25QXX_PAGE_SIZE;
return *reinterpret_cast<T*>(ptr);
}
@@ -134,6 +132,12 @@ namespace sta
return *reinterpret_cast<T*>(buffer);
}
}
template <typename T>
T Logger<T>::operator[](std::size_t i)
{
return this->get(i);
}
} // namespace sta
#endif // STA_UTILS_LOGGER_TPP