working commands. singleton deleted

Dependents:   GonioTrainer

OfflineCommand.cpp

Committer:
dkester
Date:
2015-06-04
Revision:
0:e188325211af
Child:
1:fd4c0e2decb8

File content as of revision 0:e188325211af:

#include "OfflineCommand.h"

OfflineCommand::OfflineCommand()
{
    this->sensors = Sensors::getInstance();
    this->storage = Storage::getInstance();
    this->addr = 0x0;
    this->running = 0;
}

void OfflineCommand::initialize()
{
    printf("OfflineCommand\n");
    setTicker(0.1);
}

void OfflineCommand::execute()
{
    if(running) {
        writeToMemory();
    }
}

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);
        }

        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();
    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();
        
        this->addr = this->addr + 0x4;
        
    } else {
        printf("busy: %d\n", storage->getSR1());
    }

}

void OfflineCommand::eraseMemory(){
    
    }