BatteryMould.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #pragma once
  2. #include <memory>
  3. #include "ResDataObject.h"
  4. #include "CCOS.Dev.IODevice.hpp"
  5. #include "CCOS.Dev.MouldDefine.hpp"
  6. namespace CCOS::Dev::Detail
  7. {
  8. #pragma region DeviceBatteryMould
  9. class DeviceBatteryMould : public IntMouldWithWarn
  10. {
  11. typedef enum ZSKK_Battery_state
  12. {
  13. ZSKK_BAT_STATE_TOO_LOW = 0,
  14. ZSKK_BAT_STATE_LOW,
  15. ZSKK_BAT_STAE_NORMAL,
  16. ZSKK_BAT_STATE_GOOD,
  17. ZSKK_BAT_STATE_FULL
  18. }ZSKK_BATTERY_STATE;
  19. int m_RemainPowerValue;
  20. //ResDataObject m_Cache;
  21. std::shared_ptr <CCOS::Dev::IOEventCenter> m_EventCenter;
  22. std::string m_Key;
  23. public:
  24. using super = IntMouldWithWarn;
  25. DeviceBatteryMould(const char* strkey, int initialvalue, int min,
  26. int WarnMin, int WarnMax, int CalibWarnMin, int CalibWarnMax,
  27. int max, int accuracy, std::shared_ptr <CCOS::Dev::IOEventCenter> EventCenter)
  28. :super(strkey, initialvalue, min, WarnMin, WarnMax, CalibWarnMin, CalibWarnMax, max, accuracy)
  29. {
  30. m_Key = strkey;
  31. m_EventCenter = EventCenter;
  32. m_RemainPowerValue = 0;
  33. }
  34. ~DeviceBatteryMould() {}
  35. std::string GetDescription()
  36. {
  37. ResDataObject temp, result;
  38. temp.add(ValKey::UPPERLIMIT, m_LimitMax);
  39. temp.add(ValKey::LOWERLIMIT, m_LimitMin);
  40. temp.add(ValKey::WARNUPPERLIMIT, m_WarningMax);
  41. temp.add(ValKey::WARNLOWERLIMIT, m_WarningMin);
  42. temp.add(ValKey::ACCURACY, m_Accuracy);
  43. temp.add(ValKey::UNIT, m_Key.c_str());
  44. result.add(Key.c_str(), temp);
  45. return result.encode();
  46. }
  47. RET_STATUS JSGetCurrentBatteryValue(std::string & out)
  48. {
  49. char szFDinfo[MAX_STRING] = { 0 };
  50. sprintf_s(szFDinfo, "%d", m_RemainPowerValue);
  51. out = szFDinfo;
  52. return RET_STATUS::RET_SUCCEED;
  53. }
  54. bool SetRemainPowerValue(int nValue, int & nStatus)
  55. {
  56. if (nValue != m_RemainPowerValue)
  57. {
  58. m_RemainPowerValue = nValue;
  59. if (m_WarningMin <= nValue)
  60. {
  61. nStatus = ZSKK_BAT_STAE_NORMAL;
  62. }
  63. else if (m_LimitMin <= nValue && nValue < m_WarningMin)
  64. {
  65. nStatus = ZSKK_BAT_STATE_LOW;
  66. }
  67. else if (nValue < m_LimitMin)
  68. {
  69. nStatus = ZSKK_BAT_STATE_TOO_LOW;
  70. }
  71. char szFDinfo[MAX_STRING] = { 0 };
  72. sprintf_s(szFDinfo, "%d", nValue);
  73. m_EventCenter->OnNotify((int)ATTRACTION_SET, "Remain_Power_Value", szFDinfo);
  74. }
  75. return true;
  76. }
  77. RET_STATUS JSGetBatteryWarningMin(std::string& out)
  78. {
  79. char szFDinfo[MAX_STRING] = { 0 };
  80. sprintf_s(szFDinfo, "%d", m_WarningMin);
  81. out = szFDinfo;
  82. return RET_STATUS::RET_SUCCEED;
  83. }
  84. RET_STATUS JSGetBatteryErrorMin(std::string& out)
  85. {
  86. char szFDinfo[MAX_STRING] = { 0 };
  87. sprintf_s(szFDinfo, "%d", m_ErrorMin);
  88. out = szFDinfo;
  89. return RET_STATUS::RET_SUCCEED;
  90. }
  91. RET_STATUS SetBatteryWarningMin(string nValue)
  92. {
  93. int temp = atoi(nValue.c_str());
  94. if (m_WarningMin == temp)
  95. {
  96. return RET_STATUS::RET_SUCCEED;
  97. }
  98. m_WarningMin = temp;
  99. char szFDinfo[MAX_STRING] = { 0 };
  100. sprintf_s(szFDinfo, "%d", m_WarningMin);
  101. m_EventCenter->OnNotify((int)ATTRACTION_SET, "BatLowerLimit", szFDinfo);
  102. return RET_STATUS::RET_SUCCEED;
  103. }
  104. RET_STATUS SetBatteryErrorMin(string nValue)
  105. {
  106. int temp = atoi(nValue.c_str());
  107. if (m_ErrorMin == temp)
  108. {
  109. return RET_STATUS::RET_SUCCEED;
  110. }
  111. m_ErrorMin = temp;
  112. char szFDinfo[MAX_STRING] = { 0 };
  113. sprintf_s(szFDinfo, "%d", m_ErrorMin);
  114. m_EventCenter->OnNotify((int)ATTRACTION_SET, "BatMiniLimit", szFDinfo);
  115. return RET_STATUS::RET_SUCCEED;
  116. }
  117. RET_STATUS JSGetBatteryCalibWarningMin(std::string& out)
  118. {
  119. char szFDinfo[MAX_STRING] = { 0 };
  120. sprintf_s(szFDinfo, "%d", m_CalibWarningMin);
  121. out = szFDinfo;
  122. return RET_STATUS::RET_SUCCEED;
  123. }
  124. bool SetBatteryCalibWarningMin(int nValue)
  125. {
  126. if (m_CalibWarningMin == nValue)
  127. {
  128. return true;
  129. }
  130. m_CalibWarningMin = nValue;
  131. char szFDinfo[MAX_STRING] = { 0 };
  132. sprintf_s(szFDinfo, "%d", nValue);
  133. m_EventCenter->OnNotify((int)ATTRACTION_SET, "BatLowerLimitInCali", szFDinfo);
  134. return true;
  135. }
  136. };
  137. #pragma endregion DeviceBatteryMould
  138. }