Browse Source

Pause hibernate when editing and resetting; Logs

master
Robin Thoni 2 months ago
parent
commit
95717401c9
Signed by: Robin THONI <robin@rthoni.com> GPG Key ID: 4E09DEF46B99E61E
11 changed files with 61 additions and 17 deletions
  1. 14
    5
      AppCore.cpp
  2. 7
    7
      AppCore.h
  3. 6
    0
      BaseActivity.cpp
  4. 3
    4
      Boiler.h
  5. 3
    0
      BoilerTankModeEditorActivity.cpp
  6. 11
    1
      HibernateService.cpp
  7. 4
    0
      HibernateService.h
  8. 1
    0
      HomeActivity.cpp
  9. 2
    0
      LoaderActivity.cpp
  10. 3
    0
      TempEditorActivity.cpp
  11. 7
    0
      TempInput.cpp

+ 14
- 5
AppCore.cpp View File

@@ -55,7 +55,6 @@ BoilerTankMenuActivity g_menuHeaterActivity(&g_homeActivity, &g_menuWaterActivit
55 55
                                             "", &g_appState.tanks[1]);
56 56
 MenuItemActivity g_menuVersionActivity(&g_homeActivity, nullptr, &g_menuHeaterActivity, &g_menuWaterActivity, "Version",
57 57
                                        xstr(APP_CORE_VERSION) " - " xstr(APP_CORE_COMMIT));
58
-IActivity* g_currentActivity = nullptr;
59 58
 
60 59
 
61 60
 int freeRam()
@@ -65,6 +64,11 @@ int freeRam()
65 64
     return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
66 65
 }
67 66
 
67
+AppCore::AppCore()
68
+        : m_currentActivity(nullptr)
69
+{
70
+}
71
+
68 72
 void AppCore::begin()
