added example with const bitfield

master
polymurph 4 years ago
parent 5c7200fa0a
commit ee90ae423b

@ -51,8 +51,8 @@ void Device::doSomething()
void Device::status() void Device::status()
{ {
// imitating read hardware register // imitating read hardware register (for example reading from device via SPI or i2c)
reg_motorStatus = 0xFF; reg_motorStatus = 0xFE;
if(reg_motorStatus.bits.POWER == Reg_MotorStatus::POWER::ON) { if(reg_motorStatus.bits.POWER == Reg_MotorStatus::POWER::ON) {
std::cout << "Motor is Powered ON!" << std::endl; std::cout << "Motor is Powered ON!" << std::endl;
@ -61,7 +61,9 @@ void Device::status()
} }
// will throw error because this bitfield is set const! // will throw error because this bitfield is set const!
//std::cout << "Motor is Powered ON!" << std::endl; //reg_motorStatus.bits.STATUS = Reg_MotorStatus::STATUS::STANDSTILL;
std::cout << +reg_motorStatus.bits.POWER << std::endl; std::cout << +reg_motorStatus.bits.POWER << std::endl;
std::cout << "Motor Status : " << +reg_motorStatus.bits.STATUS << std::endl;
} }
Loading…
Cancel
Save