Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added typing and made an edit to fix a typing issue (non-breaking) #73

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

Merged
merged 5 commits into from
Nov 10, 2022
Merged

Added typing and made an edit to fix a typing issue (non-breaking) #73

merged 5 commits into from
Nov 10, 2022

Conversation

BiffoBear
Copy link

Added type hints to all functions. Edited character_lcd.color setter to resolve a typing conflict with a float used when an int was expected in the line pin.duty_cycle = int(_map(color[number], 0, 100, 65535, 0)). Converted r, g and b from float to int.

            r = int((color >> 16) / 2.55)
            g = int(((color >> 8) & 0xFF) / 2.55)
            b = int((color & 0xFF) / 2.55)
            color = [r, g, b]  # This is List[float], should be List[int]
        self._color = color
        for number, pin in enumerate(self.rgb_led):
            if hasattr(pin, "duty_cycle"):
                # Assume a pwmio.PWMOut or compatible interface and set duty cycle:
                pin.duty_cycle = int(_map(color[number], 0, 100, 65535, 0))

This matches the intent of the doc-string:

    def color(self) -> List[int, int, int]:
        """
        The color of the display. Provide a list of three integers ranging 0 - 100, ``[R, G, B]``.
        ``0`` is no color, or "off". ``100`` is maximum color. For example, the brightest red would
        be ``[100, 0, 0]``, and a half-bright purple would be, ``[50, 0, 50]``.

        If PWM is unavailable, ``0`` is off, and non-zero is on. For example, ``[1, 0, 0]`` would
        be red.

        The following example turns the LCD red and displays, "Hello, world!".

        The property returns a list, but can be set as an int in the format ``0xRRGGBB``,
        as output by `rainbowio.colorwheel` for example.
        """
        ...

BTW, character_lcd._set_bit() is not called anywhere and can be deleted.

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you!

@tekktrik tekktrik merged commit d11d147 into adafruit:main Nov 10, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 11, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_CharLCD to 3.4.4 from 3.4.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#73 from BiffoBear/add_typing
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH to 5.1.19 from 5.1.18:
  > Merge pull request adafruit/Adafruit_CircuitPython_LIS3DH#73 from crotwell/extra_underscore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_SharpMemoryDisplay to 1.4.6 from 1.4.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_SharpMemoryDisplay#22 from grouma/main
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 6.0.0 from 5.5.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#125 from BiffoBear/Make_is_connected_return_bool
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants