Browse Source

Pause hibernate when editing and resetting; Logs

master
Robin Thoni 4 years 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
                                             "", &g_appState.tanks[1]);
55
                                             "", &g_appState.tanks[1]);
56
 MenuItemActivity g_menuVersionActivity(&g_homeActivity, nullptr, &g_menuHeaterActivity, &g_menuWaterActivity, "Version",
56
 MenuItemActivity g_menuVersionActivity(&g_homeActivity, nullptr, &g_menuHeaterActivity, &g_menuWaterActivity, "Version",
57
                                        xstr(APP_CORE_VERSION) " - " xstr(APP_CORE_COMMIT));
57
                                        xstr(APP_CORE_VERSION) " - " xstr(APP_CORE_COMMIT));
58
-IActivity* g_currentActivity = nullptr;
59
 
58
 
60
 
59
 
61
 int freeRam()
60
 int freeRam()
65
     return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
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
 void AppCore::begin()
72
 void AppCore::begin()
69
 {
73
 {
70
     Serial.begin(9600);
74
     Serial.begin(9600);
128
 
132
 
129
     g_hibernateService.loop();
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
     LOG_FN_END(50);
140
     LOG_FN_END(50);
138
 
142
 
139
 void AppCore::setActivity(IActivity* activity)
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
 #pragma once
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
 #include "ILifeCycle.h"
3
 #include "ILifeCycle.h"
11
 #include "IActivity.h"
4
 #include "IActivity.h"
12
 
5
 
14
         : public ILifeCycle
7
         : public ILifeCycle
15
 {
8
 {
16
 public:
9
 public:
10
+    AppCore();
11
+
17
     void begin() override;
12
     void begin() override;
18
 
13
 
19
     void loop() override;
14
     void loop() override;
20
 
15
 
21
     void setActivity(IActivity* activity);
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
 #include "BaseActivity.h"
1
 #include "BaseActivity.h"
2
 #include "globals.h"
2
 #include "globals.h"
3
 #include "Helpers.h"
3
 #include "Helpers.h"
4
+#include "Logs.h"
4
 
5
 
5
 BaseActivity::BaseActivity(
6
 BaseActivity::BaseActivity(
6
         IActivity* mParentActivity
7
         IActivity* mParentActivity
25
     {
26
     {
26
         if (g_btnCancel.wasReleased())
27
         if (g_btnCancel.wasReleased())
27
         {
28
         {
29
+            LOG(1, "BaseActivity: Cancel pressed");
28
             onButtonReleased(Cancel);
30
             onButtonReleased(Cancel);
29
         }
31
         }
30
         else if (g_btnOk.wasReleased())
32
         else if (g_btnOk.wasReleased())
31
         {
33
         {
34
+            LOG(1, "BaseActivity: Ok pressed");
32
             onButtonReleased(Ok);
35
             onButtonReleased(Ok);
33
         }
36
         }
34
         else if (g_btnMinus.wasReleased())
37
         else if (g_btnMinus.wasReleased())
35
         {
38
         {
39
+            LOG(1, "BaseActivity: Minus pressed");
36
             onButtonReleased(Minus);
40
             onButtonReleased(Minus);
37
         }
41
         }
38
         else if (g_btnPlus.wasReleased())
42
         else if (g_btnPlus.wasReleased())
39
         {
43
         {
44
+            LOG(1, "BaseActivity: Plus pressed");
40
             onButtonReleased(Plus);
45
             onButtonReleased(Plus);
41
         }
46
         }
42
     }
47
     }
49
 
54
 
50
 void BaseActivity::updateLcd()
55
 void BaseActivity::updateLcd()
51
 {
56
 {
57
+    LOG(1, "BaseActivity: Updating LCD");
52
     char lines[2][17];
58
     char lines[2][17];
53
     lines[0][0] = 0;
59
     lines[0][0] = 0;
54
     lines[1][0] = 0;
60
     lines[1][0] = 0;

+ 3
- 4
Boiler.h View File

14
 {
14
 {
15
     enum Mode
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
     Mode mode;
22
     Mode mode;
23
     temp_t setting;
23
     temp_t setting;
24
     temp_t tempTrigger;
24
     temp_t tempTrigger;
25
-//    uint8_t sensorAddress[8];
26
     TempInput* input;
25
     TempInput* input;
27
     DigitalOutput* relay;
26
     DigitalOutput* relay;
28
 };
27
 };

+ 3
- 0
BoilerTankModeEditorActivity.cpp View File

52
         {
52
         {
53
             m_tmpValue = *m_value;
53
             m_tmpValue = *m_value;
54
             m_isEditMode = false;
54
             m_isEditMode = false;
55
+            g_hibernateService.setPaused(false);
55
         }
56
         }
56
         else if (button == Ok)
57
         else if (button == Ok)
57
         {
58
         {
58
             *m_value = m_tmpValue;
59
             *m_value = m_tmpValue;
59
             g_storage.save();
60
             g_storage.save();
60
             m_isEditMode = false;
61
             m_isEditMode = false;
62
+            g_hibernateService.setPaused(false);
61
         }
63
         }
62
         else if (button == Minus)
64
         else if (button == Minus)
63
         {
65
         {
99
         {
101
         {
100
             m_isEditMode = true;
102
             m_isEditMode = true;
101
             m_lcdUpdateNeeded = true;
103
             m_lcdUpdateNeeded = true;
104
+            g_hibernateService.setPaused(true);
102
         }
105
         }
103
         else
106
         else
104
         {
107
         {

+ 11
- 1
HibernateService.cpp View File

13
         nullptr
13
         nullptr
14
 }
14
 }
15
           , m_lastEventMs(0)
15
           , m_lastEventMs(0)
16
+          , m_paused(false)
16
 {
17
 {
17
 }
18
 }
18
 
19
 
37
             break;
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
         shouldHibernate = true;
43
         shouldHibernate = true;
43
     }
44
     }
48
     {
49
     {
49
         LOG(1, "Hibernate event");
50
         LOG(1, "Hibernate event");
50
         g_lcdLed.setEnabled(!m_lastValue);
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
 
15
 
16
     void loop() override;
16
     void loop() override;
17
 
17
 
18
+    void setPaused(bool paused);
19
+
18
 protected:
20
 protected:
19
     Button* m_buttons[5];
21
     Button* m_buttons[5];
20
 
22
 
21
     timestamp_t m_lastEventMs;
23
     timestamp_t m_lastEventMs;
24
+
25
+    bool m_paused;
22
 };
26
 };

+ 1
- 0
HomeActivity.cpp View File

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

+ 2
- 0
LoaderActivity.cpp View File

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

+ 3
- 0
TempEditorActivity.cpp View File

42
         {
42
         {
43
             m_tmpValue = *m_value;
43
             m_tmpValue = *m_value;
44
             m_isEditMode = false;
44
             m_isEditMode = false;
45
+            g_hibernateService.setPaused(false);
45
         }
46
         }
46
         else if (button == Ok)
47
         else if (button == Ok)
47
         {
48
         {
48
             *m_value = m_tmpValue;
49
             *m_value = m_tmpValue;
49
             g_storage.save();
50
             g_storage.save();
50
             m_isEditMode = false;
51
             m_isEditMode = false;
52
+            g_hibernateService.setPaused(false);
51
         }
53
         }
52
         else if (button == Minus)
54
         else if (button == Minus)
53
         {
55
         {
65
         {
67
         {
66
             m_isEditMode = true;
68
             m_isEditMode = true;
67
             m_lcdUpdateNeeded = true;
69
             m_lcdUpdateNeeded = true;
70
+            g_hibernateService.setPaused(true);
68
         }
71
         }
69
         else
72
         else
70
         {
73
         {

+ 7
- 0
TempInput.cpp View File

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

Loading…
Cancel
Save