working commands. singleton deleted
Diff: OfflineCommand.cpp
- Revision:
- 1:fd4c0e2decb8
- Parent:
- 0:e188325211af
- Child:
- 2:c9e47ac47edb
--- a/OfflineCommand.cpp Thu Jun 04 10:56:18 2015 +0000 +++ b/OfflineCommand.cpp Sun Jun 07 14:11:14 2015 +0000 @@ -1,16 +1,21 @@ #include "OfflineCommand.h" +volatile int32_t OfflineCommand::addr = 0; + OfflineCommand::OfflineCommand() { this->sensors = Sensors::getInstance(); this->storage = Storage::getInstance(); - this->addr = 0x0; + addr = 0x0; this->running = 0; + this->state = 0; } void OfflineCommand::initialize() { printf("OfflineCommand\n"); + this->state = 0; + //setLed(1); setTicker(0.1); } @@ -23,37 +28,42 @@ void OfflineCommand::button() { - if (running == 0){ - this->addr = 0x0; - - //this->storage->setWREN(); - //this->storage->bulkErase(); - - //__disable_irq(); - - while(this->storage->getSR1() == 3){ - printf("erasing...\n"); - wait(1); - } + switch(state) { + case 0: + printf("ERASE COMMAND\n"); + detachTicker(); + setLed(1); + addr = 0; + wait(0.1); + eraseMemory(); + this->state = 1; + setTicker(0.1); + break; + case 1: + detachTicker(); + setLed(1); + printf("WRITE COMMAND\n"); + addr = 0; + this->running = 1; //This will unlock the writeToMemory from the execution + this->state = 2; + this->sensors->wakeIMU(); + break; + case 2: + setTicker(0.1); + printf("DONE WRITE COMMAND..."); + printf("%d\n", addr); + this->sensors->disableIMU(); + this->running = 0; + this->state = 0; + break; + } - printf("writing...\n"); - this->running = 1; - this->sensors->wakeIMU(); - wait(0.001); - - //__enable_irq(); - - } else { - this->sensors->disableIMU(); - this->running = 0; - printf("Done writing, %d\n", addr); - } - } void OfflineCommand::finish() { - detachTicker(); + this->state = 0; + detachTicker(); setLed(0); } @@ -68,19 +78,71 @@ storage->writeData(sensors->getAngleH()); storage->writeData(sensors->getAngleL()); - storage->writeData(sensors->getGyroXH()); + storage->writeData(sensors->getGyroXH()); storage->writeData(sensors->getGyroXH()); storage->endAction(); - - this->addr = this->addr + 0x4; - + + addr = addr + 0x4; + } else { printf("busy: %d\n", storage->getSR1()); } } -void OfflineCommand::eraseMemory(){ +void OfflineCommand::eraseMemory() +{ + __disable_irq(); + Storage::getInstance()->reset(); + + while(Storage::getInstance()->isBusy()) { + setLed(1); + wait(0.1); + setLed(0); + } + Storage::getInstance()->setWREN(); + + wait(0.01); + + Storage::getInstance()->bulkErase(); + + wait(0.01); + + printf("erasing...\n"); + + while(Storage::getInstance()->isBusy()) { + wait(0.1); + } + + printf("succes...%d\n", Storage::getInstance()->getSR1()); + __enable_irq(); +/* + __disable_irq(); + + Storage::getInstance()->read(addr); + + while(Storage::getInstance()->readData() != 0xFF){ + Storage::getInstance()->endAction(); //end previous read action + + Storage::getInstance()->sectorErase(addr); + + while( Storage::getInstance()->isBusy()){ + wait(0.01); + } + addr = addr + (1<<18); + printf("sector %d erased\n", addr); + Storage::getInstance()->read(addr); //set next section addr for read in the while statement } + printf("sector erase done\n"); + Storage::getInstance()->endAction(); + + __enable_irq(); + + */ +} + +int32_t OfflineCommand::getLastAddress(){ + return addr; + } \ No newline at end of file