GregDMeyer / IT8951

Driver for the IT8951 e-paper controller on Raspberry Pi
MIT License
155 stars 55 forks source link

SPI not closed #12

Closed KHome closed 4 years ago

KHome commented 4 years ago

Hi, thank you very much for supporting with this nice python-lib. In my setup I use https://www.smarthomeng.de/ to call a logic, which includes an update of the epaper.

I've missing a "close()" function for the display, which results in several opened SPIDEV ports. After a while my python instance can not open any file anymore. OS ERR24 I've helped myself by calling: "display.epd.spi.del()"

Could you add this kind a destructor?

GregDMeyer commented 4 years ago

Ah, thanks for the comment! Just to make sure I understand---you mean that you would like a more explicit close() function? The __del__ function should be called automatically when the SPI class is goes out of scope/is garbage collected. I am happy to make such a close() function, I just want to make sure I understand: is there a reason that you want to close the file but still keep the SPI object around? It seems that the SPI object would have no use after the file is closed.

Let me know! Cheers

KHome commented 4 years ago

a) you mean that you would like a more explicit close() function? --> Yes b) The del function should be called automatically when the SPI class is goes out of scope/is garbage collected --> In context of https://www.smarthomeng.de/ it seems that the object is not correctly destroyed, therefore this mechanism is not working. c) It seems that the SPI object would have no use after the file is closed. --> Correct; Is there another way to destroy the SPI object?

Thanx

GregDMeyer commented 4 years ago

I see. Yes, there is a nice way to do it. Just use the del statement. For example:

my_spi = SPI()  # create SPI object
...             # do some stuff with it
del my_spi      # object is deleted and file handle is closed

I think this is a better solution than adding a close() method, since the object would be useless after calling close() anyway. Let me know if you have any further question!