You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
#include "device.hpp"
|
|
#include <iostream>
|
|
|
|
Device::Device() :
|
|
reg_control(0x00)
|
|
{
|
|
|
|
std::cout << "Device::Device()" << std::endl;
|
|
std::cout << +reg_control.raw << std::endl;
|
|
|
|
reg_control.bits.POWER_DEV = Reg_Control::POWER_DEV::TURN_OFF;
|
|
reg_control.bits.SPEED = Reg_Control::SPEED::STAND_STILL;
|
|
|
|
std::cout << "POWER = " << +reg_control.bits.POWER_DEV << std::endl;
|
|
std::cout << "SPEED = " <<+reg_control.bits.SPEED << std::endl;
|
|
}
|
|
|
|
void Device::doSomething()
|
|
{
|
|
std::cout << "Device::doSomething()" << std::endl;
|
|
|
|
reg_control.bits.POWER_DEV = Reg_Control::POWER_DEV::TURN_ON;
|
|
reg_control.bits.SPEED = Reg_Control::SPEED::FAST;
|
|
|
|
if(reg_control.bits.POWER_DEV == Reg_Control::POWER_DEV::TURN_ON){
|
|
std::cout << "device turned on!" << std::endl;
|
|
}
|
|
|
|
std::cout << "POWER = " << +reg_control.bits.POWER_DEV << std::endl;
|
|
std::cout << "SPEED = " << +reg_control.bits.SPEED << std::endl;
|
|
|
|
std::cout << +reg_control << std::endl;
|
|
|
|
reg_control = 0;
|
|
|
|
std::cout << +reg_control << std::endl;
|
|
|
|
std::cout << "POWER = " << +reg_control.bits.POWER_DEV << std::endl;
|
|
std::cout << "SPEED = " << +reg_control.bits.SPEED << std::endl;
|
|
|
|
//reg_control.bits.SPEED = Reg_Control::SPEED::FAST;
|
|
reg_control.bits.POWER_DEV = Reg_Control::POWER_DEV::TURN_ON;
|
|
|
|
std::cout << "POWER = " << +reg_control.bits.POWER_DEV << std::endl;
|
|
std::cout << "SPEED = " << +reg_control.bits.SPEED << std::endl;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
void Device::status()
|
|
{
|
|
// imitating read hardware register (for example reading from device via SPI or i2c)
|
|
reg_motorStatus = 0xFE;
|
|
|
|
if(reg_motorStatus.bits.POWER == Reg_MotorStatus::POWER::ON) {
|
|
std::cout << "Motor is Powered ON!" << std::endl;
|
|
} else {
|
|
std::cout << "Motor is Powered OFF!" << std::endl;
|
|
}
|
|
|
|
// will throw error because this bitfield is set const!
|
|
//reg_motorStatus.bits.STATUS = Reg_MotorStatus::STATUS::STANDSTILL;
|
|
|
|
std::cout << +reg_motorStatus.bits.POWER << std::endl;
|
|
|
|
std::cout << "Motor Status : " << +reg_motorStatus.bits.STATUS << std::endl;
|
|
} |