diff --git a/appsrc/service/app/drain_liquid_service.cpp b/appsrc/service/app/drain_liquid_service.cpp index 361a51c..582872e 100644 --- a/appsrc/service/app/drain_liquid_service.cpp +++ b/appsrc/service/app/drain_liquid_service.cpp @@ -80,5 +80,9 @@ void DrainLiquidService::workThread() { logger->info("stopDraining"); m_dcs->AddLiquidPump_stop(); m_dcs->SprayPump_stop(); + + if(!thisThread.getExitFlag()){ + // m_dcs->WarningLight_setState(); + } m_workstate = kidle; } diff --git a/appsrc/service/hardware/device_ctrl_service.cpp b/appsrc/service/hardware/device_ctrl_service.cpp index 111b79c..d6dae92 100644 --- a/appsrc/service/hardware/device_ctrl_service.cpp +++ b/appsrc/service/hardware/device_ctrl_service.cpp @@ -117,7 +117,7 @@ void DeviceIoControlService::Blower_close() { CAN_MASTER->blowerCtrl(GET_BOARDID(), 0); } float DeviceIoControlService::Blower_readEI() { - if (isInPc()) return; + if (isInPc()) return 0; return CAN_MASTER->blowerReadEI(GET_BOARDID()) / 1000.0; } diff --git a/appsrc/service/hardware/warning_light_controler.cpp b/appsrc/service/hardware/warning_light_controler.cpp new file mode 100644 index 0000000..92742ac --- /dev/null +++ b/appsrc/service/hardware/warning_light_controler.cpp @@ -0,0 +1,89 @@ +#include "warning_light_controler.hpp" + +using namespace iflytop; +using namespace std; + +void WarningLightControler::workThread() { + ThisThread thisThread; + + int cnt = 0; + while (!thisThread.getExitFlag()) { + thisThread.sleepForMs(100); + + lightState_t nexState = inferTheCurrentLightingState(); + if (m_nowState != nexState) { + changeLightState(nexState); + } + cnt++; + // 1s调用一次 + if (cnt % 10 == 0) { + beepCtrl(m_nowState); + } + } +} + +void WarningLightControler::initialize() { + GET_TO_SERVICE(dcs); + m_thread.reset(new Thread("LightCtrlServiceThread", std::bind(&WarningLightControler::workThread, this))); +} + +void WarningLightControler::beepCtrl(lightState_t state) { + switch (state) { + case kstate_warning: + m_beepState = !m_beepState; + dcs->WarningLight_setState(255, 0, 0, m_beepState ? 255 : 0); + break; + default: + break; + } +} + +void WarningLightControler::changeLightState(lightState_t state) { + m_nowState = state; + + switch (m_nowState) { + case kstate_idle: + // 绿色 + dcs->WarningLight_setState(0, 255, 0, 0); + break; + case kstate_work: + // 黄色 + dcs->WarningLight_setState(0, 0, 255, 0); + break; + case kstate_warning: + // 红色 + dcs->WarningLight_setState(255, 0, 0, 0); + break; + default: + break; + } + + // #if (defined PROJECT_TYPE_PIPE_DISINFECTION) + // switch (m_nowState) { + // case kstate_idle: + // // 绿色 + // m_deviceIoControlService->warningLightCtrl(0, 255, 0, 0); + // break; + // case kstate_work: + // // 黄色 + // m_deviceIoControlService->warningLightCtrl(255, 255, 0, 0); + // break; + // case kstate_warning: + // // 红色 + // m_deviceIoControlService->warningLightCtrl(255, 0, 0, 0); + // break; + // default: + // break; + // } + // #endif +} + +WarningLightControler::lightState_t WarningLightControler::inferTheCurrentLightingState() { + if (m_warningFlag) { + return kstate_warning; + } + if (m_workFlag) { + return kstate_work; + } + return kstate_idle; +} diff --git a/appsrc/service/hardware/warning_light_controler.hpp b/appsrc/service/hardware/warning_light_controler.hpp new file mode 100644 index 0000000..c1f504e --- /dev/null +++ b/appsrc/service/hardware/warning_light_controler.hpp @@ -0,0 +1,68 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +#include "device_ctrl_service.hpp" +// +#include "base/can_packet_dumper.hpp" +#include "base/h2o2_sensor_data_mgr.hpp" +// +#include "appcomponents/algo/moving_average_filter.hpp" +/** + * @brief + * + * service: WarningLightControler + * + * 监听事件: + * 依赖状态: + * 依赖服务: + * 作用: + * + */ + +namespace iflytop { +using namespace std; +using namespace core; + +class WarningLightControler : public enable_shared_from_this { + THISCLASS(WarningLightControler); + + public: + typedef enum { + kstate_uninit, + kstate_idle, + kstate_work, + kstate_warning, + } lightState_t; + + private: + shared_ptr dcs; + unique_ptr m_thread; + + bool m_workFlag = false; + bool m_warningFlag = false; + lightState_t m_nowState = kstate_uninit; + bool m_beepState = false; + + public: + void initialize(); + + void setworkFlag(bool flag) { m_workFlag = flag; } + void setwarningFlag(bool flag) { m_warningFlag = flag; } + + private: + void workThread(); + lightState_t inferTheCurrentLightingState(); + void changeLightState(lightState_t state); + void beepCtrl(lightState_t state); +}; + +}; // namespace iflytop diff --git a/appsrc/service/main_control_service.cpp b/appsrc/service/main_control_service.cpp index 7e2813e..3d75d06 100644 --- a/appsrc/service/main_control_service.cpp +++ b/appsrc/service/main_control_service.cpp @@ -18,6 +18,7 @@ // #include "hardware/device_ctrl_service.hpp" #include "hardware/disinfectant_weight_update_service.hpp" +#include "hardware/warning_light_controler.hpp" using namespace iflytop; using namespace core; @@ -40,6 +41,7 @@ void MainControlService::initialize() { // Hardware BUILD_AND_REG_SERRVICE(DeviceIoControlService); BUILD_AND_REG_SERRVICE(DisinfectantWeightUpdateService); + BUILD_AND_REG_SERRVICE(WarningLightControler); // BUILD_AND_REG_SERRVICE(PipelinePressureControl); BUILD_AND_REG_SERRVICE(UDiskMgrService);