mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 15:09:23 +08:00
Added CPU Temp readout to OLED display type
This commit is contained in:
42
OLED.cpp
42
OLED.cpp
@@ -251,6 +251,20 @@ bool COLED::open()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float readTemperature(const std::string& filePath) {
|
||||||
|
std::ifstream file(filePath);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
std::cerr << "Error: Could not open file " << filePath << std::endl;
|
||||||
|
return -1.0; // Return a negative value to indicate that CPU temp is not available
|
||||||
|
}
|
||||||
|
|
||||||
|
float temperature;
|
||||||
|
file >> temperature;
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
return temperature / 1000.0; // The temperature is stored in millidegrees Celsius, so a bit of conversion
|
||||||
|
}
|
||||||
|
|
||||||
void COLED::setIdleInt()
|
void COLED::setIdleInt()
|
||||||
{
|
{
|
||||||
m_mode = MODE_IDLE;
|
m_mode = MODE_IDLE;
|
||||||
@@ -319,11 +333,22 @@ void COLED::setIdleInt()
|
|||||||
}
|
}
|
||||||
} else { // Connected to network - no Auto-AP mode; normal display layout...
|
} else { // Connected to network - no Auto-AP mode; normal display layout...
|
||||||
if (m_displayLogoScreensaver) {
|
if (m_displayLogoScreensaver) {
|
||||||
m_display.setCursor(0,OLED_LINE3);
|
m_display.setCursor(0,OLED_LINE2);
|
||||||
m_display.setTextSize(1);
|
m_display.setTextSize(1);
|
||||||
m_display.print(" -IDLE-");
|
m_display.print(" -IDLE-");
|
||||||
m_display.setCursor(0, OLED_LINE5);
|
m_display.setCursor(0, OLED_LINE4);
|
||||||
m_display.printf("%s", m_ipaddress.c_str());
|
m_display.printf("%s", m_ipaddress.c_str());
|
||||||
|
// Display temperature
|
||||||
|
float tempCelsius = readTemperature("/sys/class/thermal/thermal_zone0/temp");
|
||||||
|
if (tempCelsius >= 0.0) {
|
||||||
|
// Round the temperature to the nearest whole number
|
||||||
|
int roundedTempCelsius = static_cast<int>(std::round(tempCelsius));
|
||||||
|
// Convert to Fahrenheit
|
||||||
|
float tempFahrenheit = (roundedTempCelsius * 9/5) + 32;
|
||||||
|
m_display.setCursor(0, OLED_LINE5);
|
||||||
|
m_display.setTextSize(1);
|
||||||
|
m_display.printf("Temp: %.0fF / %dC ",tempFahrenheit,roundedTempCelsius);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_display.display();
|
m_display.display();
|
||||||
@@ -744,7 +769,7 @@ void COLED::writeCWInt()
|
|||||||
m_display.clearDisplay();
|
m_display.clearDisplay();
|
||||||
|
|
||||||
m_display.setCursor(0,30);
|
m_display.setCursor(0,30);
|
||||||
m_display.setTextSize(3);
|
m_display.setTextSize(2);
|
||||||
m_display.print("CW ID TX");
|
m_display.print("CW ID TX");
|
||||||
|
|
||||||
m_display.setTextSize(1);
|
m_display.setTextSize(1);
|
||||||
@@ -763,6 +788,17 @@ void COLED::clearCWInt()
|
|||||||
m_display.print(" -IDLE-");
|
m_display.print(" -IDLE-");
|
||||||
m_display.setCursor(0,OLED_LINE3);
|
m_display.setCursor(0,OLED_LINE3);
|
||||||
m_display.printf("%s",m_ipaddress.c_str());
|
m_display.printf("%s",m_ipaddress.c_str());
|
||||||
|
// Display temperature
|
||||||
|
float tempCelsius = readTemperature("/sys/class/thermal/thermal_zone0/temp");
|
||||||
|
if (tempCelsius >= 0.0) {
|
||||||
|
// Round the temperature to the nearest whole number
|
||||||
|
int roundedTempCelsius = static_cast<int>(std::round(tempCelsius));
|
||||||
|
// Convert to Fahrenheit
|
||||||
|
float tempFahrenheit = (roundedTempCelsius * 9/5) + 32;
|
||||||
|
m_display.setCursor(0, OLED_LINE5);
|
||||||
|
m_display.setTextSize(1);
|
||||||
|
m_display.printf("Temp: %.0fF / %dC ",tempFahrenheit,roundedTempCelsius);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_displayScroll)
|
if (m_displayScroll)
|
||||||
m_display.startscrolldiagleft(0x00,0x0f);
|
m_display.startscrolldiagleft(0x00,0x0f);
|
||||||
|
|||||||
2
OLED.h
2
OLED.h
@@ -34,6 +34,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <iostream> // for cpu temp value extraction
|
||||||
|
#include <cmath> // for cpu temp value rounding
|
||||||
|
|
||||||
#include "ArduiPi_OLED_lib.h"
|
#include "ArduiPi_OLED_lib.h"
|
||||||
#include "Adafruit_GFX.h"
|
#include "Adafruit_GFX.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user