pi4j-v2 icon indicating copy to clipboard operation
pi4j-v2 copied to clipboard

Spi flags overwriiten

Open taartspi opened this issue 3 years ago • 2 comments
trafficstars

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 avatar Sep 20 '22 00:09 taartspi

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

taartspi avatar Oct 16 '22 23:10 taartspi

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

eitch avatar Oct 17 '22 07:10 eitch

Code change merged

taartspi avatar Feb 01 '23 00:02 taartspi