Browse Source

Switched to pointers

master
Robin Thoni 4 years ago
parent
commit
4b0caa7dde
Signed by: Robin THONI <robin@rthoni.com> GPG Key ID: 4E09DEF46B99E61E
2 changed files with 29 additions and 29 deletions
  1. 25
    25
      AppCore.cpp
  2. 4
    4
      AppCore.h

+ 25
- 25
AppCore.cpp View File

@@ -56,10 +56,10 @@ AppCore::AppCore()
56 56
           , m_pBtnOk(new Button{PIN_BTN_OK})
57 57
           , m_pBtnMinus(new Button{PIN_BTN_MINUS})
58 58
           , m_pBtnPlus(new Button{PIN_BTN_PLUS})
59
-          , m_buttons{m_pBtnOk, m_pBtnMinus, m_pBtnPlus}
60
-          , m_lcd{PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7}
61
-          , m_oneWire{PIN_ONEWIRE}
62
-          , m_sensors{&m_oneWire}
59
+          , m_pButtons{m_pBtnOk, m_pBtnMinus, m_pBtnPlus}
60
+          , m_pLcd(new LiquidCrystal{PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7})
61
+          , m_pOneWire(new OneWire{PIN_ONEWIRE})
62
+          , m_pSensors(new DallasTemperature{m_pOneWire})
63 63
           , m_sensor1{0}
64 64
           , m_sensor2{0}
