#include #include #include #include #include #include #include #include #define SETTLE_TIMEOUT 5 using namespace std; vector> FanGenerator::FindFans(vector> rpmSensors, vector> pwmControls) { print("RPM Sensors", rpmSensors); print("PWM controllers", pwmControls); vector> mapping; cout << "Setting all fans to maximum speed" << endl; for (auto c : pwmControls) { c->EnableManualControl(); c->Power(100); } // Wait for fans to settle cout << "Waiting for fans to settle" << endl; this_thread::sleep_for(chrono::seconds(SETTLE_TIMEOUT)); // Record values of all RPM sensors for (auto s : rpmSensors) { int value = s->value(); s->max(value); cout << s->toString() << " max value: " << s->max() << endl; } // Set each fan to 50% and check if a sensor matches for (auto c : pwmControls) { cout << "Setting " << c->toString() << " to 50% and wait for it to settle..." << endl; c->Power(50); this_thread::sleep_for(chrono::seconds(SETTLE_TIMEOUT)); for (auto s : rpmSensors) { if (s->value() < s->max() * 0.7) { cout << "Found matching sensor " << s->toString() << endl; mapping.push_back(make_shared(c, s)); } } cout << "Setting fan back to 100%" << endl; c->Power(100); } return mapping; } template void FanGenerator::print(string listLabel, vector> list) { cout << listLabel << ": " << endl; for (auto i : list) { cout << i->toString() << endl; } cout << "\n"; }