I am trying to implement the kit accelerometer, and I started by basing it off of the HiTechncCompass class from last years code. (I can't find the newest version, but I doubt that class has changed). The problem I am having is when I try to initialize the I2C in my robot constructor, the constructor does not finish and the robot stops responding. The console output from the serial port also does not give me any errors either. Here is the class I started, with simple functions just to see what I can get out of it:
I2CAccel.h
Code:
#ifndef __I2CACCEL__
#define __I2CACCEL__
#include "SensorBase.h"
class I2C;
class I2CAccel : public SensorBase
{
public:
I2CAccel(UINT32 ModuleSlot);
~I2CAccel();
float Get();
private:
static const kAddress = 0x3A;
static const kReadAddress = 0x3B;
static const kPowerSaving = 0x08;
static const kPowerCtrl = 0x2D;
I2C* m_i2c;
};
#endif
I2CAccel.cpp
Code:
#include "I2CAccel.h"
#include "DigitalModule.h"
#include "I2C.h"
I2CAccel::I2CAccel(UINT32 slot)
: m_i2c (NULL)
{
//Somewhere on these 3 lines it fails...
DigitalModule *module = DigitalModule::GetInstance(slot);
m_i2c = module->GetI2C(kAddress);
m_i2c->Write(kPowerSaving,kPowerCtrl);
}
I2CAccel::~I2CAccel()
{
delete m_i2c;
m_i2c = NULL;
}
float I2CAccel::Get()
{
UINT16 value;
m_i2c->Read(kReadAddress, sizeof(value), (UINT8 *)&value);
return (float)value;
}
I was wondering if anyone else has gotten theirs working?