Browse Source

Added relays and cancel button; Renamed mode button to ok

master
Robin Thoni 4 years ago
parent
commit
db4cbd8416
Signed by: Robin THONI <robin@rthoni.com> GPG Key ID: 4E09DEF46B99E61E
3 changed files with 30 additions and 14 deletions
  1. 25
    11
      AppCore.cpp
  2. 4
    3
      AppCore.h
  3. 1
    0
      Boiler.h

+ 25
- 11
AppCore.cpp View File

9
 #define LCD_CHAR_SENSOR 1
9
 #define LCD_CHAR_SENSOR 1
10
 
10
 
11
 #define PIN_ONEWIRE A0
11
 #define PIN_ONEWIRE A0
12
-#define PIN_BTN_MODE 10
12
+#define PIN_RELAY1 A1
13
+#define PIN_RELAY2 A2
14
+#define PIN_BTN_CANCEL 9
15
+#define PIN_BTN_OK 10
13
 #define PIN_BTN_MINUS 11
16
 #define PIN_BTN_MINUS 11
14
 #define PIN_BTN_PLUS 12
17
 #define PIN_BTN_PLUS 12
15
 #define PIN_LCD_LED 2
18
 #define PIN_LCD_LED 2
31
                 .water = {
34
                 .water = {
32
                         .current = TEMP_T_INVALID,
35
                         .current = TEMP_T_INVALID,
33
                         .setting = 0,
36
                         .setting = 0,
34
-                        .isActive = false
37
+                        .isActive = false,
38
+                        .pinNo = PIN_RELAY1
35
                 },
39
                 },
36
                 .heater = {
40
                 .heater = {
37
                         .current = TEMP_T_INVALID,
41
                         .current = TEMP_T_INVALID,
38
                         .setting = 0,
42
                         .setting = 0,
39
-                        .isActive = false
43
+                        .isActive = false,
44
+                        .pinNo = PIN_RELAY2
40
                 }
45
                 }
41
         },
46
         },
42
         .uiState = {
47
         .uiState = {
47
         }
52
         }
48
 })
53
 })
49
           , m_modeSequence{WaterSetting, HeaterSetting, Lighting}
54
           , m_modeSequence{WaterSetting, HeaterSetting, Lighting}
50
-          , m_btnMode{PIN_BTN_MODE}
51
-          , m_btnMinus{PIN_BTN_MINUS}
52
-          , m_btnPlus{PIN_BTN_PLUS}
53
-          , m_buttons{&m_btnMode, &m_btnMinus, &m_btnPlus}
55
+          , m_pBtnCancel(new Button{PIN_BTN_CANCEL})
56
+          , m_pBtnOk(new Button{PIN_BTN_OK})
57
+          , m_pBtnMinus(new Button{PIN_BTN_MINUS})
58
+          , m_pBtnPlus(new Button{PIN_BTN_PLUS})
59
+          , m_buttons{m_pBtnOk, m_pBtnMinus, m_pBtnPlus}
54
           , m_lcd{PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7}
60
           , m_lcd{PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7}
55
           , m_oneWire{PIN_ONEWIRE}
61
           , m_oneWire{PIN_ONEWIRE}
56
           , m_sensors{&m_oneWire}
62
           , m_sensors{&m_oneWire}
75
         g_button->begin();
81
         g_button->begin();
76
     }
82
     }
77
 
83
 
84
+    pinMode(PIN_RELAY1, OUTPUT);
85
+    digitalWrite(PIN_RELAY1, LOW);
86
+
87
+    pinMode(PIN_RELAY2, OUTPUT);
88
+    digitalWrite(PIN_RELAY2, LOW);
89
+
78
     pinMode(PIN_LCD_LED, OUTPUT);
90
     pinMode(PIN_LCD_LED, OUTPUT);
79
     digitalWrite(PIN_LCD_LED, 1);
91
     digitalWrite(PIN_LCD_LED, 1);
80
 
92
 
178
         }
190
         }
179
         else
191
         else
