Initial commit

This commit is contained in:
2022-07-28 22:16:03 +02:00
commit cdac555c3c
13 changed files with 187 additions and 0 deletions

54
app/src/main.cxx Normal file
View File

@@ -0,0 +1,54 @@
#include <nvidia.h>
#include <pwm.h>
#include <sensors/sensors.h>
#include <iostream>
int main() {
auto config = std::fopen("/etc/conf.d/sensors", "r");
if (sensors_init(config) != 0) {
std::cout << "Fuck" << std::endl;
return 1;
}
int c = 0;
for (const sensors_chip_name *i;
(i = sensors_get_detected_chips(0, &c)) != NULL;) {
std::cout << i->prefix << std::endl;
int d = 0;
for (const sensors_feature *j; (j = sensors_get_features(i, &d)) != NULL;) {
const sensors_subfeature *temp_feature =
sensors_get_subfeature(i, j, SENSORS_SUBFEATURE_TEMP_INPUT);
if (temp_feature) {
std::cout << sensors_get_label(i, j);
double value;
if (sensors_get_value(i, temp_feature->number, &value) == 0)
std::cout << ": " << value << " C" << std::endl;
}
const sensors_subfeature *fan_feature =
sensors_get_subfeature(i, j, SENSORS_SUBFEATURE_FAN_INPUT);
if (fan_feature) {
std::cout << sensors_get_label(i, j);
double value;
if (sensors_get_value(i, fan_feature->number, &value) == 0)
std::cout << ": " << value << " RPM" << std::endl;
}
}
std::cout << std::endl;
}
Nvidia nv;
auto temp = nv.get_gpu_temperature();
std::cout << "\nGPU Temp: " << temp << std::endl;
PWM pwm;
pwm.dumpValues();
return 0;
}

16
app/src/nvidia.cxx Normal file
View File

@@ -0,0 +1,16 @@
#include <include/nvml.h>
#include <nvidia.h>
Nvidia::Nvidia() { nvmlInit_v2(); }
Nvidia::~Nvidia() { nvmlShutdown(); }
double Nvidia::get_gpu_temperature() {
nvmlDevice_t device;
nvmlDeviceGetHandleByIndex_v2(0, &device);
unsigned int temp;
nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &temp);
return static_cast<double>(temp);
}

56
app/src/pwm.cxx Normal file
View File

@@ -0,0 +1,56 @@
#include <pwm.h>
#include <filesystem>
#include <iostream>
#include <regex>
namespace fs = std::filesystem;
using namespace std;
#define HWMON_BASE_PATH "/sys/class/hwmon"
#define PWM_POSTFIX_ENABLE "_enable"
#define PWM_POSTFIX_MODE "_mode"
PWM::PWM() {
const regex re_ctrl_enable("pwm[0-9]_enable");
const regex re_ctrl_mode("pwm[0-9]_mode");
const regex re_ctrl("pwm[0-9]");
if (!fs::exists(HWMON_BASE_PATH)) {
cerr << HWMON_BASE_PATH << " doesn't exist" << endl;
} else {
for (const fs::directory_entry &hwmon_device :
fs::directory_iterator{HWMON_BASE_PATH}) {
cout << hwmon_device << endl;
for (const fs::directory_entry &control :
fs::directory_iterator{hwmon_device}) {
auto filename = control.path().filename().string();
if (regex_match(filename, re_ctrl)) {
auto controlPath = control.path().string();
fs::path path_ctrl_enable(
string(controlPath + string(PWM_POSTFIX_ENABLE)));
fs::path path_ctrl_mode(
string(controlPath + string(PWM_POSTFIX_MODE)));
if (fs::exists(path_ctrl_enable) && fs::exists(path_ctrl_mode))
cout << control << endl;
mPwmControls.insert(
{controlPath, PWM_CONTROL{controlPath, path_ctrl_enable.string(),
path_ctrl_mode.string()}});
}
}
}
}
}
void PWM::dumpValues() {
for (auto control : mPwmControls) {
cout << control.second.control << ", " << control.second.enable << ", "
<< control.second.mode << endl;
}
}