BatteryMould.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include <memory>
  3. #include "ResDataObject.h"
  4. #include "DIOS.Dev.IODevice.hpp"
  5. #include "DIOS.Dev.MouldDefine.hpp"
  6. namespace DIOS::Dev::Detail
  7. {
  8. #pragma region DeviceBatteryMould
  9. class DeviceBatteryMould : public IntMouldWithWarn
  10. {
  11. typedef enum ECOM_Battery_state
  12. {
  13. ECOM_BAT_STATE_TOO_LOW = 0,
  14. ECOM_BAT_STATE_LOW,
  15. ECOM_BAT_STAE_NORMAL,
  16. ECOM_BAT_STATE_GOOD,
  17. ECOM_BAT_STATE_FULL
  18. }ECOM_BATTERY_STATE;
  19. int m_RemainPowerValue;
  20. //ResDataObject m_Cache;
  21. std::shared_ptr <DIOS::Dev::IOEventCenter> m_EventCenter;
  22. std::string m_Key;
  23. public:
  24. using super = IntMouldWithWarn;
  25. DeviceBatteryMould(const char* strkey, int initialvalue, int min, int WarnMin, int WarnMax, int max, int accuracy, std::shared_ptr <DIOS::Dev::IOEventCenter> EventCenter)
  26. :super(strkey, initialvalue, min, WarnMin, WarnMax, max, accuracy)
  27. {
  28. m_Key = strkey;
  29. m_EventCenter = EventCenter;
  30. m_RemainPowerValue = 0;
  31. }
  32. ~DeviceBatteryMould() {}
  33. std::string GetDescription()
  34. {
  35. ResDataObject temp, result;
  36. temp.add(ValKey::UPPERLIMIT, m_LimitMax);
  37. temp.add(ValKey::LOWERLIMIT, m_LimitMin);
  38. temp.add(ValKey::WARNUPPERLIMIT, m_WarningMax);
  39. temp.add(ValKey::WARNLOWERLIMIT, m_WarningMin);
  40. temp.add(ValKey::ACCURACY, m_Accuracy);
  41. temp.add(ValKey::UNIT, m_Key.c_str());
  42. result.add(Key.c_str(), temp);
  43. return result.encode();
  44. }
  45. RET_STATUS JSGetCurrentBatteryValue(std::string & out)
  46. {
  47. char szFDinfo[MAX_STRING] = { 0 };
  48. sprintf_s(szFDinfo, "%d", m_RemainPowerValue);
  49. out = szFDinfo;
  50. return RET_STATUS::RET_SUCCEED;
  51. }
  52. bool SetRemainPowerValue(int nValue, int & nStatus)
  53. {
  54. if (nValue != m_RemainPowerValue)
  55. {
  56. m_RemainPowerValue = nValue;
  57. if (m_WarningMin <= nValue)
  58. {
  59. nStatus = ECOM_BAT_STAE_NORMAL;
  60. }
  61. else if (m_LimitMin <= nValue && nValue < m_WarningMin)
  62. {
  63. nStatus = ECOM_BAT_STATE_LOW;
  64. }
  65. else if (nValue < m_LimitMin)
  66. {
  67. nStatus = ECOM_BAT_STATE_TOO_LOW;
  68. }
  69. char szFDinfo[MAX_STRING] = { 0 };
  70. sprintf_s(szFDinfo, "%d", nValue);
  71. //std::string str = szFDinfo;
  72. m_EventCenter->OnNotify((int)ATTRACTION_SET, "Remain_Power_Value", szFDinfo);
  73. }
  74. return true;
  75. };
  76. };
  77. #pragma endregion DeviceBatteryMould
  78. }