linusg / rpi-backlight

🔆 A Python module for controlling power and brightness of the official Raspberry Pi 7" touch display
https://rpi-backlight.readthedocs.io
MIT License
276 stars 32 forks source link

Implement automatic board detection #32

Closed p1r473 closed 3 years ago

p1r473 commented 3 years ago

Hi Linus, I have taken a stab at implementation. It works!

A few points for you to review -I am not sure if I did the enumeration to your liking. -I removed the part in the readme, now that it works out of the box. -After I blacked the files, it rearranged the whitespace on your argument parser -I didnt know if I should put the _get_board in the Backlight class. I'm not very good with OOP, so I was not able to access it with self._get_board(). My guess is because it hasn't been init'd yet.

Thanks,

Fixes #30

p1r473 commented 3 years ago

Looks like the build is failing with

FileNotFoundError: [Errno 2] No such file or directory: '/proc/device-tree/model'

Perhaps the error checker does not have this file. However, my TinkerBoard 1 + 2 and the Pi have this

I've reimplemented the try:except so the build works.

p1r473 commented 3 years ago

I am ready for a re-review Thanks,

p1r473 commented 3 years ago

Seems to be failing with

rpi_backlight/utils.py:1: error: Module "__future__" has no attribute "annotations"
Found 1 error in 1 file (checked 9 source files)
Error: Process completed with exit code 1.

Without from __future__ import annotations I get

root@Harbormaster:/home/linaro/rpi-backlight# python3 setup.py install;
Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    from rpi_backlight import __version__
  File "/home/linaro/rpi-backlight/rpi_backlight/__init__.py", line 10, in <module>
    from . import utils
  File "/home/linaro/rpi-backlight/rpi_backlight/utils.py", line 11, in <module>
    def detect_board_type() -> Optional[BoardType]:
NameError: name 'BoardType' is not defined

According to https://stackoverflow.com/questions/46641078/how-to-avoid-circular-dependency-caused-by-type-hinting-of-pointer-attributes-in this import is required to allow for names to not be evaluated at compilation

Looks like it may be Python 3.7+ only

linusg commented 3 years ago

oh, hmm. Let's remove the annotations import then and make the return type Optional["BoardType"], as a string. I'm not used to this old Python anymore :D

p1r473 commented 3 years ago

Thanks Linus for your guidance As you can tell I am not as good at Python as you, so I am thankful for your teachings. I learned a lot this round! Thanks,

p1r473 commented 3 years ago

Hi, I've removed the unused import and ready for the final review Thanks,

linusg commented 3 years ago

https://github.com/linusg/rpi-backlight/pull/32#discussion_r650251704

Please add the comma and restore the original formatting :)

p1r473 commented 3 years ago

Fixed the version parser argument formatting, thanks!

linusg commented 3 years ago

:rocket: