Browse Source

Added new menu

master
Robin Thoni 4 years ago
parent
commit
3ee8d9fb5b
Signed by: Robin THONI <robin@rthoni.com> GPG Key ID: 4E09DEF46B99E61E
3 changed files with 167 additions and 51 deletions
  1. 153
    42
      AppCore.cpp
  2. 2
    4
      AppCore.h
  3. 12
    5
      Boiler.h

+ 153
- 42
AppCore.cpp View File

1
 #include "AppCore.h"
1
 #include "AppCore.h"
2
 #include "Logs.h"
2
 #include "Logs.h"
3
 
3
 
4
+#define xstr(s) str(s)
5
+#define str(s) #s
6
+
4
 #define HIBERNATE_DELAY 5000
7
 #define HIBERNATE_DELAY 5000
5
 #define SENSORS_CHECK_INTERVAL 2000
8
 #define SENSORS_CHECK_INTERVAL 2000
6
 #define SENSORS_REQUEST_DELAY 750
9
 #define SENSORS_REQUEST_DELAY 750
9
 #define LCD_CHAR_SENSOR 1
12
 #define LCD_CHAR_SENSOR 1
10
 
13
 
11
 #define PIN_ONEWIRE A0
14
 #define PIN_ONEWIRE A0
12
-#define PIN_RELAY1 A1
13
-#define PIN_RELAY2 A2
15
+#define PIN_RELAY2 A1
16
+#define PIN_RELAY1 A2
14
 #define PIN_BTN_CANCEL 9
17
 #define PIN_BTN_CANCEL 9
15
 #define PIN_BTN_OK 10
18
 #define PIN_BTN_OK 10
16
 #define PIN_BTN_MINUS 11
19
 #define PIN_BTN_MINUS 11
23
 #define PIN_LCD_D6 4
26
 #define PIN_LCD_D6 4
24
 #define PIN_LCD_D7 3
27
 #define PIN_LCD_D7 3
25
 
28
 
26
-#define BUTTONS_COUNT (sizeof(g_buttons) / sizeof(*g_buttons))
27
-#define MODE_SEQUENCE_COUNT (sizeof(m_modeSequence) / sizeof(*m_modeSequence))
29
+UiStateEnum AppCore::s_menuSequence[4]{MenuWaterSetting, MenuHeaterSetting, MenuTempTrigger, MenuVersion};
28
 
30
 
29
 AppCore::AppCore()
31
 AppCore::AppCore()
30
         : m_appCoreState(new AppCoreState{
32
         : m_appCoreState(new AppCoreState{
42
                         .setting = 0,
44
                         .setting = 0,
43
                         .isActive = false,
45
                         .isActive = false,
44
                         .pinNo = PIN_RELAY2
46
                         .pinNo = PIN_RELAY2
45
-                }
47
+                },
48
+                .tempTrigger = TEMP_TRIGGER,
49
+                .pCurrentSettingEdit = nullptr,
50
+                .currentSettingEditTmp = 0
46
         },
51
         },
47
         .uiState = {
52
         .uiState = {
48
-                .state = Lighting,
53
+                .state = HomeLighting,
49
                 .lastOpMs = 0,
54
                 .lastOpMs = 0,
50
-                .modeSequenceIndex = MODE_SEQUENCE_COUNT - 1,
51
                 .isUpdateNeeded = true
55
                 .isUpdateNeeded = true
52
         }
56
         }
53
 })
57
 })
54
-          , m_modeSequence{WaterSetting, HeaterSetting, Lighting}
55
           , m_pBtnCancel(new Button{PIN_BTN_CANCEL})
58
           , m_pBtnCancel(new Button{PIN_BTN_CANCEL})
56
           , m_pBtnOk(new Button{PIN_BTN_OK})
59
           , m_pBtnOk(new Button{PIN_BTN_OK})
57
           , m_pBtnMinus(new Button{PIN_BTN_MINUS})
60
           , m_pBtnMinus(new Button{PIN_BTN_MINUS})
171
     }
174
     }
172
 
175
 
173
 
176
 
