working commands. singleton deleted

Dependents:   GonioTrainer

Revision:
0:e188325211af
Child:
1:fd4c0e2decb8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OfflineCommand.cpp	Thu Jun 04 10:56:18 2015 +0000
@@ -0,0 +1,86 @@
+#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(){
+    
+    }