File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments