Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AppCore.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "AppCore.h"
  2. #include "Logs.h"
  3. #include "defines.h"
  4. #include "Boiler.h"
  5. #include "globals.h"
  6. #include "HomeActivity.h"
  7. #include "MenuItemActivity.h"
  8. #include "LoaderActivity.h"
  9. #define xstr(s) str(s)
  10. #define str(s) #s
  11. Button g_btnCancel(PIN_BTN_CANCEL);
  12. Button g_btnOk(PIN_BTN_OK);
  13. Button g_btnMinus(PIN_BTN_MINUS);
  14. Button g_btnPlus(PIN_BTN_PLUS);
  15. HibernateService g_hibernateService;
  16. LiquidCrystal g_lcd{PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7};
  17. DigitalOutput g_lcdLed{PIN_LCD_LED};
  18. DigitalOutput g_relay1{PIN_RELAY1};
  19. DigitalOutput g_relay2{PIN_RELAY2};
  20. OneWire g_oneWire{PIN_ONEWIRE};
  21. DallasTemperature g_dallasTemperature{&g_oneWire};
  22. TempInput g_tempInput1{0};
  23. TempInput g_tempInput2{1};
  24. BoilerTankService g_tankService1{&g_appState.tanks[0]};
  25. BoilerTankService g_tankService2{&g_appState.tanks[1]};
  26. AppCoreState g_appState{
  27. .tanks = {
  28. {
  29. .mode = BoilerTankState::Auto,
  30. .setting = 0,
  31. .tempTrigger = TEMP_TRIGGER,
  32. .input = &g_tempInput1,
  33. .relay = &g_relay1
  34. },
  35. {
  36. .mode = BoilerTankState::Auto,
  37. .setting = 0,
  38. .tempTrigger = TEMP_TRIGGER,
  39. .input = &g_tempInput2,
  40. .relay = &g_relay2
  41. }
  42. }
  43. };
  44. Storage g_storage;
  45. LoaderActivity g_loaderActivity;
  46. HomeActivity g_homeActivity;
  47. BoilerTankMenuActivity g_menuWaterActivity(&g_homeActivity, &g_menuVersionActivity, &g_menuHeaterActivity, "Sanitaire",
  48. "", &g_appState.tanks[0]);
  49. BoilerTankMenuActivity g_menuHeaterActivity(&g_homeActivity, &g_menuWaterActivity, &g_menuVersionActivity, "Chauffage",
  50. "", &g_appState.tanks[1]);
  51. MenuItemActivity g_menuVersionActivity(&g_homeActivity, nullptr, &g_menuHeaterActivity, &g_menuWaterActivity, "Version",
  52. xstr(APP_CORE_VERSION) " - " xstr(APP_CORE_COMMIT));
  53. int freeRam()
  54. {
  55. extern int __heap_start, * __brkval;
  56. int v;
  57. return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
  58. }
  59. AppCore::AppCore()
  60. : m_currentActivity(nullptr)
  61. {
  62. }
  63. void AppCore::begin()
  64. {
  65. Serial.begin(9600);
  66. LOG_FN_BEGIN(1);
  67. LOG(1, "Free RAM: %i bytes", freeRam());
  68. g_btnCancel.begin();
  69. g_btnOk.begin();
  70. g_btnMinus.begin();
  71. g_btnPlus.begin();
  72. g_hibernateService.begin();
  73. g_lcd.begin(16, 2);
  74. byte sensorChar[8] = {
  75. B00100,
  76. B01010,
  77. B01010,
  78. B01010,
  79. B01010,
  80. B10001,
  81. B11111,
  82. B01110,
  83. };
  84. g_lcd.createChar(LCD_CHAR_SENSOR, sensorChar);
  85. g_lcdLed.begin();
  86. g_relay1.begin();
  87. g_relay2.begin();
  88. g_dallasTemperature.begin();
  89. g_dallasTemperature.setWaitForConversion(false);
  90. LOG(1, "Found %i sensors", g_dallasTemperature.getDeviceCount());
  91. g_tempInput1.begin();
  92. g_tempInput2.begin();
  93. g_tankService1.begin();
  94. g_tankService2.begin();
  95. setActivity(&g_loaderActivity);
  96. LOG_FN_END(1);
  97. }
  98. void AppCore::loop()
  99. {
  100. LOG_FN_BEGIN(50);
  101. g_btnCancel.read();
  102. g_btnOk.read();
  103. g_btnMinus.read();
  104. g_btnPlus.read();
  105. g_tempInput1.loop();
  106. g_tempInput2.loop();
  107. g_tankService1.loop();
  108. g_tankService2.loop();
  109. g_hibernateService.loop();
  110. if (m_currentActivity)
  111. {
  112. m_currentActivity->loop();
  113. }
  114. LOG_FN_END(50);
  115. }
  116. void AppCore::setActivity(IActivity* activity)
  117. {
  118. m_currentActivity = activity;
  119. m_currentActivity->begin();
  120. }
  121. IActivity* AppCore::getCurrentActivity() const
  122. {
  123. return m_currentActivity;
  124. }