123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #include "AppCore.h"
- #include "Logs.h"
-
- #include "defines.h"
- #include "Boiler.h"
- #include "globals.h"
- #include "HomeActivity.h"
- #include "MenuItemActivity.h"
- #include "LoaderActivity.h"
-
- #define xstr(s) str(s)
- #define str(s) #s
-
- Button g_btnCancel(PIN_BTN_CANCEL);
- Button g_btnOk(PIN_BTN_OK);
- Button g_btnMinus(PIN_BTN_MINUS);
- Button g_btnPlus(PIN_BTN_PLUS);
- HibernateService g_hibernateService;
- LiquidCrystal g_lcd{PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7};
- DigitalOutput g_lcdLed{PIN_LCD_LED};
- DigitalOutput g_relay1{PIN_RELAY1};
- DigitalOutput g_relay2{PIN_RELAY2};
- OneWire g_oneWire{PIN_ONEWIRE};
- DallasTemperature g_dallasTemperature{&g_oneWire};
- TempInput g_tempInput1{0};
- TempInput g_tempInput2{1};
- BoilerTankService g_tankService1{&g_appState.tanks[0]};
- BoilerTankService g_tankService2{&g_appState.tanks[1]};
-
- AppCoreState g_appState{
- .tanks = {
- {
- .mode = BoilerTankState::Auto,
- .setting = 0,
- .tempTrigger = TEMP_TRIGGER,
- .input = &g_tempInput1,
- .relay = &g_relay1
- },
- {
- .mode = BoilerTankState::Auto,
- .setting = 0,
- .tempTrigger = TEMP_TRIGGER,
- .input = &g_tempInput2,
- .relay = &g_relay2
- }
- }
- };
- Storage g_storage;
-
- LoaderActivity g_loaderActivity;
- HomeActivity g_homeActivity;
- BoilerTankMenuActivity g_menuWaterActivity(&g_homeActivity, &g_menuVersionActivity, &g_menuHeaterActivity, "Sanitaire",
- "", &g_appState.tanks[0]);
- BoilerTankMenuActivity g_menuHeaterActivity(&g_homeActivity, &g_menuWaterActivity, &g_menuVersionActivity, "Chauffage",
- "", &g_appState.tanks[1]);
- MenuItemActivity g_menuVersionActivity(&g_homeActivity, nullptr, &g_menuHeaterActivity, &g_menuWaterActivity, "Version",
- xstr(APP_CORE_VERSION) " - " xstr(APP_CORE_COMMIT));
-
-
- int freeRam()
- {
- extern int __heap_start, * __brkval;
- int v;
- return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
- }
-
- AppCore::AppCore()
- : m_currentActivity(nullptr)
- {
- }
-
- void AppCore::begin()
- {
- Serial.begin(9600);
- LOG_FN_BEGIN(1);
-
- LOG(1, "Free RAM: %i bytes", freeRam());
-
- g_btnCancel.begin();
- g_btnOk.begin();
- g_btnMinus.begin();
- g_btnPlus.begin();
-
- g_hibernateService.begin();
-
- g_lcd.begin(16, 2);
- byte sensorChar[8] = {
- B00100,
- B01010,
- B01010,
- B01010,
- B01010,
- B10001,
- B11111,
- B01110,
- };
- g_lcd.createChar(LCD_CHAR_SENSOR, sensorChar);
-
- g_lcdLed.begin();
- g_relay1.begin();
- g_relay2.begin();
-
- g_dallasTemperature.begin();
- g_dallasTemperature.setWaitForConversion(false);
- LOG(1, "Found %i sensors", g_dallasTemperature.getDeviceCount());
-
- g_tempInput1.begin();
- g_tempInput2.begin();
-
- g_tankService1.begin();
- g_tankService2.begin();
-
- setActivity(&g_loaderActivity);
-
- LOG_FN_END(1);
- }
-
- void AppCore::loop()
- {
- LOG_FN_BEGIN(50);
-
- g_btnCancel.read();
- g_btnOk.read();
- g_btnMinus.read();
- g_btnPlus.read();
-
- g_tempInput1.loop();
- g_tempInput2.loop();
-
- g_tankService1.loop();
- g_tankService2.loop();
-
- g_hibernateService.loop();
-
- if (m_currentActivity)
- {
- m_currentActivity->loop();
- }
-
- LOG_FN_END(50);
- }
-
- void AppCore::setActivity(IActivity* activity)
- {
- m_currentActivity = activity;
- m_currentActivity->begin();
- }
-
- IActivity* AppCore::getCurrentActivity() const
- {
- return m_currentActivity;
- }
|