working commands. singleton deleted
OfflineCommand.cpp
- Committer:
- dkester
- Date:
- 2015-06-07
- Revision:
- 1:fd4c0e2decb8
- Parent:
- 0:e188325211af
- Child:
- 2:c9e47ac47edb
File content as of revision 1:fd4c0e2decb8:
#include "OfflineCommand.h" volatile int32_t OfflineCommand::addr = 0; OfflineCommand::OfflineCommand() { this->sensors = Sensors::getInstance(); this->storage = Storage::getInstance(); addr = 0x0; this->running = 0; this->state = 0; } void OfflineCommand::initialize() { printf("OfflineCommand\n"); this->state = 0; //setLed(1); 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; 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; } } void OfflineCommand::finish() { this->state = 0; detachTicker(); setLed(0); } void OfflineCommand::writeToMemory() { sensors->updateIMU(); sensors->updateAngle(); if(!storage->isBusy()) { storage->pageProgram(addr); storage->writeData(sensors->getAngleH()); storage->writeData(sensors->getAngleL()); storage->writeData(sensors->getGyroXH()); storage->writeData(sensors->getGyroXH()); storage->endAction(); addr = addr + 0x4; } else { printf("busy: %d\n", storage->getSR1()); } } 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; }