Closed lynniemagoo closed 1 year ago
Peter,
I have a working version of the code that will support the PCF8575. However, as the 8575 and the 8574 are very similar and can share the same interrupt bus, I'm thinking we want an aggregate version that will manage the GPIO for the interrupt pin.
I've added an examples2.js/ts file here that does exactly what examples.js did on the 2nd port.
The README may need updates but for what it's worth, here it is.
The script compiles with typescript as expected. What I did not include were your github workflows as I've not yet used this capability.
Let me know if you'd like to discuss further.
Lyndel
Hi Lyndel, thank you for your contribution! I think it would be the best, to integrate the PCF8575 into this module, as the most code parts are the same. I'll have a look at this in detail in the next days.
The changes are really simple. Instead of 8 pins, we have 16. Instead or writing one byte to I2C, we write 2. Compare pcf8575.ts to pcf8574.ts and you can quickly see.
To make an 'uber' module may require breaking backward compatibility as I'd think you'd want to add options or a special flag to the constructor. I'm also curious about something else. When I 'tsc' example.ts, I get different markup around I2C than you have in your example.js here. I'm not sure why. PCF8575 import resolves to __1 and the I2cBus.openSync has the (0, ... ) markup.
I specifically run 'tsc' from the root folder and as the examples are not compiled, I then go into that folder and 'tsc *.ts'.
What am I doing wrong or not specifying to have tsc pretty-up the code like in your original example.js?
// Import the i2c-bus module and open the bus var i2c_bus_1 = require("i2c-bus"); var i2cBus = (0, i2c_bus_1.openSync)(1); // Define the address of the PCF8575 var addr = 0x20; // Init a new PCF8575 with all pins high by default // Instead of 'true' you can also use a 8-bit binary notation to define each // pin speratly, e.g. 0b0000000000101010 var pcf = new __1.PCF8575(i2cBus, addr, true);
Hi Peter. Did you get a chance to have a look? I was thinking about the changes and based on the constructor I think this would be a breaking change. I'm curious as to how you would approach this.
Sorry, I haven't had much time for it so far.
My idea was to create an internal abstract base class (e.g called PCF857x) with all common code parts and extend this by a PCF8574 and a PCF8575 class containing the specific code parts. Then this two classes will be exported and the PCF8574 class will keep all existing interfaces as before, so no breaking change. Maybe nearly all code should be in the PCF857x base class and the extended classes only set some flag about the used type.
Perfect.
I've implemented the PCF8575 support know using a base class and two sub-classes as described above. Some docs and examples are still missing, but it should work. :)
Can you test it for the PCF8575 using the code from the current master branch?
Install it like:
npm install https://github.com/crycode-de/node-pcf8574
To import the PCF8575 class just use
import { PCF8575 } from 'pcf8574';
Peter, I’m out of the country on holiday until Jan 3rd. Will review sometime in the next few days but can’t test until I return home. Sent from my iPhone
Peter,I reviewed the code. Looks good and should work with no issues. I’m curious as to why you chose to not use the same I2C api call for both the 8574 and the 8575. The difference being that you write a buffer with one or two bytes depending on either 8 or 16 pins. When I return, I will fork the project and submit a PR if you are interested in using a common function. Merry Christmas.
Peter,
I just finished testing both PCF8574 and PCF8575 with your updates. I've also created this PR that also includes a separate PCF8575 example.
It should be ready for merge. https://github.com/crycode-de/node-pcf8574/pull/54
Thanks, Lyndel
Thank you!
I'll leave this issue open for know as a reminder to me to update the readme file and create a new npm release.
Peter, also see the typo PCF7585 in the readme at the bottom. I missed that earlier with your changes.
Hello Peter,
Just wanted you to know I'm now using this version via an npm install against github for now. Any updates as to when you might be pushing newer version to npm?
Oops... I totally forgot about that. Sorry!
Just released v3.0.1 on npm. :)
Hello Peter,
I'm currently using a PCF8575 module as they've become readily available on Amazon here in the US. I've ported the PCF8574 Nodejs code to support a 16 pin expander. I've not installed Typescript on my side to be able to create the .js file. However, I'm good to make modifications as needed.
I'd be interested in collaborating on a PCF8575 module. Might you be interested in publishing?
The PCF8575 is supported by Johnny-Five and Node Red but I really like the design of your module and prefer to use standalone.
Regards, Lynnie