working commands. singleton deleted

Dependents:   GonioTrainer

ReadCommand.cpp

Committer:
dkester
Date:
2015-06-07
Revision:
1:fd4c0e2decb8
Parent:
0:e188325211af
Child:
2:c9e47ac47edb

File content as of revision 1:fd4c0e2decb8:

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

ReadCommand::ReadCommand()
{
    Storage* storage = Storage::getInstance();
    Sensors* sensors = Sensors::getInstance();
    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()
{
    float angle;
    float gyro;

    for(int i = 0; i <= OfflineCommand::getLastAddress(); i = i + 4 ) {
        this->storage->read(i);

        angle_H= this->storage->readData();
        angle_L = this->storage->readData();
        imu_H = this->storage->readData();
        imu_L = this->storage->readData();

        this->storage->endAction();

        angle = ((angle_H << 8) + angle_L) * 0.087912087;
        
        
        gyro = ((float)((imu_H << 8) + imu_L)) / 200;
        //float xgyro = ((float)sensors->getGyroX())/200;
     

        printf("Memory: angle = %.2f, gyroX =  %.4f\n", angle, gyro);
    }


    printf("DONE!\n");
}