Skip to content

Docstrings updating #143

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 23 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[flake8]
docstring_style=sphinx
max-line-length = 127
ignore = D, Q000, P101, W605, S311, PLW, PLC, PLR
ignore = D400, Q000, P101, W605, S311, PLW, PLC, PLR
per-file-ignores =
buildhat/__init__.py:F401
exclude = docs/conf.py, docs/sphinxcontrib/cmtinc-buildhat.py, docs/sphinx_selective_exclude/*.py
1 change: 1 addition & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
echo "PYTHONPATH=." >> $GITHUB_ENV
- name: Lint with flake8
run: |
flake8 . --version
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
Expand Down
2 changes: 2 additions & 0 deletions buildhat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Provide all the classes we need for build HAT"""

from .color import ColorSensor
from .colordistance import ColorDistanceSensor
from .distance import DistanceSensor
Expand Down
37 changes: 26 additions & 11 deletions buildhat/color.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Color sensor handling functionality"""

import math
from collections import deque
from threading import Condition
Expand All @@ -11,16 +13,25 @@ class ColorSensor(Device):
:param port: Port of device
:raises DeviceError: Occurs if there is no color sensor attached to port
"""

def __init__(self, port):
"""
Initialise color sensor

:param port: Port of device
"""
super().__init__(port)
self.reverse()
self.mode(6)
self.avg_reads = 4
self._old_color = None

def segment_color(self, r, g, b):
"""Returns the color name from RGB
"""Return the color name from RGB

:param r: Red
:param g: Green
:param b: Blue
:return: Name of the color as a string
:rtype: str
"""
Expand All @@ -46,6 +57,9 @@ def rgb_to_hsv(self, r, g, b):

Based on https://www.rapidtables.com/convert/color/rgb-to-hsv.html algorithm

:param r: Red
:param g: Green
:param b: Blue
:return: HSV representation of color
:rtype: tuple
"""
Expand All @@ -69,7 +83,7 @@ def rgb_to_hsv(self, r, g, b):
return int(h), int(s * 100), int(v * 100)

def get_color(self):
"""Returns the color
"""Return the color

:return: Name of the color as a string
:rtype: str
Expand All @@ -78,7 +92,7 @@ def get_color(self):
return self.segment_color(r, g, b)

def get_ambient_light(self):
"""Returns the ambient light
"""Return the ambient light

:return: Ambient light
:rtype: int
Expand All @@ -90,7 +104,7 @@ def get_ambient_light(self):
return int(sum(readings) / len(readings))

def get_reflected_light(self):
"""Returns the reflected light
"""Return the reflected light

:return: Reflected light
:rtype: int
Expand All @@ -115,7 +129,7 @@ def _avgrgbi(self, reads):
return rgbi

def get_color_rgbi(self):
"""Returns the color
"""Return the color

:return: RGBI representation
:rtype: list
Expand All @@ -127,7 +141,7 @@ def get_color_rgbi(self):
return self._avgrgbi(reads)

def get_color_hsv(self):
"""Returns the color
"""Return the color

:return: HSV representation
:rtype: tuple
Expand Down Expand Up @@ -160,7 +174,7 @@ def _cb_handle(self, lst):
self._cond.notify()

def wait_until_color(self, color):
"""Waits until specific color
"""Wait until specific color

:param color: Color to look for
"""
Expand All @@ -175,7 +189,10 @@ def wait_until_color(self, color):
self.callback(None)

def wait_for_new_color(self):
"""Waits for new color or returns immediately if first call
"""Wait for new color or returns immediately if first call

:return: Name of the color as a string
:rtype: str
"""
self.mode(5)
if self._old_color is None:
Expand All @@ -192,7 +209,5 @@ def wait_for_new_color(self):
return self._old_color

def on(self):
"""
Turns on the sensor and LED
"""
"""Turn on the sensor and LED"""
self._write("port {} ; plimit 1 ; set -1\r".format(self.port))
35 changes: 25 additions & 10 deletions buildhat/colordistance.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Color distance sensor handling functionality"""

import math
from collections import deque
from threading import Condition
Expand All @@ -11,16 +13,25 @@ class ColorDistanceSensor(Device):
:param port: Port of device
:raises DeviceError: Occurs if there is no colordistance sensor attached to port
"""

def __init__(self, port):
"""
Initialise color distance sensor

:param port: Port of device
"""
super().__init__(port)
self.on()
self.mode(6)
self.avg_reads = 4
self._old_color = None

def segment_color(self, r, g, b):
"""Returns the color name from HSV
"""Return the color name from HSV

:param r: Red
:param g: Green
:param b: Blue
:return: Name of the color as a string
:rtype: str
"""
Expand All @@ -46,6 +57,9 @@ def rgb_to_hsv(self, r, g, b):

Based on https://www.rapidtables.com/convert/color/rgb-to-hsv.html algorithm

:param r: Red
:param g: Green
:param b: Blue
:return: HSV representation of color
:rtype: tuple
"""
Expand All @@ -69,7 +83,7 @@ def rgb_to_hsv(self, r, g, b):
return int(h), int(s * 100), int(v * 100)

def get_color(self):
"""Returns the color
"""Return the color

:return: Name of the color as a string
:rtype: str
Expand All @@ -78,7 +92,7 @@ def get_color(self):
return self.segment_color(r, g, b)

def get_ambient_light(self):
"""Returns the ambient light
"""Return the ambient light

:return: Ambient light
:rtype: int
Expand All @@ -90,7 +104,7 @@ def get_ambient_light(self):
return int(sum(readings) / len(readings))

def get_reflected_light(self):
"""Returns the reflected light
"""Return the reflected light

:return: Reflected light
:rtype: int
Expand All @@ -117,7 +131,7 @@ def _avgrgb(self, reads):
return rgb

def get_color_rgb(self):
"""Returns the color
"""Return the color

:return: RGBI representation
:rtype: list
Expand All @@ -139,7 +153,7 @@ def _cb_handle(self, lst):
self._cond.notify()

def wait_until_color(self, color):
"""Waits until specific color
"""Wait until specific color

:param color: Color to look for
"""
Expand All @@ -154,7 +168,10 @@ def wait_until_color(self, color):
self.callback(None)

def wait_for_new_color(self):
"""Waits for new color or returns immediately if first call
"""Wait for new color or returns immediately if first call

:return: Name of the color as a string
:rtype: str
"""
self.mode(6)
if self._old_color is None:
Expand All @@ -171,7 +188,5 @@ def wait_for_new_color(self):
return self._old_color

def on(self):
"""
Turns on the sensor and LED
"""
"""Turn on the sensor and LED"""
self._write("port {} ; plimit 1 ; set -1\r".format(self.port))
Loading