Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
TestAccelerometer.cpp@3:1a9d0f0a50bf, 2017-01-14 (annotated)
- Committer:
- dupm2216
- Date:
- Sat Jan 14 22:37:34 2017 +0000
- Revision:
- 3:1a9d0f0a50bf
- Child:
- 4:303fb83498fd
Convert raw axis data to int; ; Agreed, it kind of looks dumb; ; Also:; - Move Tests in TestAccelerometer; - Accelerometer constructor now takes PinName's instead of a I2C device
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dupm2216 | 3:1a9d0f0a50bf | 1 | #include "TestAccelerometer.hpp" |
dupm2216 | 3:1a9d0f0a50bf | 2 | #include "Accelerometer.hpp" |
dupm2216 | 3:1a9d0f0a50bf | 3 | #include "mbed.h" |
dupm2216 | 3:1a9d0f0a50bf | 4 | |
dupm2216 | 3:1a9d0f0a50bf | 5 | #include <cassert> |
dupm2216 | 3:1a9d0f0a50bf | 6 | |
dupm2216 | 3:1a9d0f0a50bf | 7 | namespace accelerometer |
dupm2216 | 3:1a9d0f0a50bf | 8 | { |
dupm2216 | 3:1a9d0f0a50bf | 9 | void run_all_tests() |
dupm2216 | 3:1a9d0f0a50bf | 10 | { |
dupm2216 | 3:1a9d0f0a50bf | 11 | test_raw_axis_data_to_int(); |
dupm2216 | 3:1a9d0f0a50bf | 12 | test_set_standby_and_active(); |
dupm2216 | 3:1a9d0f0a50bf | 13 | } |
dupm2216 | 3:1a9d0f0a50bf | 14 | |
dupm2216 | 3:1a9d0f0a50bf | 15 | void test_raw_axis_data_to_int() |
dupm2216 | 3:1a9d0f0a50bf | 16 | { |
dupm2216 | 3:1a9d0f0a50bf | 17 | assert(128 == (unsigned char)(0x80)); |
dupm2216 | 3:1a9d0f0a50bf | 18 | assert(-128 == (signed char)(0x80)); |
dupm2216 | 3:1a9d0f0a50bf | 19 | |
dupm2216 | 3:1a9d0f0a50bf | 20 | assert(0 == raw_axis_data_to_int(0x00)); |
dupm2216 | 3:1a9d0f0a50bf | 21 | assert(1 == raw_axis_data_to_int(0x01)); |
dupm2216 | 3:1a9d0f0a50bf | 22 | assert(127 == raw_axis_data_to_int(0x7F)); |
dupm2216 | 3:1a9d0f0a50bf | 23 | assert(-1 == raw_axis_data_to_int(0xFF)); |
dupm2216 | 3:1a9d0f0a50bf | 24 | assert(-128 == raw_axis_data_to_int(0x80)); |
dupm2216 | 3:1a9d0f0a50bf | 25 | } |
dupm2216 | 3:1a9d0f0a50bf | 26 | |
dupm2216 | 3:1a9d0f0a50bf | 27 | void test_set_standby_and_active() |
dupm2216 | 3:1a9d0f0a50bf | 28 | { |
dupm2216 | 3:1a9d0f0a50bf | 29 | Accelerometer accelerometer(p9, p10, I2C_ACCELEROMETER_ADDRESS); |
dupm2216 | 3:1a9d0f0a50bf | 30 | |
dupm2216 | 3:1a9d0f0a50bf | 31 | accelerometer.set_standby(); |
dupm2216 | 3:1a9d0f0a50bf | 32 | char value = accelerometer.read_register(CTRL_REG1_REGISTER_ADDRESS); |
dupm2216 | 3:1a9d0f0a50bf | 33 | if(value % 2 != 0) |
dupm2216 | 3:1a9d0f0a50bf | 34 | { |
dupm2216 | 3:1a9d0f0a50bf | 35 | printf("Fail\r\n"); |
dupm2216 | 3:1a9d0f0a50bf | 36 | } |
dupm2216 | 3:1a9d0f0a50bf | 37 | |
dupm2216 | 3:1a9d0f0a50bf | 38 | accelerometer.set_active(); |
dupm2216 | 3:1a9d0f0a50bf | 39 | value = accelerometer.read_register(CTRL_REG1_REGISTER_ADDRESS); |
dupm2216 | 3:1a9d0f0a50bf | 40 | if(value % 2 != 1) |
dupm2216 | 3:1a9d0f0a50bf | 41 | { |
dupm2216 | 3:1a9d0f0a50bf | 42 | printf("Fail\r\n"); |
dupm2216 | 3:1a9d0f0a50bf | 43 | } |
dupm2216 | 3:1a9d0f0a50bf | 44 | } |
dupm2216 | 3:1a9d0f0a50bf | 45 | } |