65 65
 {
@@ -70,13 +70,13 @@ void AppCore::setup()
70 70
     Serial.begin(9600);
71 71
     LOG_FN_BEGIN(1);
72 72
 
73
-    m_sensors.begin();
74
-    LOG(5, "Found %i sensors", m_sensors.getDeviceCount());
75
-    m_sensors.getAddress(m_sensor1, 0);
76
-    m_sensors.getAddress(m_sensor2, 1);
77
-    m_sensors.setWaitForConversion(false);
73
+    m_pSensors->begin();
74
+    LOG(5, "Found %i sensors", m_pSensors->getDeviceCount());
75
+    m_pSensors->getAddress(m_sensor1, 0);
76
+    m_pSensors->getAddress(m_sensor2, 1);
77
+    m_pSensors->setWaitForConversion(false);
78 78
 
79
-    for (auto& g_button : m_buttons)
79
+    for (auto& g_button : m_pButtons)
80 80
     {
81 81
         g_button->begin();
82 82
     }
@@ -90,7 +90,7 @@ void AppCore::setup()
90 90
     pinMode(PIN_LCD_LED, OUTPUT);
91 91
     digitalWrite(PIN_LCD_LED, 1);
92 92
 
93
-    m_lcd.begin(16, 2);
93
+    m_pLcd->begin(16, 2);
94 94
     byte sensorChar[8] = {
95 95
             B00100,
96 96
             B01110,
@@ -101,11 +101,11 @@ void AppCore::setup()
101 101
             B11111,
102 102
             B01110,
103 103
     };
104
-    m_lcd.createChar(LCD_CHAR_SENSOR, sensorChar);
104
+    m_pLcd->createChar(LCD_CHAR_SENSOR, sensorChar);
105 105
 
106 106
 
107 107
     bool allButtonsPressed = true;
108
-    for (auto& g_button : m_buttons)
108
+    for (auto& g_button : m_pButtons)
109 109
     {
110 110
         g_button->read();
111 111
         allButtonsPressed = allButtonsPressed && g_button->isPressed();
@@ -119,13 +119,13 @@ void AppCore::setup()
119 119
     {
120 120
         LOG(5, "%s: Resetting settings", __FUNCTION__);
121 121
         m_storage.save(*m_appCoreState);
122
-        m_lcd.clear();
123
-        m_lcd.setCursor(6, 0);
124
-        m_lcd.print("Reset");
122
+        m_pLcd->clear();
123
+        m_pLcd->setCursor(6, 0);
124
+        m_pLcd->print("Reset");
125 125
         bool allButtonsPressed = true;
126 126
         while (allButtonsPressed)
127 127
         {
128
-            for (auto& g_button : m_buttons)
128
+            for (auto& g_button : m_pButtons)
129 129
             {
130 130
                 g_button->read();
131 131
                 allButtonsPressed = allButtonsPressed && g_button->isPressed();
@@ -146,8 +146,8 @@ void AppCore::loop()
146 146
     {
147 147
         m_appCoreState->appState.lastSensorRequestMs = currentMs;
148 148
         m_appCoreState->appState.hasReadSensors = false;
149
-        m_sensors.requestTemperaturesByAddress(m_sensor1);
150
-        m_sensors.requestTemperaturesByAddress(m_sensor2);
149
+        m_pSensors->requestTemperaturesByAddress(m_sensor1);
150
+        m_pSensors->requestTemperaturesByAddress(m_sensor2);
151 151
     }
152 152
     if (currentMs - m_appCoreState->appState.lastSensorRequestMs >= SENSORS_REQUEST_DELAY &&
153 153
         !m_appCoreState->appState.hasReadSensors)
@@ -160,7 +160,7 @@ void AppCore::loop()
160 160
     }
161 161
 
162 162
 
163
-    for (auto& pButton : m_buttons)
163
+    for (auto& pButton : m_pButtons)
164 164
     {
165 165
         pButton->read();
166 166
         if (pButton->isPressed())
@@ -173,7 +173,7 @@ void AppCore::loop()
173 173
 
174 174
     if (m_appCoreState->uiState.state == Hibernate)
175 175
     {
176
-        for (auto& pButton : m_buttons)
176
+        for (auto& pButton : m_pButtons)
177 177
         {
178 178
             if (pButton->wasReleased())
179 179
             {
@@ -287,7 +287,7 @@ void AppCore::readAndUpdateSensors(
287 287
 {
288 288
     LOG_FN_BEGIN(2);
289 289
 
290
-    auto raw = m_sensors.getTempC(sensor);
290
+    auto raw = m_pSensors->getTempC(sensor);
291 291
     temp_t temp = TEMP_T_INVALID;
292 292
     if (raw != DEVICE_DISCONNECTED_C)
293 293
     {
@@ -307,10 +307,10 @@ void AppCore::printState()
307 307
 {
308 308
     LOG_FN_BEGIN(2);
309 309
 
310
-    m_lcd.setCursor(0, 0);
310
+    m_pLcd->setCursor(0, 0);
311 311
     printStateLine('S', &m_appCoreState->appState.water, m_appCoreState->uiState.state == WaterSetting,
312 312
                    m_appCoreState->appState.water.isActive);
313
-    m_lcd.setCursor(0, 1);
313
+    m_pLcd->setCursor(0, 1);
314 314
     printStateLine('C', &m_appCoreState->appState.heater, m_appCoreState->uiState.state == HeaterSetting,
315 315
                    m_appCoreState->appState.heater.isActive);
316 316
     m_appCoreState->uiState.isUpdateNeeded = false;
@@ -338,7 +338,7 @@ AppCore::printStateLine(
338 338
         tmp[count] = ' ';
339 339
     }
340 340
     tmp[count] = 0;
341
-    m_lcd.print(tmp);
341
+    m_pLcd->print(tmp);
342 342
 
343 343
     LOG_FN_END(2);
344 344
 }

+ 4
- 4
AppCore.h View File

@@ -48,12 +48,12 @@ private:
48 48
     Button* m_pBtnOk;
49 49
     Button* m_pBtnMinus;
50 50
     Button* m_pBtnPlus;
51
-    Button* m_buttons[3];
51
+    Button* m_pButtons[3];
52 52
 
53
-    LiquidCrystal m_lcd;
53
+    LiquidCrystal* m_pLcd;
54 54
 
55
-    OneWire m_oneWire;
56
-    DallasTemperature m_sensors;
55
+    OneWire* m_pOneWire;
56
+    DallasTemperature* m_pSensors;
57 57
     DeviceAddress m_sensor1;
58 58
     DeviceAddress m_sensor2;
59 59
 };

Loading…
Cancel
Save