@@ -251,6 +251,20 @@ bool COLED::open()
251
251
return true ;
252
252
}
253
253
254
+ float readTemperature (const std::string& filePath) {
255
+ std::ifstream file (filePath);
256
+ if (!file.is_open ()) {
257
+ std::cerr << " Error: Could not open file " << filePath << std::endl;
258
+ return -1.0 ; // Return a negative value to indicate that CPU temp is not available
259
+ }
260
+
261
+ float temperature;
262
+ file >> temperature;
263
+ file.close ();
264
+
265
+ return temperature / 1000.0 ; // The temperature is stored in millidegrees Celsius, so a bit of conversion
266
+ }
267
+
254
268
void COLED::setIdleInt ()
255
269
{
256
270
m_mode = MODE_IDLE;
@@ -292,14 +306,14 @@ void COLED::setIdleInt()
292
306
if (configFile.is_open ()) {
293
307
std::string line;
294
308
while (std::getline (configFile, line)) {
295
- if (line.find (" ssid=" ) != std::string::npos) {
296
- std::istringstream iss (line);
297
- std::string key, value;
298
- if (std::getline (iss, key, ' =' ) && std::getline (iss, value)) {
299
- ssid = value;
300
- break ;
301
- }
302
- }
309
+ if (line.find (" ssid=" ) != std::string::npos) {
310
+ std::istringstream iss (line);
311
+ std::string key, value;
312
+ if (std::getline (iss, key, ' =' ) && std::getline (iss, value)) {
313
+ ssid = value;
314
+ break ;
315
+ }
316
+ }
303
317
}
304
318
configFile.close ();
305
319
} else {
@@ -319,11 +333,22 @@ void COLED::setIdleInt()
319
333
}
320
334
} else { // Connected to network - no Auto-AP mode; normal display layout...
321
335
if (m_displayLogoScreensaver) {
322
- m_display.setCursor (0 ,OLED_LINE3 );
336
+ m_display.setCursor (0 ,OLED_LINE2 );
323
337
m_display.setTextSize (1 );
324
338
m_display.print (" -IDLE-" );
325
- m_display.setCursor (0 , OLED_LINE5 );
339
+ m_display.setCursor (0 , OLED_LINE4 );
326
340
m_display.printf (" %s" , m_ipaddress.c_str ());
341
+ // Display temperature
342
+ float tempCelsius = readTemperature (" /sys/class/thermal/thermal_zone0/temp" );
343
+ if (tempCelsius >= 0.0 ) {
344
+ // Round the temperature to the nearest whole number
345
+ int roundedTempCelsius = static_cast <int >(std::round (tempCelsius));
346
+ // Convert to Fahrenheit
347
+ float tempFahrenheit = (roundedTempCelsius * 9 /5 ) + 32 ;
348
+ m_display.setCursor (0 , OLED_LINE5);
349
+ m_display.setTextSize (1 );
350
+ m_display.printf (" Temp: %.0fF / %dC " ,tempFahrenheit,roundedTempCelsius);
351
+ }
327
352
}
328
353
}
329
354
m_display.display ();
@@ -744,7 +769,7 @@ void COLED::writeCWInt()
744
769
m_display.clearDisplay ();
745
770
746
771
m_display.setCursor (0 ,30 );
747
- m_display.setTextSize (3 );
772
+ m_display.setTextSize (2 );
748
773
m_display.print (" CW ID TX" );
749
774
750
775
m_display.setTextSize (1 );
@@ -763,6 +788,17 @@ void COLED::clearCWInt()
763
788
m_display.print (" -IDLE-" );
764
789
m_display.setCursor (0 ,OLED_LINE3);
765
790
m_display.printf (" %s" ,m_ipaddress.c_str ());
791
+ // Display temperature
792
+ float tempCelsius = readTemperature (" /sys/class/thermal/thermal_zone0/temp" );
793
+ if (tempCelsius >= 0.0 ) {
794
+ // Round the temperature to the nearest whole number
795
+ int roundedTempCelsius = static_cast <int >(std::round (tempCelsius));
796
+ // Convert to Fahrenheit
797
+ float tempFahrenheit = (roundedTempCelsius * 9 /5 ) + 32 ;
798
+ m_display.setCursor (0 , OLED_LINE5);
799
+ m_display.setTextSize (1 );
800
+ m_display.printf (" Temp: %.0fF / %dC " ,tempFahrenheit,roundedTempCelsius);
801
+ }
766
802
767
803
if (m_displayScroll)
768
804
m_display.startscrolldiagleft (0x00 ,0x0f );
0 commit comments