ソースを参照

Added relays and cancel button; Renamed mode button to ok

master
Robin Thoni 4年前
コミット
db4cbd8416
署名者: Robin THONI <robin@rthoni.com> GPGキーID: 4E09DEF46B99E61E
3個のファイルの変更30行の追加14行の削除
  1. 25
    11
      AppCore.cpp
  2. 4
    3
      AppCore.h
  3. 1
    0
      Boiler.h

+ 25
- 11
AppCore.cpp ファイルの表示

@@ -9,7 +9,10 @@
9 9
 #define LCD_CHAR_SENSOR 1
10 10
 
11 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 16
 #define PIN_BTN_MINUS 11
14 17
 #define PIN_BTN_PLUS 12
15 18
 #define PIN_LCD_LED 2
@@ -31,12 +34,14 @@ AppCore::AppCore()
31 34
                 .water = {
32 35
                         .current = TEMP_T_INVALID,
33 36
                         .setting = 0,
34
-                        .isActive = false
37
+                        .isActive = false,
38
+                        .pinNo = PIN_RELAY1
35 39
                 },
36 40
                 .heater = {
37 41
                         .current = TEMP_T_INVALID,
38 42
                         .setting = 0,
39
-                        .isActive = false
43
+                        .isActive = false,
44
+                        .pinNo = PIN_RELAY2
40 45
                 }
41 46
         },
42 47
         .uiState = {
@@ -47,10 +52,11 @@ AppCore::AppCore()
47 52
         }
48 53
 })
49 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 60
           , m_lcd{PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7}
55 61
           , m_oneWire{PIN_ONEWIRE}
56 62
           , m_sensors{&m_oneWire}
@@ -75,6 +81,12 @@ void AppCore::setup()
75 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 90
     pinMode(PIN_LCD_LED, OUTPUT);
79 91
     digitalWrite(PIN_LCD_LED, 1);
80 92
 
@@ -178,13 +190,13 @@ void AppCore::loop()
178 190
         }
179 191
         else
180 192
         {
181
-            if (m_btnMode.wasReleased())
193
+            if (m_pBtnOk->wasReleased())
182 194
             {
183 195
                 m_appCoreState->uiState.modeSequenceIndex =
184 196
                         (m_appCoreState->uiState.modeSequenceIndex + 1) % MODE_SEQUENCE_COUNT;
185 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 201
                 BoilerItemState* itemState = nullptr;
190 202
                 if (m_appCoreState->uiState.state == WaterSetting)
@@ -198,11 +210,11 @@ void AppCore::loop()
198 210
 
199 211
                 if (itemState)
200 212
                 {
201
-                    if (m_btnMinus.wasReleased())
213
+                    if (m_pBtnMinus->wasReleased())
202 214
                     {
203 215
                         itemState->setting -= TEMP_INTERVAL;
204 216
                     }
205
-                    else if (m_btnPlus.wasReleased())
217
+                    else if (m_pBtnPlus->wasReleased())
206 218
                     {
207 219
                         itemState->setting += TEMP_INTERVAL;
208 220
                     }
@@ -254,12 +266,14 @@ void AppCore::checkBoilerItem(
254 266
         boilerItemState->current <= boilerItemState->setting - TEMP_TRIGGER)
255 267
     {
256 268
         boilerItemState->isActive = true;
269
+        digitalWrite(boilerItemState->pinNo, HIGH);
257 270
         m_appCoreState->uiState.isUpdateNeeded = true;
258 271
     }
259 272
     else if (boilerItemState->isActive &&
260 273
              (boilerItemState->current == TEMP_T_INVALID || boilerItemState->current >= boilerItemState->setting))
261 274
     {
262 275
         boilerItemState->isActive = false;
276
+        digitalWrite(boilerItemState->pinNo, LOW);
263 277
         m_appCoreState->uiState.isUpdateNeeded = true;
264 278
     }
265 279
 

+ 4
- 3
AppCore.h ファイルの表示

@@ -44,9 +44,10 @@ private:
44 44
 
45 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 51
     Button* m_buttons[3];
51 52
 
52 53
     LiquidCrystal m_lcd;

+ 1
- 0
Boiler.h ファイルの表示

@@ -17,6 +17,7 @@ struct BoilerItemState
17 17
     temp_t current;
18 18
     temp_t setting;
19 19
     bool isActive;
20
+    int pinNo;
20 21
 };
21 22
 
22 23
 struct AppState

読み込み中…
キャンセル
保存