diff --git a/index.js b/index.js index d9095fe..fb300a2 100644 --- a/index.js +++ b/index.js @@ -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); +}; \ No newline at end of file diff --git a/src/binding.cc b/src/binding.cc index 68da34a..71c8fb3 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -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 maybeFanNumber = Nan::To(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 maybeRPMNumber = Nan::To(info[1]); + if (maybeRPMNumber.IsNothing()) + return; + + unsigned int rpm = maybeRPMNumber.FromMaybe(0); + + // Get auth boolean + Nan::Maybe maybeAuth = Nan::To(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 exports) { NAN_EXPORT(exports, Open); @@ -98,6 +128,7 @@ namespace libsmc { NAN_EXPORT(exports, GetFans); NAN_EXPORT(exports, GetFanInformation); + NAN_EXPORT(exports, SetFanMinRPM); } NODE_MODULE(libsmc, Initialize)