working commands. singleton deleted
Diff: OfflineCommand.cpp
- Revision:
- 4:f81029197ab2
- Parent:
- 3:32afe87d4b62
--- a/OfflineCommand.cpp Sun Jun 07 21:57:46 2015 +0000 +++ b/OfflineCommand.cpp Thu Jun 11 10:42:50 2015 +0000 @@ -1,7 +1,7 @@ #include "OfflineCommand.h" - + volatile int32_t OfflineCommand::addr = 0; - + OfflineCommand::OfflineCommand(Sensors* sensors, Storage* storage) { this->sensors = sensors; @@ -10,26 +10,24 @@ this->running = 0; this->state = 0; } - + void OfflineCommand::initialize() { - printf("OfflineCommand\n"); this->state = 0; setTicker(0.1); } - + void OfflineCommand::execute() { if(running) { writeToMemory(); } } - + void OfflineCommand::button() { switch(state) { case 0: - printf("ERASE COMMAND\n"); detachTicker(); setLed(1); addr = 0; @@ -41,82 +39,59 @@ 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; + setLed(0); + NRF_POWER->SYSTEMOFF = 1; break; } - + } - + void OfflineCommand::finish() { this->state = 0; detachTicker(); setLed(0); } - + void OfflineCommand::writeToMemory() { + + sensors->updateAngle(); sensors->updateIMU(); if(!storage->isBusy()) { - + storage->pageProgram(addr); - + storage->writeData(sensors->getAngle(0)); storage->writeData(sensors->getAngle(1)); storage->writeData(sensors->getIMU(0)); storage->writeData(sensors->getIMU(1)); storage->endAction(); - + addr = addr + 0x4; - + } else { printf("busy: %d\n", storage->getSR1()); } - + } - + void OfflineCommand::eraseMemory() { - /* - __disable_irq(); - storage->reset(); - - while(storage->isBusy()) { - wait(0.1); - } - - storage->setWREN(); - wait(0.01); - storage->bulkErase(); - wait(0.01); - - printf("erasing...\n"); - - while(storage->isBusy()) { - wait(0.1); - } - - printf("SUCCES!\n"); - __enable_irq(); - */ - - __disable_irq(); - + __disable_irq(); + storage->read(0x00); while(storage->readData() != -1){ @@ -135,4 +110,5 @@ storage->endAction(); __enable_irq(); -} \ No newline at end of file +} + \ No newline at end of file