180
         {
192
         {
181
-            if (m_btnMode.wasReleased())
193
+            if (m_pBtnOk->wasReleased())
182
             {
194
             {
183
                 m_appCoreState->uiState.modeSequenceIndex =
195
                 m_appCoreState->uiState.modeSequenceIndex =
184
                         (m_appCoreState->uiState.modeSequenceIndex + 1) % MODE_SEQUENCE_COUNT;
196
                         (m_appCoreState->uiState.modeSequenceIndex + 1) % MODE_SEQUENCE_COUNT;
185
                 setState(m_modeSequence[m_appCoreState->uiState.modeSequenceIndex]);
197
                 setState(m_modeSequence[m_appCoreState->uiState.modeSequenceIndex]);
186
             }
198
             }
187
-            else if (m_btnMinus.wasReleased() || m_btnPlus.wasReleased())
199
+            else if (m_pBtnMinus->wasReleased() || m_pBtnPlus->wasReleased())
188
             {
200
             {
189
                 BoilerItemState* itemState = nullptr;
201
                 BoilerItemState* itemState = nullptr;
190
                 if (m_appCoreState->uiState.state == WaterSetting)
202
                 if (m_appCoreState->uiState.state == WaterSetting)
198
 
210
 
199
                 if (itemState)
211
                 if (itemState)
200
                 {
212
                 {
201
-                    if (m_btnMinus.wasReleased())
213
+                    if (m_pBtnMinus->wasReleased())
202
                     {
214
                     {
203
                         itemState->setting -= TEMP_INTERVAL;
215
                         itemState->setting -= TEMP_INTERVAL;
204
                     }
216
                     }
205
-                    else if (m_btnPlus.wasReleased())
217
+                    else if (m_pBtnPlus->wasReleased())
206
                     {
218
                     {
207
                         itemState->setting += TEMP_INTERVAL;
219
                         itemState->setting += TEMP_INTERVAL;
208
                     }
220
                     }
254
         boilerItemState->current <= boilerItemState->setting - TEMP_TRIGGER)
266
         boilerItemState->current <= boilerItemState->setting - TEMP_TRIGGER)
255
     {
267
     {
256
         boilerItemState->isActive = true;
268
         boilerItemState->isActive = true;
269
+        digitalWrite(boilerItemState->pinNo, HIGH);
257
         m_appCoreState->uiState.isUpdateNeeded = true;
270
         m_appCoreState->uiState.isUpdateNeeded = true;
258
     }
271
     }
259
     else if (boilerItemState->isActive &&
272
     else if (boilerItemState->isActive &&
260
              (boilerItemState->current == TEMP_T_INVALID || boilerItemState->current >= boilerItemState->setting))
273
              (boilerItemState->current == TEMP_T_INVALID || boilerItemState->current >= boilerItemState->setting))
261
     {
274
     {
262
         boilerItemState->isActive = false;
275
         boilerItemState->isActive = false;
276
+        digitalWrite(boilerItemState->pinNo, LOW);
263
         m_appCoreState->uiState.isUpdateNeeded = true;
277
         m_appCoreState->uiState.isUpdateNeeded = true;
264
     }
278
     }
265
 
279
 

+ 4
- 3
AppCore.h View File

44
 
44
 
45
     UiStateEnum m_modeSequence[3];
45
     UiStateEnum m_modeSequence[3];
46
 
46
 
47
-    Button m_btnMode;
48
-    Button m_btnMinus;
49
-    Button m_btnPlus;
47
+    Button* m_pBtnCancel;
48
+    Button* m_pBtnOk;
49
+    Button* m_pBtnMinus;
50
+    Button* m_pBtnPlus;
50
     Button* m_buttons[3];
51
     Button* m_buttons[3];
51
 
52
 
52
     LiquidCrystal m_lcd;
53
     LiquidCrystal m_lcd;

+ 1
- 0
Boiler.h View File

17
     temp_t current;
17
     temp_t current;
18
     temp_t setting;
18
     temp_t setting;
19
     bool isActive;
19
     bool isActive;
20
+    int pinNo;
20
 };
21
 };
21
 
22
 
22
 struct AppState
23
 struct AppState

Loading…
Cancel
Save