From e644a9dda800dc8bc5ca8057ddba599ed1e65847 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 1 Jun 2021 13:17:22 +1000 Subject: [PATCH] StorageManager: add read_float and write_float --- libraries/StorageManager/StorageManager.cpp | 18 ++++++++++++++++++ libraries/StorageManager/StorageManager.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/libraries/StorageManager/StorageManager.cpp b/libraries/StorageManager/StorageManager.cpp index 88f553134f..d182937c04 100644 --- a/libraries/StorageManager/StorageManager.cpp +++ b/libraries/StorageManager/StorageManager.cpp @@ -265,6 +265,16 @@ uint32_t StorageAccess::read_uint32(uint16_t loc) const return v; } +/* + read a float + */ +float StorageAccess::read_float(uint16_t loc) const +{ + float v; + read_block(&v, loc, sizeof(v)); + return v; +} + /* write a byte */ @@ -289,6 +299,14 @@ void StorageAccess::write_uint32(uint16_t loc, uint32_t value) const write_block(loc, &value, sizeof(value)); } +/* + write a float + */ +void StorageAccess::write_float(uint16_t loc, float value) const +{ + write_block(loc, &value, sizeof(value)); +} + /* copy one area to another */ diff --git a/libraries/StorageManager/StorageManager.h b/libraries/StorageManager/StorageManager.h index 369d76d1a4..782c4ba9db 100644 --- a/libraries/StorageManager/StorageManager.h +++ b/libraries/StorageManager/StorageManager.h @@ -95,11 +95,13 @@ public: uint8_t read_uint8(uint16_t loc) const { return read_byte(loc); } uint16_t read_uint16(uint16_t loc) const; uint32_t read_uint32(uint16_t loc) const; + float read_float(uint16_t loc) const; void write_byte(uint16_t loc, uint8_t value) const; void write_uint8(uint16_t loc, uint8_t value) const { return write_byte(loc, value); } void write_uint16(uint16_t loc, uint16_t value) const; void write_uint32(uint16_t loc, uint32_t value) const; + void write_float(uint16_t loc, float value) const; // copy from one storage area to another bool copy_area(const StorageAccess &source) const;