1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #pragma once
- #include <memory>
- #include "ResDataObject.h"
- #include "DIOS.Dev.IODevice.hpp"
- #include "DIOS.Dev.MouldDefine.hpp"
- namespace DIOS::Dev::Detail
- {
- #pragma region DeviceBatteryMould
- class DeviceBatteryMould : public IntMouldWithWarn
- {
- typedef enum ECOM_Battery_state
- {
- ECOM_BAT_STATE_TOO_LOW = 0,
- ECOM_BAT_STATE_LOW,
- ECOM_BAT_STAE_NORMAL,
- ECOM_BAT_STATE_GOOD,
- ECOM_BAT_STATE_FULL
- }ECOM_BATTERY_STATE;
- int m_RemainPowerValue;
- //ResDataObject m_Cache;
- std::shared_ptr <DIOS::Dev::IOEventCenter> m_EventCenter;
- std::string m_Key;
- public:
- using super = IntMouldWithWarn;
- DeviceBatteryMould(const char* strkey, int initialvalue, int min, int WarnMin, int WarnMax, int max, int accuracy, std::shared_ptr <DIOS::Dev::IOEventCenter> EventCenter)
- :super(strkey, initialvalue, min, WarnMin, WarnMax, max, accuracy)
- {
- m_Key = strkey;
- m_EventCenter = EventCenter;
- m_RemainPowerValue = 0;
- }
- ~DeviceBatteryMould() {}
- std::string GetDescription()
- {
- ResDataObject temp, result;
- temp.add(ValKey::UPPERLIMIT, m_LimitMax);
- temp.add(ValKey::LOWERLIMIT, m_LimitMin);
- temp.add(ValKey::WARNUPPERLIMIT, m_WarningMax);
- temp.add(ValKey::WARNLOWERLIMIT, m_WarningMin);
- temp.add(ValKey::ACCURACY, m_Accuracy);
- temp.add(ValKey::UNIT, m_Key.c_str());
- result.add(Key.c_str(), temp);
- return result.encode();
- }
- RET_STATUS JSGetCurrentBatteryValue(std::string & out)
- {
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf_s(szFDinfo, "%d", m_RemainPowerValue);
- out = szFDinfo;
- return RET_STATUS::RET_SUCCEED;
- }
- bool SetRemainPowerValue(int nValue, int & nStatus)
- {
- if (nValue != m_RemainPowerValue)
- {
- m_RemainPowerValue = nValue;
- if (m_WarningMin <= nValue)
- {
- nStatus = ECOM_BAT_STAE_NORMAL;
- }
- else if (m_LimitMin <= nValue && nValue < m_WarningMin)
- {
- nStatus = ECOM_BAT_STATE_LOW;
- }
- else if (nValue < m_LimitMin)
- {
- nStatus = ECOM_BAT_STATE_TOO_LOW;
- }
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf_s(szFDinfo, "%d", nValue);
- //std::string str = szFDinfo;
- m_EventCenter->OnNotify((int)ATTRACTION_SET, "Remain_Power_Value", szFDinfo);
- }
- return true;
- };
- };
- #pragma endregion DeviceBatteryMould
- }
|