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
           , m_pBtnOk(new Button{PIN_BTN_OK})
56
           , m_pBtnOk(new Button{PIN_BTN_OK})
57
           , m_pBtnMinus(new Button{PIN_BTN_MINUS})
57
           , m_pBtnMinus(new Button{PIN_BTN_MINUS})
58
           , m_pBtnPlus(new Button{PIN_BTN_PLUS})
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
           , m_sensor1{0}
63
           , m_sensor1{0}
64
           , m_sensor2{0}
64
           , m_sensor2{0}
65
 {
65
 {
70
     Serial.begin(9600);
70
     Serial.begin(9600);
71
     LOG_FN_BEGIN(1);
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
         g_button->begin();
81
         g_button->begin();
82
     }
82
     }
90
     pinMode(PIN_LCD_LED, OUTPUT);
90
     pinMode(PIN_LCD_LED, OUTPUT);
91
     digitalWrite(PIN_LCD_LED, 1);
91
     digitalWrite(PIN_LCD_LED, 1);
92
 
92
 
93
-    m_lcd.begin(16, 2);
93
+    m_pLcd->begin(16, 2);
94
     byte sensorChar[8] = {
94
     byte sensorChar[8] = {
95
             B00100,
95
             B00100,
96
             B01110,
96
             B01110,
101
             B11111,
101
             B11111,
102
             B01110,
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
     bool allButtonsPressed = true;
107
     bool allButtonsPressed = true;
108
-    for (auto& g_button : m_buttons)
108
+    for (auto& g_button : m_pButtons)
109
     {
109
     {
110
         g_button->read();
110
         g_button->read();
111
         allButtonsPressed = allButtonsPressed && g_button->isPressed();
111
         allButtonsPressed = allButtonsPressed && g_button->isPressed();
119
     {
119
     {
120
         LOG(5, "%s: Resetting settings", __FUNCTION__);
120
         LOG(5, "%s: Resetting settings", __FUNCTION__);
121
         m_storage.save(*m_appCoreState);
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
         bool allButtonsPressed = true;
125
         bool allButtonsPressed = true;
126
         while (allButtonsPressed)
126
         while (allButtonsPressed)
127
         {
127
         {
128
-            for (auto& g_button : m_buttons)
128
+            for (auto& g_button : m_pButtons)
129
             {
129
             {
130
                 g_button->read();
130
                 g_button->read();
131
                 allButtonsPressed = allButtonsPressed && g_button->isPressed();
131
                 allButtonsPressed = allButtonsPressed && g_button->isPressed();
146
     {
146
     {
147
         m_appCoreState->appState.lastSensorRequestMs = currentMs;
147
         m_appCoreState->appState.lastSensorRequestMs = currentMs;
148
         m_appCoreState->appState.hasReadSensors = false;
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
     if (currentMs - m_appCoreState->appState.lastSensorRequestMs >= SENSORS_REQUEST_DELAY &&
152
     if (currentMs - m_appCoreState->appState.lastSensorRequestMs >= SENSORS_REQUEST_DELAY &&
153
         !m_appCoreState->appState.hasReadSensors)
153
         !m_appCoreState->appState.hasReadSensors)
160
     }
160
     }
161
 
161
 
162
 
162
 
163
-    for (auto& pButton : m_buttons)
163
+    for (auto& pButton : m_pButtons)
164
     {
164
     {
165
         pButton->read();
165
         pButton->read();
166
         if (pButton->isPressed())
166
         if (pButton->isPressed())
173
 
173
 
174
     if (m_appCoreState->uiState.state == Hibernate)
174
     if (m_appCoreState->uiState.state == Hibernate)
175
     {
175
     {
176
-        for (auto& pButton : m_buttons)
176
+        for (auto& pButton : m_pButtons)
177
         {
177
         {
178
             if (pButton->wasReleased())
178
             if (pButton->wasReleased())
179
             {
179
             {
287
 {
287
 {
288
     LOG_FN_BEGIN(2);
288
     LOG_FN_BEGIN(2);
289
 
289
 
290
-    auto raw = m_sensors.getTempC(sensor);
290
+    auto raw = m_pSensors->getTempC(sensor);
291
     temp_t temp = TEMP_T_INVALID;
291
     temp_t temp = TEMP_T_INVALID;
292
     if (raw != DEVICE_DISCONNECTED_C)
292
     if (raw != DEVICE_DISCONNECTED_C)
293
     {
293
     {
307
 {
307
 {
308
     LOG_FN_BEGIN(2);
308
     LOG_FN_BEGIN(2);
309
 
309
 
310
-    m_lcd.setCursor(0, 0);
310
+    m_pLcd->setCursor(0, 0);
311
     printStateLine('S', &m_appCoreState->appState.water, m_appCoreState->uiState.state == WaterSetting,
311
     printStateLine('S', &m_appCoreState->appState.water, m_appCoreState->uiState.state == WaterSetting,
312
                    m_appCoreState->appState.water.isActive);
312
                    m_appCoreState->appState.water.isActive);
313
-    m_lcd.setCursor(0, 1);
313
+    m_pLcd->setCursor(0, 1);
314
     printStateLine('C', &m_appCoreState->appState.heater, m_appCoreState->uiState.state == HeaterSetting,
314
     printStateLine('C', &m_appCoreState->appState.heater, m_appCoreState->uiState.state == HeaterSetting,
315
                    m_appCoreState->appState.heater.isActive);
315
                    m_appCoreState->appState.heater.isActive);
316
     m_appCoreState->uiState.isUpdateNeeded = false;
316
     m_appCoreState->uiState.isUpdateNeeded = false;
338
         tmp[count] = ' ';
338
         tmp[count] = ' ';
339
     }
339
     }
340
     tmp[count] = 0;
340
     tmp[count] = 0;
341
-    m_lcd.print(tmp);
341
+    m_pLcd->print(tmp);
342
 
342
 
343
     LOG_FN_END(2);
343
     LOG_FN_END(2);
344
 }
344
 }

+ 4
- 4
AppCore.h View File

48
     Button* m_pBtnOk;
48
     Button* m_pBtnOk;
49
     Button* m_pBtnMinus;
49
     Button* m_pBtnMinus;
50
     Button* m_pBtnPlus;
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
     DeviceAddress m_sensor1;
57
     DeviceAddress m_sensor1;
58
     DeviceAddress m_sensor2;
58
     DeviceAddress m_sensor2;
59
 };
59
 };

Loading…
Cancel
Save