Skip to content

Commit 15c1a45

Browse files
committed
simplified struct Verification
1 parent ba9a743 commit 15c1a45

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/modm/driver/motion/adns9800.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,21 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
158158
/// @endcond
159159
};
160160

161-
union VerificationResult {
162-
uint8_t value;
163-
struct {
164-
bool ProductId: 1;
165-
bool ProductIdInverse: 1;
166-
bool RevisionId: 1;
167-
};
168-
static constexpr uint8_t Ok = 0b111;
161+
struct Verification {
162+
bool ProductId: 1;
163+
bool ProductIdInverse: 1;
164+
bool RevisionId: 1;
165+
166+
operator bool() const {
167+
return ProductId and ProductIdInverse and RevisionId;
168+
}
169169
};
170170

171171
void
172172
initialize() {
173173
powerUp();
174-
const VerificationResult result = verifyIdentity();
175-
if(result.value == VerificationResult::Ok) {
174+
175+
if(verify()) {
176176
writeFirmware();
177177
laserEnable();
178178
}
@@ -201,12 +201,12 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
201201
/**
202202
* @brief Verify presence of the device by validating various id registers.
203203
*/
204-
VerificationResult
205-
verifyIdentity() {
206-
return VerificationResult{
207-
ProductId: readRegister(Register::Product_ID) == uint8_t(0x33),
208-
ProductIdInverse: readRegister(Register::Inverse_Product_ID) == uint8_t(~0x33),
209-
RevisionId: readRegister(Register::Revision_ID) == uint8_t(0x03)
204+
Verification
205+
verify() {
206+
return {
207+
ProductId: readRegister(Register::Product_ID) == static_cast<uint8_t>(0x33),
208+
ProductIdInverse: readRegister(Register::Inverse_Product_ID) == static_cast<uint8_t>(~0x33),
209+
RevisionId: readRegister(Register::Revision_ID) == static_cast<uint8_t>(0x03)
210210
};
211211
}
212212

0 commit comments

Comments
 (0)