WiringPi / WiringPi-Node

Node.js bindings to wiringPi
333 stars 94 forks source link

Fixes #43 How to release a wiringPiI2CSetup() file descriptor #50

Closed NoHomey closed 7 years ago

NoHomey commented 7 years ago

I've searched WiringPi's src for functions that open a file descriptor and found that only SPI and I2C interfaces opens file descriptor by making call to open for which there is no corresponding disposing function, since in C/C++ it is expected close to be used like @nekuz0r pointed in #43.

The search showed that currently wiirngPiI2cSetup makes a call to wiringPiI2CSetupInterface which dose an open and wiringPiSPISetup makes a call to wiirngPiSPISetupMode which dose an open.

I've decided to add separate closing function for each communication interface instead of one core close for both since Serial has it's own serialClose and some one may potentially decide to close the opened file descriptor by making a call to that open function instead of serialClose ...

So with this PR I'm adding:

Both functions share a redundant implementation but having one separate implementation in nodemodule namespace would require manually writing function's implementation and exporting under different name using v8 members which in my opinion contrasts with the whole idea of addon.h beeing declaritive and unified framework for writing WiringPi's node addon ...

nekuz0r commented 7 years ago

@NoHomey Great job, exactly what i had in mind