Skip to content

Ran black, updated to pylint 2.x #90

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 1 commit into from
Mar 20, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
5 changes: 3 additions & 2 deletions adafruit_circuitplayground/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"""Verifies which board is being used and imports the appropriate module."""

import sys
if sys.platform == 'nRF52840':

if sys.platform == "nRF52840":
from .bluefruit import cpb as cp
elif sys.platform == 'Atmel SAMD21':
elif sys.platform == "Atmel SAMD21":
from .express import cpx as cp
25 changes: 18 additions & 7 deletions adafruit_circuitplayground/bluefruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,35 @@ class Bluefruit(CircuitPlaygroundBase):

def __init__(self):
# Only create the cpb module member when we aren't being imported by Sphinx
if ("__module__" in dir(digitalio.DigitalInOut) and
digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"):
if (
"__module__" in dir(digitalio.DigitalInOut)
and digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"
):
return

super().__init__()

self._sample = None

# Define mic/sound sensor:
self._mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
sample_rate=16000, bit_depth=16)
self._mic = audiobusio.PDMIn(
board.MICROPHONE_CLOCK,
board.MICROPHONE_DATA,
sample_rate=16000,
bit_depth=16,
)
self._samples = None

@staticmethod
def _normalized_rms(values):
mean_values = int(sum(values) / len(values))
return math.sqrt(sum(float(sample - mean_values) * (sample - mean_values)
for sample in values) / len(values))
return math.sqrt(
sum(
float(sample - mean_values) * (sample - mean_values)
for sample in values
)
/ len(values)
)

@property
def sound_level(self):
Expand All @@ -94,7 +105,7 @@ def sound_level(self):
print(cpb.sound_level)
"""
if self._sample is None:
self._samples = array.array('H', [0] * 160)
self._samples = array.array("H", [0] * 160)
self._mic.record(self._samples, len(self._samples))
return self._normalized_rms(self._samples)

Expand Down
39 changes: 29 additions & 10 deletions adafruit_circuitplayground/circuit_playground_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@
import math
import array
import time

try:
import audiocore
except ImportError:
import audioio as audiocore
import adafruit_lis3dh
import adafruit_thermistor
import analogio
import board
import busio
import digitalio
import adafruit_lis3dh
import adafruit_thermistor
import neopixel
import touchio
import gamepad
Expand All @@ -60,6 +61,7 @@

class Photocell:
"""Simple driver for analog photocell on the Circuit Playground Express and Bluefruit."""

# pylint: disable=too-few-public-methods
def __init__(self, pin):
self._photocell = analogio.AnalogIn(pin)
Expand All @@ -71,7 +73,7 @@ def light(self):
return self._photocell.value * 330 // (2 ** 16)


class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
"""Circuit Playground base class."""

_audio_out = None
Expand All @@ -93,7 +95,9 @@ def __init__(self):
self._pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)

# Define sensors:
self._temp = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
self._temp = adafruit_thermistor.Thermistor(
board.TEMPERATURE, 10000, 10000, 25, 3950
)
self._light = Photocell(board.LIGHT)

# Define touch:
Expand All @@ -103,13 +107,24 @@ def __init__(self):
# For example, after `cp.touch_A2`, self._touches is equivalent to:
# [None, board.A1, touchio.TouchIn(board.A2), board.A3, ...]
# Slot 0 is not used (A0 is not allowed as a touch pin).
self._touches = [None, board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.TX]
self._touches = [
None,
board.A1,
board.A2,
board.A3,
board.A4,
board.A5,
board.A6,
board.TX,
]
self._touch_threshold_adjustment = 0

# Define acceleration:
self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
self._int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19, int1=self._int1)
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(
self._i2c, address=0x19, int1=self._int1
)
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G

# Define audio:
Expand Down Expand Up @@ -148,9 +163,13 @@ def detect_taps(self):
def detect_taps(self, value):
self._detect_taps = value
if value == 1:
self._lis3dh.set_tap(value, 90, time_limit=4, time_latency=50, time_window=255)
self._lis3dh.set_tap(
value, 90, time_limit=4, time_latency=50, time_window=255
)
if value == 2:
self._lis3dh.set_tap(value, 60, time_limit=10, time_latency=50, time_window=255)
self._lis3dh.set_tap(
value, 60, time_limit=10, time_latency=50, time_window=255
)

@property
def tapped(self):
Expand Down Expand Up @@ -515,7 +534,7 @@ def were_pressed(self):
"""
ret = set()
pressed = self.gamepad.get_pressed()
for button, mask in (('A', 0x01), ('B', 0x02)):
for button, mask in (("A", 0x01), ("B", 0x02)):
if mask & pressed:
ret.add(button)
return ret
Expand Down Expand Up @@ -619,7 +638,7 @@ def _sine_sample(length):
tone_volume = (2 ** 15) - 1
shift = 2 ** 15
for i in range(length):
yield int(tone_volume * math.sin(2*math.pi*(i / length)) + shift)
yield int(tone_volume * math.sin(2 * math.pi * (i / length)) + shift)

def _generate_sample(self, length=100):
if self._sample is not None:
Expand Down
20 changes: 13 additions & 7 deletions adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@
"""

import sys
import audioio
import digitalio
# pylint: disable=wrong-import-position
import audioio

try:
lib_index = sys.path.index("/lib") # pylint: disable=invalid-name
lib_index = sys.path.index("/lib") # pylint: disable=invalid-name
if lib_index < sys.path.index(".frozen"):
# Prefer frozen modules over those in /lib.
sys.path.insert(lib_index, ".frozen")
except ValueError:
# Don't change sys.path if it doesn't contain "lib" or ".frozen".
pass
from adafruit_circuitplayground.circuit_playground_base import CircuitPlaygroundBase
from adafruit_circuitplayground.circuit_playground_base import ( # pylint: disable=wrong-import-position
CircuitPlaygroundBase,
)


__version__ = "0.0.0-auto.0"
Expand All @@ -65,16 +67,20 @@ class Express(CircuitPlaygroundBase):

def __init__(self):
# Only create the cpx module member when we aren't being imported by Sphinx
if ("__module__" in dir(digitalio.DigitalInOut) and
digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"):
if (
"__module__" in dir(digitalio.DigitalInOut)
and digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"
):
return

super().__init__()

@property
def _unsupported(self):
"""This feature is not supported on Circuit Playground Express."""
raise NotImplementedError("This feature is not supported on Circuit Playground Express.")
raise NotImplementedError(
"This feature is not supported on Circuit Playground Express."
)

# The following is a list of the features available in other Circuit Playground modules but
# not available for Circuit Playground Express. If called while using a Circuit Playground
Expand Down
Loading