Browse Source

添加灯光控制服务

storage-in-realtime
zhaohe 12 months ago
parent
commit
9035f3b61b
  1. 4
      appsrc/service/app/drain_liquid_service.cpp
  2. 2
      appsrc/service/hardware/device_ctrl_service.cpp
  3. 89
      appsrc/service/hardware/warning_light_controler.cpp
  4. 68
      appsrc/service/hardware/warning_light_controler.hpp
  5. 2
      appsrc/service/main_control_service.cpp

4
appsrc/service/app/drain_liquid_service.cpp

@ -80,5 +80,9 @@ void DrainLiquidService::workThread() {
logger->info("stopDraining"); logger->info("stopDraining");
m_dcs->AddLiquidPump_stop(); m_dcs->AddLiquidPump_stop();
m_dcs->SprayPump_stop(); m_dcs->SprayPump_stop();
if(!thisThread.getExitFlag()){
// m_dcs->WarningLight_setState();
}
m_workstate = kidle; m_workstate = kidle;
} }

2
appsrc/service/hardware/device_ctrl_service.cpp

@ -117,7 +117,7 @@ void DeviceIoControlService::Blower_close() {
CAN_MASTER->blowerCtrl(GET_BOARDID(), 0); CAN_MASTER->blowerCtrl(GET_BOARDID(), 0);
} }
float DeviceIoControlService::Blower_readEI() { float DeviceIoControlService::Blower_readEI() {
if (isInPc()) return;
if (isInPc()) return 0;
return CAN_MASTER->blowerReadEI(GET_BOARDID()) / 1000.0; return CAN_MASTER->blowerReadEI(GET_BOARDID()) / 1000.0;
} }

89
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;
}

68
appsrc/service/hardware/warning_light_controler.hpp

@ -0,0 +1,68 @@
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
//
#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<WarningLightControler> {
THISCLASS(WarningLightControler);
public:
typedef enum {
kstate_uninit,
kstate_idle,
kstate_work,
kstate_warning,
} lightState_t;
private:
shared_ptr<DeviceIoControlService> dcs;
unique_ptr<Thread> 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

2
appsrc/service/main_control_service.cpp

@ -18,6 +18,7 @@
// //
#include "hardware/device_ctrl_service.hpp" #include "hardware/device_ctrl_service.hpp"
#include "hardware/disinfectant_weight_update_service.hpp" #include "hardware/disinfectant_weight_update_service.hpp"
#include "hardware/warning_light_controler.hpp"
using namespace iflytop; using namespace iflytop;
using namespace core; using namespace core;
@ -40,6 +41,7 @@ void MainControlService::initialize() {
// Hardware // Hardware
BUILD_AND_REG_SERRVICE(DeviceIoControlService); BUILD_AND_REG_SERRVICE(DeviceIoControlService);
BUILD_AND_REG_SERRVICE(DisinfectantWeightUpdateService); BUILD_AND_REG_SERRVICE(DisinfectantWeightUpdateService);
BUILD_AND_REG_SERRVICE(WarningLightControler);
// //
BUILD_AND_REG_SERRVICE(PipelinePressureControl); BUILD_AND_REG_SERRVICE(PipelinePressureControl);
BUILD_AND_REG_SERRVICE(UDiskMgrService); BUILD_AND_REG_SERRVICE(UDiskMgrService);

Loading…
Cancel
Save