cek bisa gak
Revision 2:a45896ca96f0, committed 2019-03-21
- Comitter:
- hisyamfs
- Date:
- Thu Mar 21 14:16:40 2019 +0000
- Parent:
- 1:a129c630cee0
- Commit message:
- - nambahin fungsi untuk ngecek status kalibrasi; - benerin bug pada fungsi kalibrasi; - nambahin fungsi untuk menghapus profil kalibrasi
Changed in this revision
CMPS_KRAI.cpp | Show annotated file Show diff for this revision Revisions of this file |
CMPS_KRAI.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r a129c630cee0 -r a45896ca96f0 CMPS_KRAI.cpp --- a/CMPS_KRAI.cpp Thu Mar 21 13:50:22 2019 +0000 +++ b/CMPS_KRAI.cpp Thu Mar 21 14:16:40 2019 +0000 @@ -51,7 +51,7 @@ char registerNumber = SOFTWARE_REVISION_REG; char calibrate_data1 = 0xF0; char calibrate_data2 = 0xF5; - char calibrate_data3 = 0xF7; + char calibrate_data3 = 0xF6; //kirim data 1 wait_ms(25); i2c->write(i2cAddress, ®isterNumber, 1); @@ -75,9 +75,41 @@ } void CMPS_KRAI::eraseProfile() { - + char registerNumber = SOFTWARE_REVISION_REG; + char calibrate_data1 = 0xE0; + char calibrate_data2 = 0xE5; + char calibrate_data3 = 0xE2; + //kirim data 1 + wait_ms(25); + i2c->write(i2cAddress, ®isterNumber, 1); + i2c->write(i2cAddress, &calibrate_data1, 1); + //kirim data 2 delay 25ms + wait_ms(25); + i2c->write(i2cAddress, ®isterNumber, 1); + i2c->write(i2cAddress, &calibrate_data2, 1); + //kirim data 3 delay 25ms + wait_ms(25); + i2c->write(i2cAddress, ®isterNumber, 1); + i2c->write(i2cAddress, &calibrate_data3, 1); } -void CMPS_KRAI::storeProfile() { - +int CMPS_KRAI::state(int sys) { + int status = -1; + char buf = 0x00; + char registerNumber = CMPS12_CALIBRATION_STATE_REG; + i2c->write(i2cAddress, ®isterNumber, 1); + i2c->read(i2cAddress, &buf, 1); + switch (sys) { + case SYSTEM_STATE: + status = (buf >> 6) & 0x3; + case GYRO_STATE: + status = (buf >> 4) & 0x3; + case ACCEL_STATE: + status = (buf >> 2) & 0x3; + case MAG_STATE: + status = buf & 0x3; + default: + status = -1; + } + return status; } \ No newline at end of file
diff -r a129c630cee0 -r a45896ca96f0 CMPS_KRAI.h --- a/CMPS_KRAI.h Thu Mar 21 13:50:22 2019 +0000 +++ b/CMPS_KRAI.h Thu Mar 21 14:16:40 2019 +0000 @@ -17,6 +17,13 @@ //set register kompas #define SOFTWARE_REVISION_REG 0x0 #define COMPASS_BEARING_WORD_REG 0x2 +#define CMPS12_CALIBRATION_STATE_REG 0x1E + +#define SYSTEM_STATE 3 +#define GYRO_STATE 2 +#define ACCEL_STATE 1 +#define MAG_STATE 0 + //Inisiasi I2C komunikasi dari kompas class CMPS_KRAI { @@ -56,13 +63,11 @@ */ void stopCalibrate(void); - /** - /* Menghapus calibration profile - */ +// Menghapus calibration profile void eraseProfile(); - // Menyimpan calibration profile - void storeProfile(); + // Cek status kalibrasi + int state(int sys); }; #endif /* CMPS_KRAI_H */