Add mapping logic and serialization for writing

This commit is contained in:
2022-09-20 23:17:40 +02:00
parent df1c8f3821
commit 8ceb762fe1
68 changed files with 49901 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
#include <boost/json/object.hpp>
#include <fan/HwmonFan.h>
using namespace std;
@@ -9,3 +10,9 @@ HwmonFan::HwmonFan(shared_ptr<PwmControl> pwmControl,
void HwmonFan::pwm(int percent) { mPwmControl->pwm(percent); }
int HwmonFan::rpm() { return mRpmSensor->value(); }
json HwmonFan::toJson() const {
json obj;
obj["HwmonFan"] = {mPwmControl->toJson(), mRpmSensor->toJson()};
return obj;
}

View File

@@ -1,5 +1,7 @@
#include <boost/json/object.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <fan/PwmControl.h>
@@ -29,6 +31,11 @@ PwmControl::PwmControl(string controlPath) : mControlPath(controlPath) {
istrm.close();
}
PwmControl::~PwmControl() {
cout << "Cleanup" << endl;
Reset();
}
void PwmControl::pwm(int percent) {
int pwmValue = PWM_MAX_VALUE * percent / 100;
@@ -47,13 +54,13 @@ int PwmControl::pwm() {
return value;
}
void PwmControl::enableManualControl() {
void PwmControl::EnableManualControl() {
ofstream ostrm(mEnablePath, ios::trunc);
ostrm << static_cast<int>(PWM_ENABLE::MANUAL_CONTROL);
ostrm.close();
}
void PwmControl::reset() {
void PwmControl::Reset() {
ofstream ostrm(mEnablePath, ios::trunc);
ostrm << mInitialEnable;
@@ -68,3 +75,8 @@ void PwmControl::reset() {
const string PwmControl::toString() const {
return fs::path(mControlPath).filename();
}
json PwmControl::toJson() const {
json obj = {"PwmControl", toString()};
return obj;
}