hobbyking_cheetah source code modified 2020/12/15
Dependencies: mbed-dev-f303 FastPWM3
PreferenceWriter/PrefrenceWriter.cpp@55:71a6e5fe5805, 2020-12-15 (annotated)
- Committer:
- WinnieLiu
- Date:
- Tue Dec 15 07:28:27 2020 +0000
- Revision:
- 55:71a6e5fe5805
- Parent:
- 24:58c2d7571207
2020/12/15
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 23:2adf23ee0305 | 1 | #include "PreferenceWriter.h" |
benkatz | 23:2adf23ee0305 | 2 | #include "FlashWriter.h" |
benkatz | 23:2adf23ee0305 | 3 | #include "user_config.h" |
benkatz | 23:2adf23ee0305 | 4 | #include "mbed.h" |
benkatz | 23:2adf23ee0305 | 5 | |
benkatz | 23:2adf23ee0305 | 6 | PreferenceWriter::PreferenceWriter(uint32_t sector) { |
benkatz | 23:2adf23ee0305 | 7 | writer = new FlashWriter(sector); |
benkatz | 23:2adf23ee0305 | 8 | __sector = sector; |
benkatz | 23:2adf23ee0305 | 9 | __ready = false; |
benkatz | 23:2adf23ee0305 | 10 | } |
benkatz | 23:2adf23ee0305 | 11 | |
benkatz | 23:2adf23ee0305 | 12 | void PreferenceWriter::open() { |
benkatz | 23:2adf23ee0305 | 13 | writer->open(); |
benkatz | 23:2adf23ee0305 | 14 | __ready = true; |
benkatz | 23:2adf23ee0305 | 15 | } |
benkatz | 23:2adf23ee0305 | 16 | |
benkatz | 23:2adf23ee0305 | 17 | bool PreferenceWriter::ready() { |
benkatz | 23:2adf23ee0305 | 18 | return __ready; |
benkatz | 23:2adf23ee0305 | 19 | } |
benkatz | 23:2adf23ee0305 | 20 | |
benkatz | 23:2adf23ee0305 | 21 | void PreferenceWriter::write(int x, int index) { |
benkatz | 23:2adf23ee0305 | 22 | __int_reg[index] = x; |
benkatz | 23:2adf23ee0305 | 23 | } |
benkatz | 23:2adf23ee0305 | 24 | |
benkatz | 23:2adf23ee0305 | 25 | void PreferenceWriter::write(float x, int index) { |
benkatz | 23:2adf23ee0305 | 26 | __float_reg[index] = x; |
benkatz | 23:2adf23ee0305 | 27 | } |
benkatz | 23:2adf23ee0305 | 28 | |
benkatz | 23:2adf23ee0305 | 29 | void PreferenceWriter::flush() { |
benkatz | 23:2adf23ee0305 | 30 | int offs; |
benkatz | 23:2adf23ee0305 | 31 | for (offs = 0; offs < 256; offs++) { |
benkatz | 23:2adf23ee0305 | 32 | writer->write(offs, __int_reg[offs]); |
benkatz | 23:2adf23ee0305 | 33 | } |
benkatz | 23:2adf23ee0305 | 34 | for (; offs < 320; offs++) { |
benkatz | 23:2adf23ee0305 | 35 | writer->write(offs, __float_reg[offs - 256]); |
benkatz | 23:2adf23ee0305 | 36 | } |
benkatz | 24:58c2d7571207 | 37 | __ready = false; |
benkatz | 23:2adf23ee0305 | 38 | } |
benkatz | 23:2adf23ee0305 | 39 | |
benkatz | 23:2adf23ee0305 | 40 | void PreferenceWriter::load() { |
benkatz | 23:2adf23ee0305 | 41 | int offs; |
benkatz | 23:2adf23ee0305 | 42 | for (offs = 0; offs < 256; offs++) { |
benkatz | 23:2adf23ee0305 | 43 | __int_reg[offs] = flashReadInt(__sector, offs); |
benkatz | 23:2adf23ee0305 | 44 | } |
benkatz | 23:2adf23ee0305 | 45 | for(; offs < 320; offs++) { |
benkatz | 23:2adf23ee0305 | 46 | __float_reg[offs - 256] = flashReadFloat(__sector, offs); |
benkatz | 23:2adf23ee0305 | 47 | } |
benkatz | 23:2adf23ee0305 | 48 | } |
benkatz | 23:2adf23ee0305 | 49 | |
benkatz | 23:2adf23ee0305 | 50 | void PreferenceWriter::close() { |
benkatz | 24:58c2d7571207 | 51 | __ready = false; |
benkatz | 23:2adf23ee0305 | 52 | writer->close(); |
benkatz | 23:2adf23ee0305 | 53 | } |