Basic functions is OK. Lack interrupts function.
Revision 4:413b8ef9aed5, committed 2017-03-23
- Comitter:
- bcc6
- Date:
- Thu Mar 23 08:54:15 2017 +0000
- Parent:
- 3:14f634433c89
- Parent:
- 2:afb035feac6c
- Commit message:
- Merge from branch
Changed in this revision
--- a/AK09970.cpp Thu Mar 23 08:42:16 2017 +0000 +++ b/AK09970.cpp Thu Mar 23 08:54:15 2017 +0000 @@ -22,7 +22,7 @@ } -void AK09970::ConfigDevice() { +void AK09970::ConfigDevice(uint8_t mode) { char val[8]; /* Soft reset */ @@ -34,7 +34,8 @@ RegWrite(0x20, val, 2); /* Mode */ - RegWrite(0x21, 0x02); // SMR(HighSensitivity), SDR(LowNoiseDrive), MODE(ContMode1) + _sensitivity = (mode & SMR_WideRange) ? 3.1f : 1.1f; + RegWrite(0x21, mode); } void AK09970::GetDeviceID(uint8_t *id) { @@ -62,7 +63,7 @@ } float AK09970::ConvertAdcToMagnetic(int16_t adc) { - float magnetic_flux_density = (float)adc * 1.1f; + float magnetic_flux_density = (float)adc * _sensitivity; return magnetic_flux_density; }
--- a/AK09970.h Thu Mar 23 08:42:16 2017 +0000 +++ b/AK09970.h Thu Mar 23 08:54:15 2017 +0000 @@ -26,6 +26,28 @@ class AK09970 { public: + enum SMR { + SMR_HighSens = (0<<5), + SMR_WideRange = (1<<5), + }; + + enum SDR { + SDR_LowNoise = (0<<4), + SDR_LowPower = (1<<4), + }; + + enum Mode { + Mode_PowerDown = 0, + Mode_Single, + Mode_1_0p25Hz, + Mode_2_0p5Hz = 4, + Mode_3_1Hz = 6, + Mode_4_10Hz = 8, + Mode_5_20Hz = 10, + Mode_6_50Hz = 12, + Mode_7_100Hz = 14, + }; + struct Data { float x; // uT/LSB float y; @@ -36,13 +58,15 @@ AK09970(I2C &i2c, PinName int1 = NC); - void ConfigDevice(); + void ConfigDevice(uint8_t mode = SMR_HighSens | SDR_LowNoise | Mode_1_0p25Hz); void GetDeviceID(uint8_t *id); void GetData(Data *data); private: I2C &_i2c; InterruptIn _int1; + + float _sensitivity; float ConvertAdcToMagnetic(int16_t adc);