174
-    if (m_appCoreState->uiState.state == Hibernate)
177
+    if (m_appCoreState->uiState.state == HomeHibernate)
175
     {
178
     {
176
         for (auto& pButton : m_pButtons)
179
         for (auto& pButton : m_pButtons)
177
         {
180
         {
178
             if (pButton->wasReleased())
181
             if (pButton->wasReleased())
179
             {
182
             {
180
-                setState(Lighting);
183
+                setState(HomeLighting);
181
                 break;
184
                 break;
182
             }
185
             }
183
         }
186
         }
186
     {
189
     {
187
         if (currentMs - m_appCoreState->uiState.lastOpMs >= HIBERNATE_DELAY)
190
         if (currentMs - m_appCoreState->uiState.lastOpMs >= HIBERNATE_DELAY)
188
         {
191
         {
189
-            setState(Hibernate);
192
+            setState(HomeHibernate);
190
         }
193
         }
191
         else
194
         else
192
         {
195
         {
193
-            if (m_pBtnOk->wasReleased())
196
+            if (m_appCoreState->uiState.state == HomeLighting)
194
             {
197
             {
195
-                m_appCoreState->uiState.modeSequenceIndex =
196
-                        (m_appCoreState->uiState.modeSequenceIndex + 1) % MODE_SEQUENCE_COUNT;
197
-                setState(m_modeSequence[m_appCoreState->uiState.modeSequenceIndex]);
198
+                if (m_pBtnCancel->wasReleased())
199
+                {
200
+                    setState(HomeHibernate);
201
+                }
202
+                else if (m_pBtnOk->wasReleased())
203
+                {
204
+                    setState(s_menuSequence[0]);
205
+                }
198
             }
206
             }
199
-            else if (m_pBtnMinus->wasReleased() || m_pBtnPlus->wasReleased())
207
+            else if (m_appCoreState->uiState.state == MenuWaterSetting || m_appCoreState->uiState.state == MenuHeaterSetting || m_appCoreState->uiState.state == MenuTempTrigger || m_appCoreState->uiState.state == MenuVersion)
200
             {
208
             {
201
-                BoilerItemState* itemState = nullptr;
202
-                if (m_appCoreState->uiState.state == WaterSetting)
209
+                if (m_pBtnCancel->wasReleased())
203
                 {
210
                 {
204
-                    itemState = &m_appCoreState->appState.water;
211
+                    setState(HomeLighting);
212
+                }
213
+                else if (m_pBtnOk->wasReleased())
214
+                {
215
+                    UiStateEnum nextState = m_appCoreState->uiState.state;
216
+                    if (m_appCoreState->uiState.state == MenuWaterSetting)
217
+                    {
218
+                        nextState = MenuWaterSettingEdit;
219
+                    }
220
+                    else if (m_appCoreState->uiState.state == MenuHeaterSetting)
221
+                    {
222
+                        nextState = MenuHeaterSettingEdit;
223
+                    }
224
+                    else if (m_appCoreState->uiState.state == MenuTempTrigger)
225
+                    {
226
+                        nextState = MenuTempTriggerEdit;
227
+                    }
228
+                    setState(nextState);
205
                 }
229
                 }
206
-                else if (m_appCoreState->uiState.state == HeaterSetting)
230
+                else if (m_pBtnMinus->wasReleased() || m_pBtnPlus->wasReleased())
207
                 {
231
                 {
208
-                    itemState = &m_appCoreState->appState.heater;
232
+                    int idx = 0;
233
+                    while (m_appCoreState->uiState.state != s_menuSequence[idx])
234
+                    {
235
+                        ++idx;
236
+                    }
237
+                    auto shift = m_pBtnMinus->wasReleased() ? (-1) : 1;
238
+                    setState(s_menuSequence[(idx + shift) % ((sizeof(s_menuSequence) / sizeof(*s_menuSequence)))]);
209
                 }
239
                 }
210
-
211
-                if (itemState)
240
+            }
241
+            else if (m_appCoreState->uiState.state == MenuWaterSettingEdit || m_appCoreState->uiState.state == MenuHeaterSettingEdit || m_appCoreState->uiState.state == MenuTempTriggerEdit)
242
+            {
243
+                if (m_pBtnCancel->wasReleased() || m_pBtnOk->wasReleased())
212
                 {
244
                 {
213
-                    if (m_pBtnMinus->wasReleased())
245
+                    UiStateEnum nextState = m_appCoreState->uiState.state;
246
+                    if (m_appCoreState->uiState.state == MenuWaterSettingEdit)
214
                     {
247
                     {
215
-                        itemState->setting -= TEMP_INTERVAL;
248
+                        nextState = MenuWaterSetting;
216
                     }
249
                     }
217
-                    else if (m_pBtnPlus->wasReleased())
250
+                    else if (m_appCoreState->uiState.state == MenuHeaterSettingEdit)
218
                     {
251
                     {
219
-                        itemState->setting += TEMP_INTERVAL;
252
+                        nextState = MenuHeaterSetting;
220
                     }
253
                     }
221
-                    LOG(1, "Setting temp to %i (%i)", itemState->setting, TEMP_INTERVAL);
254
+                    else if (m_appCoreState->uiState.state == MenuTempTriggerEdit)
255
+                    {
256
+                        nextState = MenuTempTrigger;
257
+                    }
258
+
259
+                    if (m_pBtnOk->wasReleased())
260
+                    {
261
+                        *m_appCoreState->appState.pCurrentSettingEdit = m_appCoreState->appState.currentSettingEditTmp;
262
+                    }
263
+
264
+                    m_appCoreState->appState.currentSettingEditTmp = 0;
265
+                    m_appCoreState->appState.pCurrentSettingEdit = nullptr;
266
+                    setState(nextState);
267
+                }
268
+                else if (m_pBtnMinus->wasReleased() || m_pBtnPlus->wasReleased())
269
+                {
270
+                    m_appCoreState->appState.currentSettingEditTmp += (m_pBtnMinus->wasReleased() ? -1 : 1) * TEMP_INTERVAL;
222
                     m_appCoreState->uiState.isUpdateNeeded = true;
271
                     m_appCoreState->uiState.isUpdateNeeded = true;
223
                 }
272
                 }
224
             }
273
             }
240
     LOG_FN_BEGIN(1);
289
     LOG_FN_BEGIN(1);
241
     LOG(5, "Changing state %i => %i", m_appCoreState->uiState.state, state);
290
     LOG(5, "Changing state %i => %i", m_appCoreState->uiState.state, state);
242
 
291
 
243
-    if (state == Lighting)
292
+    if (state == HomeLighting)
244
     {
293
     {
245
         digitalWrite(PIN_LCD_LED, 1);
294
         digitalWrite(PIN_LCD_LED, 1);
246
     }
295
     }
247
-    else if (state == Hibernate)
296
+    else if (state == HomeHibernate)
248
     {
297
     {
249
         digitalWrite(PIN_LCD_LED, 0);
298
         digitalWrite(PIN_LCD_LED, 0);
250
-        m_appCoreState->uiState.modeSequenceIndex = MODE_SEQUENCE_COUNT - 1;
251
         m_storage.save(*m_appCoreState);
299
         m_storage.save(*m_appCoreState);
252
     }
300
     }
301
+    else if (state == MenuWaterSettingEdit)
302
+    {
303
+        m_appCoreState->appState.currentSettingEditTmp = m_appCoreState->appState.water.setting;
304
+        m_appCoreState->appState.pCurrentSettingEdit = &m_appCoreState->appState.water.setting;
305
+    }
306
+    else if (state == MenuHeaterSettingEdit)
307
+    {
308
+        m_appCoreState->appState.currentSettingEditTmp = m_appCoreState->appState.heater.setting;
309
+        m_appCoreState->appState.pCurrentSettingEdit = &m_appCoreState->appState.heater.setting;
310
+    }
311
+    else if (state == MenuTempTriggerEdit)
312
+    {
313
+        m_appCoreState->appState.currentSettingEditTmp = m_appCoreState->appState.tempTrigger;
314
+        m_appCoreState->appState.pCurrentSettingEdit = &m_appCoreState->appState.tempTrigger;
315
+    }
253
     m_appCoreState->uiState.state = state;
316
     m_appCoreState->uiState.state = state;
254
     m_appCoreState->uiState.isUpdateNeeded = true;
317
     m_appCoreState->uiState.isUpdateNeeded = true;
255
 
318
 
263
     LOG_FN_BEGIN(2);
326
     LOG_FN_BEGIN(2);
264
 
327
 
265
     if (!boilerItemState->isActive && boilerItemState->current != TEMP_T_INVALID &&
328
     if (!boilerItemState->isActive && boilerItemState->current != TEMP_T_INVALID &&
266
-        boilerItemState->current <= boilerItemState->setting - TEMP_TRIGGER)
329
+        boilerItemState->current <= boilerItemState->setting - m_appCoreState->appState.tempTrigger)
267
     {
330
     {
268
         boilerItemState->isActive = true;
331
         boilerItemState->isActive = true;
269
         digitalWrite(boilerItemState->pinNo, HIGH);
332
         digitalWrite(boilerItemState->pinNo, HIGH);
307
 {
370
 {
308
     LOG_FN_BEGIN(2);
371
     LOG_FN_BEGIN(2);
309
 
372
 
310
-    m_pLcd->setCursor(0, 0);
311
-    printStateLine('S', &m_appCoreState->appState.water, m_appCoreState->uiState.state == WaterSetting,
312
-                   m_appCoreState->appState.water.isActive);
313
-    m_pLcd->setCursor(0, 1);
314
-    printStateLine('C', &m_appCoreState->appState.heater, m_appCoreState->uiState.state == HeaterSetting,
315
-                   m_appCoreState->appState.heater.isActive);
373
+    if (m_appCoreState->uiState.state == HomeLighting || m_appCoreState->uiState.state == HomeHibernate)
374
+    {
375
+        m_pLcd->setCursor(0, 0);
376
+        printStateLine('S', &m_appCoreState->appState.water);
377
+        m_pLcd->setCursor(0, 1);
378
+        printStateLine('C', &m_appCoreState->appState.heater);
379
+    }
380
+    else if (m_appCoreState->uiState.state == MenuWaterSetting || m_appCoreState->uiState.state == MenuHeaterSetting || m_appCoreState->uiState.state == MenuTempTrigger ||
381
+            m_appCoreState->uiState.state == MenuWaterSettingEdit || m_appCoreState->uiState.state == MenuHeaterSettingEdit || m_appCoreState->uiState.state == MenuTempTriggerEdit)
382
+    {
383
+        const auto isEdit = m_appCoreState->uiState.state == MenuWaterSettingEdit || m_appCoreState->uiState.state == MenuHeaterSettingEdit || m_appCoreState->uiState.state == MenuTempTriggerEdit;
384
+        const char* pTitle = nullptr;
385
+        temp_t* pTemp = nullptr;
386
+        if (isEdit)
387
+        {
388
+            pTemp = &m_appCoreState->appState.currentSettingEditTmp;
389
+        }
390
+        else
391
+        {
392
+            if (m_appCoreState->uiState.state == MenuWaterSetting ||
393
+                m_appCoreState->uiState.state == MenuWaterSettingEdit)
394
+            {
395
+                pTitle = "Sanitaire";
396
+                pTemp = &m_appCoreState->appState.water.setting;
397
+            }
398
+            else if (m_appCoreState->uiState.state == MenuHeaterSetting ||
399
+                     m_appCoreState->uiState.state == MenuHeaterSettingEdit)
400
+            {
401
+                pTitle = "Chauffage";
402
+                pTemp = &m_appCoreState->appState.heater.setting;
403
+            }
404
+            else if (m_appCoreState->uiState.state == MenuTempTrigger ||
405
+                     m_appCoreState->uiState.state == MenuTempTriggerEdit)
406
+            {
407
+                pTitle = "Delta";
408
+                pTemp = &m_appCoreState->appState.tempTrigger;
409
+            }
410
+        }
411
+        char tmpStr[17], tmpTemp[7];
412
+        m_pLcd->setCursor(0, 0);
413
+        snprintf(tmpStr, sizeof(tmpStr), "%s :                ", pTitle);
414
+        m_pLcd->print(tmpStr);
415
+        m_pLcd->setCursor(0, 1);
416
+        tempToStr(tmpTemp, *pTemp, 4);
417
+        snprintf(tmpStr, sizeof(tmpStr), "%s%s C                ", isEdit ? "> " : "  ", tmpTemp);
418
+        m_pLcd->print(tmpStr);
419
+    }
420
+    else if (m_appCoreState->uiState.state == MenuVersion)
421
+    {
422
+        char tmpStr[17];
423
+        m_pLcd->setCursor(0, 0);
424
+        snprintf(tmpStr, sizeof(tmpStr), "%s :                ", "Version");
425
+        m_pLcd->print(tmpStr);
426
+        m_pLcd->setCursor(0, 1);
427
+        snprintf(tmpStr, sizeof(tmpStr), "%s - %s                ", xstr(APP_CORE_VERSION), xstr(APP_CORE_COMMIT));
428
+        m_pLcd->print(tmpStr);
429
+    }
316
     m_appCoreState->uiState.isUpdateNeeded = false;
430
     m_appCoreState->uiState.isUpdateNeeded = false;
317
 
431
 
318
     LOG_FN_END(2);
432
     LOG_FN_END(2);
322
 AppCore::printStateLine(
436
 AppCore::printStateLine(
323
         char prefix
437
         char prefix
324
         , const BoilerItemState* boilerItemState
438
         , const BoilerItemState* boilerItemState
325
-        , bool isModifying
326
-        , bool isActive
327
 )
439
 )
328
 {
440
 {
329
     LOG_FN_BEGIN(2);
441
     LOG_FN_BEGIN(2);
331
     char curTmp[7], setTmp[7], tmp[17];
443
     char curTmp[7], setTmp[7], tmp[17];
332
     tempToStr(curTmp, boilerItemState->current, 5);
444
     tempToStr(curTmp, boilerItemState->current, 5);
333
     tempToStr(setTmp, boilerItemState->setting, 4);
445
     tempToStr(setTmp, boilerItemState->setting, 4);
334
-    int count = snprintf(tmp, sizeof(tmp), "%c:%s [%s]%c%c", prefix, curTmp, setTmp, isModifying ? '<' : ' ',
335
-                         isActive ? LCD_CHAR_SENSOR : ' ');
446
+    int count = snprintf(tmp, sizeof(tmp), "%c:%s [%s] %c", prefix, curTmp, setTmp, boilerItemState->isActive ? LCD_CHAR_SENSOR : ' ');
336
     for (; count < 17; ++count)
447
     for (; count < 17; ++count)
337
     {
448
     {
338
         tmp[count] = ' ';
449
         tmp[count] = ' ';

+ 2
- 4
AppCore.h View File

10
 class AppCore
10
 class AppCore
11
 {
11
 {
12
 public:
12
 public:
13
+    static UiStateEnum s_menuSequence[4];
14
+
13
     AppCore();
15
     AppCore();
14
 
16
 
15
     void setup();
17
     void setup();
28
     void printStateLine(
30
     void printStateLine(
29
             char prefix
31
             char prefix
30
             , const BoilerItemState* boilerItemState
32
             , const BoilerItemState* boilerItemState
31
-            , bool isModifying
32
-            , bool isActive
33
     );
33
     );
34
 
34
 
35
     void tempToStr(
35
     void tempToStr(
42
     AppCoreState* m_appCoreState;
42
     AppCoreState* m_appCoreState;
43
     Storage m_storage;
43
     Storage m_storage;
44
 
44
 
45
-    UiStateEnum m_modeSequence[3];
46
-
47
     Button* m_pBtnCancel;
45
     Button* m_pBtnCancel;
48
     Button* m_pBtnOk;
46
     Button* m_pBtnOk;
49
     Button* m_pBtnMinus;
47
     Button* m_pBtnMinus;

+ 12
- 5
Boiler.h View File

6
 
6
 
7
 enum UiStateEnum
7
 enum UiStateEnum
8
 {
8
 {
9
-    Hibernate,
10
-    Lighting,
11
-    WaterSetting,
12
-    HeaterSetting
9
+    HomeHibernate,
10
+    HomeLighting,
11
+    MenuWaterSetting,
12
+    MenuWaterSettingEdit,
13
+    MenuHeaterSetting,
14
+    MenuHeaterSettingEdit,
15
+    MenuTempTrigger,
16
+    MenuTempTriggerEdit,
17
+    MenuVersion
13
 };
18
 };
14
 
19
 
15
 struct BoilerItemState
20
 struct BoilerItemState
26
     bool hasReadSensors;
31
     bool hasReadSensors;
27
     BoilerItemState water;
32
     BoilerItemState water;
28
     BoilerItemState heater;
33
     BoilerItemState heater;
34
+    temp_t tempTrigger;
35
+    temp_t* pCurrentSettingEdit;
36
+    temp_t currentSettingEditTmp;
29
 };
37
 };
30
 
38
 
31
 struct UiState
39
 struct UiState
32
 {
40
 {
33
     UiStateEnum state;
41
     UiStateEnum state;
34
     timestamp_t lastOpMs;
42
     timestamp_t lastOpMs;
35
-    unsigned modeSequenceIndex;
36
     bool isUpdateNeeded;
43
     bool isUpdateNeeded;
37
 };
44
 };
38
 
45
 

Loading…
Cancel
Save