mirror of https://github.com/ARMmbed/mbed-os.git
Added KL25Z_5 MMA8451Q accelerometer test to test automation suite
parent
9f0911462f
commit
6b044ada5b
|
@ -1,7 +1,6 @@
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "MMA8451Q.h"
|
#include "MMA8451Q.h"
|
||||||
|
#include "test_env.h"
|
||||||
#define MMA8451_I2C_ADDRESS (0x1d<<1)
|
|
||||||
|
|
||||||
#ifdef TARGET_KL05Z
|
#ifdef TARGET_KL05Z
|
||||||
#define SDA PTB4
|
#define SDA PTB4
|
||||||
|
@ -11,18 +10,37 @@
|
||||||
#define SCL PTE24
|
#define SCL PTE24
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const int MMA8451_I2C_ADDRESS = 0x1D << 1; // I2C bus address
|
||||||
|
const float MMA8451_DIGITAL_SENSITIVITY = 4096.0; // Counts/g
|
||||||
|
}
|
||||||
|
|
||||||
|
float calc_3d_vector_len(float x, float y, float z) {
|
||||||
|
return sqrt(x*x + y*y + z*z);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_ITERATIONS 25
|
||||||
|
#define TEST_ITERATIONS_SKIP 5
|
||||||
|
#define MEASURE_DEVIATION_TOLERANCE 0.025 // 2.5%
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
DigitalOut led(LED_GREEN);
|
DigitalOut led(LED_GREEN);
|
||||||
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
|
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
|
||||||
printf("WHO AM I: 0x%2X\r\n", acc.getWhoAmI());
|
bool result = true;
|
||||||
|
printf("WHO AM I: 0x%2X\r\n\n", acc.getWhoAmI());
|
||||||
|
|
||||||
while (true) {
|
for (int i = 0; i < TEST_ITERATIONS; i++) {
|
||||||
printf("-----------\r\n");
|
if (i < TEST_ITERATIONS_SKIP) {
|
||||||
printf("acc_x: %d\r\n", acc.getAccX());
|
// Skip first 5 measurements
|
||||||
printf("acc_y: %d\r\n", acc.getAccY());
|
continue;
|
||||||
printf("acc_z: %d\r\n", acc.getAccZ());
|
}
|
||||||
|
const float g_vect_len = calc_3d_vector_len(acc.getAccX(), acc.getAccY(), acc.getAccZ()) / MMA8451_DIGITAL_SENSITIVITY;
|
||||||
wait(1);
|
const float deviation = fabs(g_vect_len - 1.0);
|
||||||
|
const char *succes_str = deviation <= MEASURE_DEVIATION_TOLERANCE ? "[OK]" : "[FAIL]";
|
||||||
|
result = result && (deviation <= MEASURE_DEVIATION_TOLERANCE);
|
||||||
|
printf("X:% 6d Y:% 6d Z:% 5d GF:%0.3fg, dev:%0.3f ... %s\r\n", acc.getAccX(), acc.getAccY(), acc.getAccZ(), g_vect_len, deviation, succes_str);
|
||||||
|
wait(0.5);
|
||||||
led = !led;
|
led = !led;
|
||||||
}
|
}
|
||||||
|
notify_completion(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -764,6 +764,8 @@ TESTS = [
|
||||||
"source_dir": join(TEST_DIR, "mbed", "i2c_MMA8451Q"),
|
"source_dir": join(TEST_DIR, "mbed", "i2c_MMA8451Q"),
|
||||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, join(PERIPHERALS, 'MMA8451Q')],
|
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, join(PERIPHERALS, 'MMA8451Q')],
|
||||||
"mcu": ["KL25Z", "KL05Z", "KL46Z"],
|
"mcu": ["KL25Z", "KL05Z", "KL46Z"],
|
||||||
|
"automated": True,
|
||||||
|
"duration": 15,
|
||||||
},
|
},
|
||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
|
|
Loading…
Reference in New Issue