Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ exports.getFan = function(number) {
exports.getNumberOfFans = function() {
return binding.GetFans();
};

exports.setFanMinRPM = function(fanNum, rpm, auth) {
if (typeof fanNum !== 'number' || (fanNum < 0))
throw new Error('fan number must be a positive integer');

if (typeof rpm !== 'number' || (rpm <= 0))
throw new Error('rpm must be a positive integer or 0');

// Convert to a boolean
auth = !!auth;

return binding.SetFanMinRPM(fanNum, rpm, auth);
};
31 changes: 31 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@ namespace libsmc {
info.GetReturnValue().Set(information);
}

// Sets the minimum RPM value for a fan
NAN_METHOD(SetFanMinRPM)
{
// JS provides us with a fan number, but that might not be satisfactory.
// Bail if it doesn't fit into an unsigned int type.
Nan::Maybe<unsigned int> maybeFanNumber = Nan::To<unsigned int>(info[0]);
if (maybeFanNumber.IsNothing())
return;

unsigned int fanNumber = maybeFanNumber.FromMaybe(0);

// JS provides us with an rpm number, but that might not be satisfactory.
// Bail if it doesn't fit into an unsigned int type.
Nan::Maybe<unsigned int> maybeRPMNumber = Nan::To<unsigned int>(info[1]);
if (maybeRPMNumber.IsNothing())
return;

unsigned int rpm = maybeRPMNumber.FromMaybe(0);

// Get auth boolean
Nan::Maybe<bool> maybeAuth = Nan::To<bool>(info[2]);
bool auth = maybeAuth.FromMaybe(true);

// Attempt to set the fan RPM
bool success = set_fan_min_rpm(fanNumber, rpm, auth);

// Return whether or not it worked.
info.GetReturnValue().Set(success);
}

// Initialize the module by exporting the methods.
void Initialize(v8::Local<v8::Object> exports) {
NAN_EXPORT(exports, Open);
Expand All @@ -98,6 +128,7 @@ namespace libsmc {

NAN_EXPORT(exports, GetFans);
NAN_EXPORT(exports, GetFanInformation);
NAN_EXPORT(exports, SetFanMinRPM);
}

NODE_MODULE(libsmc, Initialize)
Expand Down