Skip to content

Commit ce43b2f

Browse files
authored
🐛 Support fake WHO_AM_I in mpu6050 (#19)
1 parent 7673ab1 commit ce43b2f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/imu/mpu6050.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,26 @@ mpu6050::mpu6050(hal::i2c& p_i2c, hal::byte p_device_address)
5555
: m_i2c(&p_i2c)
5656
, m_address(p_device_address)
5757
{
58-
static constexpr hal::byte expected_device_id = 0x68;
58+
constexpr std::array<hal::u8, 2> expected_ids = {
59+
0x68, // real mpu6050 who_am_i value
60+
0x72, // fake mpu6050 who_am_i value (but still works)
61+
};
5962
// Read out the identity register
60-
auto device_id =
63+
auto const device_id =
6164
hal::write_then_read<1>(*m_i2c,
6265
m_address,
6366
std::array{ hal::sensor::who_am_i_register },
6467
hal::never_timeout())[0];
6568

66-
if (device_id != expected_device_id) {
69+
bool id_verified = false;
70+
for (auto const& id : expected_ids) {
71+
if (device_id == id) {
72+
id_verified = true;
73+
break;
74+
}
75+
}
76+
77+
if (not id_verified) {
6778
hal::safe_throw(hal::no_such_device(m_address, this));
6879
}
6980

0 commit comments

Comments
 (0)