Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-dev-f303 FastPWM3
Diff: PreferenceWriter/PrefrenceWriter.cpp
- Revision:
- 23:2adf23ee0305
- Child:
- 24:58c2d7571207
diff -r 60276ba87ac6 -r 2adf23ee0305 PreferenceWriter/PrefrenceWriter.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PreferenceWriter/PrefrenceWriter.cpp Wed Apr 05 20:54:16 2017 +0000
@@ -0,0 +1,51 @@
+#include "PreferenceWriter.h"
+#include "FlashWriter.h"
+#include "user_config.h"
+#include "mbed.h"
+
+PreferenceWriter::PreferenceWriter(uint32_t sector) {
+ writer = new FlashWriter(sector);
+ __sector = sector;
+ __ready = false;
+}
+
+void PreferenceWriter::open() {
+ writer->open();
+ __ready = true;
+}
+
+bool PreferenceWriter::ready() {
+ return __ready;
+}
+
+void PreferenceWriter::write(int x, int index) {
+ __int_reg[index] = x;
+}
+
+void PreferenceWriter::write(float x, int index) {
+ __float_reg[index] = x;
+}
+
+void PreferenceWriter::flush() {
+ int offs;
+ for (offs = 0; offs < 256; offs++) {
+ writer->write(offs, __int_reg[offs]);
+ }
+ for (; offs < 320; offs++) {
+ writer->write(offs, __float_reg[offs - 256]);
+ }
+}
+
+void PreferenceWriter::load() {
+ int offs;
+ for (offs = 0; offs < 256; offs++) {
+ __int_reg[offs] = flashReadInt(__sector, offs);
+ }
+ for(; offs < 320; offs++) {
+ __float_reg[offs - 256] = flashReadFloat(__sector, offs);
+ }
+}
+
+void PreferenceWriter::close() {
+ writer->close();
+}
\ No newline at end of file