diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index bcd2a5a5..5ed6445e 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -228,10 +228,6 @@ ReturnValue_t ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF, auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF, spiCookieRadSensor, gpioComIF, stackHandler); static_cast(radSensor); - // The radiation sensor ADC is powered by the 5V stack connector which should always be on - radSensor->setStartUpImmediately(); - // It's a simple sensor, so just to to normal mode immediately - radSensor->setToGoToNormalModeImmediately(); #if OBSW_DEBUG_RAD_SENSOR == 1 radSensor->enablePeriodicDataPrint(true); #endif diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index f8e0df9e..411dd510 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -7,8 +7,11 @@ RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie, GpioIF *gpioIF, - Stack5VHandler &handler) - : DeviceHandlerBase(objectId, comIF, comCookie), dataset(this), gpioIF(gpioIF) { + Stack5VHandler &stackHandler) + : DeviceHandlerBase(objectId, comIF, comCookie), + dataset(this), + gpioIF(gpioIF), + stackHandler(stackHandler) { if (comCookie == nullptr) { sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; } @@ -17,12 +20,22 @@ RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t RadiationSensorHandler::~RadiationSensorHandler() {} void RadiationSensorHandler::doStartUp() { + if (internalState == InternalState::OFF) { + ReturnValue_t retval = stackHandler.deviceToOn(StackCommander::RAD_SENSOR); + if (retval == BUSY) { + return; + } + internalState = InternalState::POWER_SWITCHING; + } + if (internalState == InternalState::POWER_SWITCHING) { + if (stackHandler.isSwitchOn()) { + internalState == InternalState::SETUP; + } + } if (internalState == InternalState::CONFIGURED) { if (goToNormalMode) { setMode(MODE_NORMAL); - } - - else { + } else { setMode(_MODE_TO_ON); } } diff --git a/mission/devices/RadiationSensorHandler.h b/mission/devices/RadiationSensorHandler.h index dff273a0..b4ad39de 100644 --- a/mission/devices/RadiationSensorHandler.h +++ b/mission/devices/RadiationSensorHandler.h @@ -40,16 +40,17 @@ class RadiationSensorHandler : public DeviceHandlerBase { private: enum class CommunicationStep { START_CONVERSION, READ_CONVERSIONS }; - enum class InternalState { SETUP, CONFIGURED }; + enum class InternalState { OFF, POWER_SWITCHING, SETUP, CONFIGURED }; bool printPeriodicData = false; RAD_SENSOR::RadSensorDataset dataset; static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; GpioIF *gpioIF = nullptr; + Stack5VHandler &stackHandler; bool goToNormalMode = false; uint8_t cmdBuffer[MAX_CMD_LEN]; - InternalState internalState = InternalState::SETUP; + InternalState internalState = InternalState::OFF; CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; };