Pi4J / pi4j-v2

Pi4J Version 2.0
Apache License 2.0
273 stars 57 forks source link

Spi flags overwriiten #240

Closed taartspi closed 1 year ago

taartspi commented 2 years ago

Sometime back I made a fix in the PiGpioSpi and commented a user might supply the flags attribute and that be overwritten. I said I would look at this and the other pigpio providers.

PiGpioSpi is the only provider that overwrites user data. I see two ways to fix this.

1 At present the PiGpioSpi does not know if the flags contents was user supplied or the default value. Same applies to the mode and bus. If it was known the code could validate the user hadn’t set bus or mode to one value in flags, and used a different values with the individual attributes. If the user confused things we could throw an IOException as done with other violations. But this requires changes in DefaultSpiConfig to track when these are user supplied and changes in PiGpioSpi to validate. The validation rules will be a cumbersome reading when you consider the combination of user /default supplied.

  1. Make mode and bus required, IOException if not user supplied. The validation will be compare mode and bus against the flag IF flag was user supplied, IOException for fails. I think the advantages to this is mode and bus value are made very obvious to the coder, and validation is simpler.

3 if they supply the flag attribute do not permit the mode or bus throw IOException. Remove code that overwrites the flag Your thoughts
@eitch @FDelporte

taartspi commented 1 year ago

I created a pull request as an implementation of the above question #248

eitch commented 1 year ago

I merged your PR. We will release a new version soon

taartspi commented 1 year ago

Code change merged