Motor control for robots. More compact, less object-oriented revision.

Dependencies:   FastPWM3 mbed-dev-f303

Fork of Hobbyking_Cheetah_V1 by Ben Katz

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PrefrenceWriter.cpp Source File

PrefrenceWriter.cpp

00001 #include "PreferenceWriter.h"
00002 #include "FlashWriter.h"
00003 #include "user_config.h"
00004 #include "mbed.h"
00005 
00006 PreferenceWriter::PreferenceWriter(uint32_t sector) {
00007     writer = new FlashWriter(sector);
00008     __sector = sector;
00009     __ready = false;
00010 }
00011 
00012 void PreferenceWriter::open() {
00013     writer->open();
00014     __ready = true;
00015 }
00016 
00017 bool  PreferenceWriter::ready() {
00018     return __ready;
00019 }
00020 
00021 void PreferenceWriter::write(int x, int index) {
00022     __int_reg[index] = x;
00023 }
00024 
00025 void PreferenceWriter::write(float x, int index) {
00026     __float_reg[index] = x;
00027 }
00028 
00029 void PreferenceWriter::flush() {
00030     int offs;
00031     for (offs = 0; offs < 256; offs++) {
00032         writer->write(offs, __int_reg[offs]);
00033     }
00034     for (; offs < 320; offs++) {
00035         writer->write(offs, __float_reg[offs - 256]);
00036     }
00037     __ready = false;
00038 }
00039 
00040 void PreferenceWriter::load() {
00041     int offs;
00042     for (offs = 0; offs < 256; offs++) {
00043         __int_reg[offs] = flashReadInt(__sector, offs);
00044     }
00045     for(; offs < 320; offs++) {
00046         __float_reg[offs - 256] = flashReadFloat(__sector, offs);
00047     }
00048 }
00049 
00050 void PreferenceWriter::close() {
00051     __ready = false;
00052     writer->close();
00053 }