-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Tinker Board #19
Conversation
It looks mostly good so far, thanks for woking on it! (some of the code violates PEP 8, but we can fix that once everything else is working. I guess I did not think _BACKLIGHT_SYSFS_PATHS = {
BoardType.RASPBERRY_PI: "/sys/class/backlight/rpi_backlight/",
BoardType.TINKER_BOARD: "/sys/devices/platform/ff150000.i2c/i2c-3/3-0045/",
} and then change the parameter's default value to backlight_sysfs_path: Optional[Union[str, "PathLike[str]"]] = None, and then check if we weren't given a sysfs path, and assign the right one if so: if not isinstance(board_type, BoardType):
raise TypeError("board_type must be a a member of the BoardType enum, got {0}".format(type(board_type)))
if not backlight_sysfs_path:
backlight_sysfs_path = _BACKLIGHT_SYSFS_PATHS[board_type]
elif backlight_sysfs_path == _EMULATOR_MAGIC_STRING:
... existing code ... Let's also keep
That is likely because you define the enum twice, so the value you pass to the contructor and the one you compare against are actually not considered equal. That's expected behaviour, I think. Just define the enum once and then import it in cli.py 🙂
Yes, sorry about that - it was added in Python 3.6, so your solution using If you get stuck or have any questions, I'm happy to answer them! |
Hi @linusg Please note, Tinkerboard only has a brightness value, and no power or max brightness values. One thing of note: I was going to implement a smooth option, -s, for when you want to power on smoothly. But, I have commented this out as Im not sure youd like this, as brightness function does the same. If you are okay with the changes, tonight I plan on testing everything (have not begun intensive testing yet), and trying to learn how to black format. |
Just saw it, looking good! Just want to mention it, don't take everything I say/request for granted - it might be a good idea, if if you can think of somethink better implement that instead 😃
Let's discuss this in a separate issue/PR - please remove these changes for now as they're not relevant to this PR (support for Tinker Board). Having a clean history is somewhat important to me, and the changes will be easier to review if there's less "noise" in the diff. |
Co-Authored-By: Linus Groh <mail@linusgroh.de>
Co-Authored-By: Linus Groh <mail@linusgroh.de>
Hi @linusg |
There are still CI checks failing 🙂 it's a few mypy errors:
The first two could probably be solved by changing if self._board_type == BoardType.RASPBERRY_PI:
...
elif self._board_type == BoardType.TINKER_BOARD:
... to if self._board_type == BoardType.RASPBERRY_PI:
...
elif self._board_type == BoardType.TINKER_BOARD:
...
else:
raise RuntimeError("Invalid board type") This is handling the unlikely case that The last two are proper bugs, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got some feedback below. I'd also suggest updating the readme and docs and ideally test as well if you feel comfortable doing that!
Co-Authored-By: Linus Groh <mail@linusgroh.de>
Co-Authored-By: Linus Groh <mail@linusgroh.de>
Co-Authored-By: Linus Groh <mail@linusgroh.de>
I am still getting the CI errors... |
Hi @linusg Good news first: I am finally finished testing, everything seems to work, I am passing on Travis now, bugs seem to be out. Please do a review after reading the bad news. Bad news: Tonight I have also upgraded my Tinkerboard to latest 2.0.11 version image. In this version, they have implemented /sys/class/backlight/rpi_backlight/ Some things to point out
However, I am mentioning these points to you in case you want to completely remove /sys/devices/platform/ff150000.i2c/i2c-3/3-0045/ and do everything instead from /sys/class/backlight/rpi_backlight/ which does exist now Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made one minor comment but apart from that this looks great - thanks! Will do some testing this evening.
That's very much possible; I don't have a Tinker Board to verify - but nonetheless it still seems to be necessary to add these changes, as you say. And as long as they don't remove the old path, let's just stick with it 👍 |
Hi @p1r473, I tested the PR, works great! I have to request a few more changes, not your fault:
This is what the docs will look like:
For all changes I made see the diff below: diff --git a/rpi_backlight/__init__.py b/rpi_backlight/__init__.py
index d775501..6d3e1ba 100644
--- a/rpi_backlight/__init__.py
+++ b/rpi_backlight/__init__.py
@@ -10,11 +10,15 @@ if TYPE_CHECKING:
__author__ = "Linus Groh"
__version__ = "2.0.1"
-__all__ = ["Backlight"]
+__all__ = ["Backlight", "BoardType"]
class BoardType(Enum):
+ """Enum to specify a board type in the :class:`~rpi_backlight.Backlight` constructor."""
+
+ #: Raspberry Pi
RASPBERRY_PI = 1
+ #: Tinker Board
TINKER_BOARD = 2
@@ -38,8 +42,8 @@ class Backlight:
def __init__(
self,
- board_type: BoardType = BoardType.RASPBERRY_PI,
backlight_sysfs_path: Optional[Union[str, "PathLike[str]"]] = None,
+ board_type: BoardType = BoardType.RASPBERRY_PI,
):
"""Set ``backlight_sysfs_path`` to ``":emulator:"`` to use with rpi-backlight-emulator."""
if not isinstance(board_type, BoardType):
diff --git a/rpi_backlight/cli.py b/rpi_backlight/cli.py
index 19f5084..377f5cb 100644
--- a/rpi_backlight/cli.py
+++ b/rpi_backlight/cli.py
@@ -2,9 +2,9 @@ from argparse import ArgumentParser
from . import Backlight, __version__, BoardType
-board_types = {
- "raspberry_pi": BoardType.RASPBERRY_PI,
- "tinker_board": BoardType.TINKER_BOARD,
+BOARD_TYPES = {
+ "raspberry-pi": BoardType.RASPBERRY_PI,
+ "tinker-board": BoardType.TINKER_BOARD,
}
@@ -56,8 +56,8 @@ def _create_argument_parser():
parser.add_argument(
"-B",
"--board-type",
- default="raspberry_pi",
- choices=board_types.keys(),
+ default="raspberry-pi",
+ choices=BOARD_TYPES.keys(),
help="board type",
)
return parser
@@ -69,7 +69,7 @@ def main():
args = parser.parse_args()
backlight = Backlight(
- board_type=board_types[args.board_type], backlight_sysfs_path=args.sysfs_path
+ board_type=BOARD_TYPES[args.board_type], backlight_sysfs_path=args.sysfs_path
)
if args.get_brightness: Thank you! |
Changes made, thanks |
looks like you accidentally added new files instead of updating the ones in the |
Oopsies |
Let me check why Travis is failing now... |
@linusg have you had any luck installing black on your Pi? |
Merged, thanks! I'll update the docs to reflect this change and then release a new version on PyPI.
Yes, but only with
|
Hold up, seems to be a problem setting the default board type.
However, even with the default being TINKER_BOARD, board_type is still being detected as RASPBERRY_PI, when not using -B 2 |
Looks like we setting the default in the init and ALSO in the parser.
|
Yes, that's expected - you're not supposed to change the library source code 😄 The default for the CLI is set here: rpi-backlight/rpi_backlight/cli.py Line 59 in bdda78b
|
I think it's fine, as long as they match. Most users are probably using the display with a Raspberry Pi anyway, they don't have to do anything as the defaults will just work. Tinker Board users will have to set |
@linusg Hi, yes, that helps very much.
I've been working on this for 2 hours so far and seem to hit a roadblock.
I will keep this pull request open this time and we can work in this one, as I closed the last one
First, I'd like to check in with you and make sure I am following your plan so far.
Second, I can't seem to get this to work
Can you see if I am doing something bad with enum? I cant seem to get it to work unless I do
BTW, I couldnt use auto for enum, I think it is not supported on my Tinkerboard... Was not able to import it.