69 73
 {
70 74
     Serial.begin(9600);
@@ -128,9 +132,9 @@ void AppCore::loop()
128 132
 
129 133
     g_hibernateService.loop();
130 134
 
131
-    if (g_currentActivity)
135
+    if (m_currentActivity)
132 136
     {
133
-        g_currentActivity->loop();
137
+        m_currentActivity->loop();
134 138
     }
135 139
 
136 140
     LOG_FN_END(50);
@@ -138,6 +142,11 @@ void AppCore::loop()
138 142
 
139 143
 void AppCore::setActivity(IActivity* activity)
140 144
 {
141
-    g_currentActivity = activity;
142
-    g_currentActivity->begin();
145
+    m_currentActivity = activity;
146
+    m_currentActivity->begin();
147
+}
148
+
149
+IActivity* AppCore::getCurrentActivity() const
150
+{
151
+    return m_currentActivity;
143 152
 }

+ 7
- 7
AppCore.h View File

@@ -1,12 +1,5 @@
1 1
 #pragma once
2 2
 
3
-#include <LiquidCrystal.h>
4
-#include <JC_Button.h>
5
-#include <OneWire.h>
6
-#include <DallasTemperature.h>
7
-#include "Boiler.h"
8
-#include "Storage.h"
9
-#include "IInput.h"
10 3
 #include "ILifeCycle.h"
11 4
 #include "IActivity.h"
12 5
 
@@ -14,9 +7,16 @@ class AppCore
14 7
         : public ILifeCycle
15 8
 {
16 9
 public:
10
+    AppCore();
11
+
17 12
     void begin() override;
18 13
 
19 14
     void loop() override;
20 15
 
21 16
     void setActivity(IActivity* activity);
17
+
18
+    IActivity* getCurrentActivity() const;
19
+
20
+protected:
21
+    IActivity* m_currentActivity;
22 22
 };

+ 6
- 0
BaseActivity.cpp View File

@@ -1,6 +1,7 @@
1 1
 #include "BaseActivity.h"
2 2
 #include "globals.h"
3 3
 #include "Helpers.h"
4
+#include "Logs.h"
4 5
 
5 6
 BaseActivity::BaseActivity(
6 7
         IActivity* mParentActivity
@@ -25,18 +26,22 @@ void BaseActivity::loop()
25 26
     {
26 27
         if (g_btnCancel.wasReleased())
27 28
         {
29
+            LOG(1, "BaseActivity: Cancel pressed");
28 30
             onButtonReleased(Cancel);
29 31
         }
30 32
         else if (g_btnOk.wasReleased())
31 33
         {
34
+            LOG(1, "BaseActivity: Ok pressed");
32 35
             onButtonReleased(Ok);
33 36
         }
34 37
         else if (g_btnMinus.wasReleased())
35 38
         {
39
+            LOG(1, "BaseActivity: Minus pressed");
36 40
             onButtonReleased(Minus);
37 41
         }
38 42
         else if (g_btnPlus.wasReleased())
39 43
         {
44
+            LOG(1, "BaseActivity: Plus pressed");
40 45
             onButtonReleased(Plus);
41 46
         }
42 47
     }
@@ -49,6 +54,7 @@ void BaseActivity::loop()
49 54
 
50 55
 void BaseActivity::updateLcd()
51 56
 {
57
+    LOG(1, "BaseActivity: Updating LCD");
52 58
     char lines[2][17];
53 59
     lines[0][0] = 0;
54 60
     lines[1][0] = 0;

+ 3
- 4
Boiler.h View File

@@ -14,15 +14,14 @@ struct BoilerTankState
14 14
 {
15 15
     enum Mode
16 16
     {
17
-        Auto,
18
-        On,
19
-        Off
17
+        Auto = 1,
18
+        On = 2,
19
+        Off = 3
20 20
     };
21 21
 
22 22
     Mode mode;
23 23
     temp_t setting;
24 24
     temp_t tempTrigger;
25
-//    uint8_t sensorAddress[8];
26 25
     TempInput* input;
27 26
     DigitalOutput* relay;
28 27
 };

+ 3
- 0
BoilerTankModeEditorActivity.cpp View File

@@ -52,12 +52,14 @@ void BoilerTankModeEditorActivity::onButtonReleased(BaseActivity::Button button)
52 52
         {
53 53
             m_tmpValue = *m_value;
54 54
             m_isEditMode = false;
55
+            g_hibernateService.setPaused(false);
55 56
         }
56 57
         else if (button == Ok)
57 58
         {
58 59
             *m_value = m_tmpValue;
59 60
             g_storage.save();
60 61
             m_isEditMode = false;
62
+            g_hibernateService.setPaused(false);
61 63
         }
62 64
         else if (button == Minus)
63 65
         {
@@ -99,6 +101,7 @@ void BoilerTankModeEditorActivity::onButtonReleased(BaseActivity::Button button)
99 101
         {
100 102
             m_isEditMode = true;
101 103
             m_lcdUpdateNeeded = true;
104
+            g_hibernateService.setPaused(true);
102 105
         }
103 106
         else
104 107
         {

+ 11
- 1
HibernateService.cpp View File

@@ -13,6 +13,7 @@ HibernateService::HibernateService()
13 13
         nullptr
14 14
 }
15 15
           , m_lastEventMs(0)
16
+          , m_paused(false)
16 17
 {
17 18
 }
18 19
 
@@ -37,7 +38,7 @@ void HibernateService::loop()
37 38
             break;
38 39
         }
39 40
     }
40
-    if (!m_lastValue && currentMs - m_lastEventMs > HIBERNATE_DELAY)
41
+    if (!m_lastValue && !m_paused && currentMs - m_lastEventMs > HIBERNATE_DELAY)
41 42
     {
42 43
         shouldHibernate = true;
43 44
     }
@@ -48,5 +49,14 @@ void HibernateService::loop()
48 49
     {
49 50
         LOG(1, "Hibernate event");
50 51
         g_lcdLed.setEnabled(!m_lastValue);
52
+        if (m_lastValue && g_appCore.getCurrentActivity() != &g_homeActivity)
53
+        {
54
+            g_appCore.setActivity(&g_homeActivity);
55
+        }
51 56
     }
52 57
 }
58
+
59
+void HibernateService::setPaused(bool paused)
60
+{
61
+    m_paused = paused;
62
+}

+ 4
- 0
HibernateService.h View File

@@ -15,8 +15,12 @@ public:
15 15
 
16 16
     void loop() override;
17 17
 
18
+    void setPaused(bool paused);
19
+
18 20
 protected:
19 21
     Button* m_buttons[5];
20 22
 
21 23
     timestamp_t m_lastEventMs;
24
+
25
+    bool m_paused;
22 26
 };

+ 1
- 0
HomeActivity.cpp View File

@@ -35,6 +35,7 @@ void HomeActivity::loop()
35 35
 {
36 36
     if (g_appState.tanks[0].input->hasChanged() || g_appState.tanks[1].input->hasChanged())
37 37
     {
38
+        LOG(1, "HomeActivity: Input has changed");
38 39
         m_lcdUpdateNeeded = true;
39 40
     }
40 41
     BaseActivity::loop();

+ 2
- 0
LoaderActivity.cpp View File

@@ -11,6 +11,7 @@ void LoaderActivity::begin()
11 11
     }
12 12
     else
13 13
     {
14
+        g_hibernateService.setPaused(true);
14 15
         BaseActivity::begin();
15 16
     }
16 17
 }
@@ -26,6 +27,7 @@ void LoaderActivity::reset()
26 27
 {
27 28
     LOG(1, "%s: Resetting settings", __FUNCTION__);
28 29
     g_storage.save();
30
+    g_hibernateService.setPaused(false);
29 31
     g_appCore.setActivity(&g_homeActivity);
30 32
 }
31 33
 

+ 3
- 0
TempEditorActivity.cpp View File

@@ -42,12 +42,14 @@ void TempEditorActivity::onButtonReleased(BaseActivity::Button button)
42 42
         {
43 43
             m_tmpValue = *m_value;
44 44
             m_isEditMode = false;
45
+            g_hibernateService.setPaused(false);
45 46
         }
46 47
         else if (button == Ok)
47 48
         {
48 49
             *m_value = m_tmpValue;
49 50
             g_storage.save();
50 51
             m_isEditMode = false;
52
+            g_hibernateService.setPaused(false);
51 53
         }
52 54
         else if (button == Minus)
53 55
         {
@@ -65,6 +67,7 @@ void TempEditorActivity::onButtonReleased(BaseActivity::Button button)
65 67
         {
66 68
             m_isEditMode = true;
67 69
             m_lcdUpdateNeeded = true;
70
+            g_hibernateService.setPaused(true);
68 71
         }
69 72
         else
70 73
         {

+ 7
- 0
TempInput.cpp View File

@@ -1,6 +1,7 @@
1 1
 #include "TempInput.h"
2 2
 #include "globals.h"
3 3
 #include "defines.h"
4
+#include "Logs.h"
4 5
 
5 6
 TempInput::TempInput(uint8_t index)
6 7
         : m_address{0}
@@ -22,6 +23,7 @@ void TempInput::loop()
22 23
 
23 24
     if (currentMs - m_lastSensorRequestMs >= SENSORS_CHECK_INTERVAL)
24 25
     {
26
+        LOG(5, "TempInput: requesting value");
25 27
         m_lastSensorRequestMs = currentMs;
26 28
         m_hasReadSensor = false;
27 29
         g_dallasTemperature.requestTemperaturesByAddress(m_address);
@@ -29,6 +31,7 @@ void TempInput::loop()
29 31
     if (currentMs - m_lastSensorRequestMs >= SENSORS_REQUEST_DELAY &&
30 32
         !m_hasReadSensor)
31 33
     {
34
+        LOG(5, "TempInput: reading value");
32 35
         m_hasReadSensor = true;
33 36
         auto raw = g_dallasTemperature.getTempC(m_address);
34 37
         temp_t temp = TEMP_T_INVALID;
@@ -38,4 +41,8 @@ void TempInput::loop()
38 41
         }
39 42
         setValue(temp);
40 43
     }
44
+    else
45
+    {
46
+        setValue(m_lastValue);
47
+    }
41 48
 }

Loading…
Cancel
Save