working commands. singleton deleted

Dependents:   GonioTrainer

ReadCommand.cpp

Committer:
dkester
Date:
2015-06-07
Revision:
3:32afe87d4b62
Parent:
2:c9e47ac47edb
Child:
4:f81029197ab2

File content as of revision 3:32afe87d4b62:

#include "ReadCommand.h"
#include "OfflineCommand.h"

ReadCommand::ReadCommand(Storage* storage)
{
    this->storage = storage;
    this->running = 0;
    this->addr = 0x00;
}

void ReadCommand::initialize()
{
    printf("ReadCommand\n");
    setLed(1);
}

void ReadCommand::finish()
{
    setLed(0);
}


void ReadCommand::execute()
{
    //Read has nothing to do with the IMU interrupt
}

void ReadCommand::button()
{
    printf("**** BUTTON: ReadCommand    *****\n");

    __disable_irq();
    readFromMemory();
    __enable_irq();
}


void ReadCommand::readFromMemory()
{
    uint8_t angle[2]= {0,0};
    int8_t imu[2]= {0,0};

    uint32_t addr = 0; 
    
    do{
        storage->read(addr);

        angle[0] = storage->readData();
        angle[1] = storage->readData();
        imu[0] = storage->readData();
        imu[1] = storage->readData();

        storage->endAction();
        
        printf("Memory: angle = %.2f, ", ((float)(angle[0] << 8) + angle[1]) * 0.087912087);
        printf("accelX = %.2f\n", ((float)(imu[0] << 8) + imu[1]) / 16.4);
        addr = addr + 4;
        
    } while(angle[0] != 255);
    
    printf("DONE!\n");
}