Skip to content

Commit 5deef50

Browse files
authored
Merge pull request #7 from fourstix/b_new_build
Updated files with Black and Pylint
2 parents 531c549 + f331486 commit 5deef50

9 files changed

+113
-93
lines changed

README.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ Introduction
2020
:target: https://github.com/psf/black
2121
:alt: Code Style: Black
2222

23-
CircuitPython library for Sparkfun Qwiic Joystick. This library is ported from the
23+
CircuitPython library for Sparkfun Qwiic Joystick. This library is ported from the
2424
`SparkFun Qwiic Joystick Arduino Library <https://github.com/sparkfun/SparkFun_Qwiic_Joystick_Arduino_Library>`_
2525

2626
.. image:: https://cdn.sparkfun.com/assets/parts/1/3/5/5/8/15168-SparkFun_Qwiic_Joystick-01.jpg
2727
:target: https://www.sparkfun.com/products/15168
2828
:alt: SparkFun Qwiic Joystick (COM-15168)
2929

3030
`SparkFun Qwiic Joystick (COM-15168) <https://www.sparkfun.com/products/15168>`_
31-
31+
3232

3333

3434
Dependencies
@@ -49,7 +49,7 @@ Raspberry Pi Setup
4949
------------------
5050
Adafruit has an excellent tutorial on `Installing CircuitPython Libraries on Raspberry Pi
5151
<https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi/>`_.
52-
52+
5353
Quick Start Summary:
5454
--------------------
5555
* Start with the latest version of Raspbian with Wifi configured.
@@ -200,15 +200,12 @@ Then run the build:
200200
201201
License Information
202202
-----------------------
203-
This product is **open source**!
203+
This product is **open source**!
204204

205-
Please review the LICENSE.md file for license information.
205+
Please review the LICENSE.md file for license information.
206206

207-
Please use, reuse, and modify these files as you see fit.
207+
Please use, reuse, and modify these files as you see fit.
208208

209209
Please maintain the attributions to SparkFun Electronics and Adafruit and release any derivative under the same license.
210210

211211
Distributed as-is; no warranty is given.
212-
213-
214-

docs/conf.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929

3030

3131
intersphinx_mapping = {
32-
"python": ("https://docs.python.org/3.4", None),"BusDevice": ("https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", None),
33-
32+
"python": ("https://docs.python.org/3.4", None),
33+
"BusDevice": (
34+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
35+
None,
36+
),
3437
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
3538
}
3639

examples/example1_basic_readings.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15
# This is example is for the SparkFun Qwiic Joystick.
26
# SparkFun sells these at its website: www.sparkfun.com
37
# Do you like this library? Help support SparkFun. Buy a board!
@@ -14,33 +18,37 @@
1418
This program uses the Qwiic Joystick CircuitPython Library to read and
1519
print the current joystick position and button state.
1620
"""
17-
21+
import sys
1822
from time import sleep
1923
import board
20-
import busio
2124
import sparkfun_qwiicjoystick
2225

2326
# Create bus object using our board's I2C port
24-
i2c = busio.I2C(board.SCL, board.SDA)
27+
i2c = board.I2C()
2528

2629
# Create joystick object
2730
joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c)
2831

2932
# Check if connected
3033
if joystick.connected:
31-
print('Joystick connected.')
34+
print("Joystick connected.")
3235
else:
33-
print('Joystick does not appear to be connected. Please check wiring.')
34-
exit()
36+
print("Joystick does not appear to be connected. Please check wiring.")
37+
sys.exit()
3538

36-
print('Joystick Version: ' + joystick.version)
37-
print('Type Ctrl-C to exit program.')
39+
print("Joystick Version: " + joystick.version)
40+
print("Type Ctrl-C to exit program.")
3841

3942
try:
4043
while True:
41-
print('X: ' + str(joystick.horizontal)
42-
+ ' Y: ' + str(joystick.vertical)
43-
+ ' Button: ' + str(joystick.button))
44+
print(
45+
"X: "
46+
+ str(joystick.horizontal)
47+
+ " Y: "
48+
+ str(joystick.vertical)
49+
+ " Button: "
50+
+ str(joystick.button)
51+
)
4452
# sleep a bit to slow down messages
4553
sleep(0.200)
4654
except KeyboardInterrupt:

examples/example2_change_i2c_address.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15
# This is example is for the SparkFun Qwiic Joystick.
26
# SparkFun sells these at its website: www.sparkfun.com
37
# Do you like this library? Help support SparkFun. Buy a board!
@@ -25,7 +29,6 @@
2529

2630
import sys
2731
import board
28-
import busio
2932
import sparkfun_qwiicjoystick
3033

3134
# The default QwiicJoystick i2c address is 0x20 (32)
@@ -38,56 +41,62 @@
3841
if len(sys.argv) > 1:
3942
try:
4043
# check to see if hex or decimal arguement
41-
if '0x' in sys.argv[1]:
44+
if "0x" in sys.argv[1]:
4245
i2c_address = int(sys.argv[1], 16)
4346
else:
4447
i2c_address = int(sys.argv[1])
4548
except ValueError:
46-
print('Ignoring invalid arguement: ' + str(sys.argv[1]))
49+
print("Ignoring invalid arguement: " + str(sys.argv[1]))
4750

4851
# Show the initial address
49-
print('Current i2c address = ' + str(i2c_address)
50-
+ ' [' + hex(i2c_address) + ']')
52+
print("Current i2c address = " + str(i2c_address) + " [" + hex(i2c_address) + "]")
5153

5254
# Create library object using our Bus I2C port
53-
i2c = busio.I2C(board.SCL, board.SDA)
55+
i2c = board.I2C()
5456
joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c, i2c_address)
5557

5658
if joystick.connected:
57-
print('Qwiic Joystick Example.')
59+
print("Qwiic Joystick Example.")
5860
else:
5961
# if we can't connecct, something is wrong so just quit
60-
print('Joystick does not appear to be connected. Please check wiring.')
61-
exit()
62-
63-
print('Address: ' + str(i2c_address) + ' [' + hex(i2c_address) + ']'
64-
+ ' Version: ' + joystick.version)
65-
66-
text = input('Enter a new I2C address (as a decimal from 8 to 119 or hex 0x08 to 0x77):')
62+
print("Joystick does not appear to be connected. Please check wiring.")
63+
sys.exit()
64+
65+
print(
66+
"Address: "
67+
+ str(i2c_address)
68+
+ " ["
69+
+ hex(i2c_address)
70+
+ "]"
71+
+ " Version: "
72+
+ joystick.version
73+
)
74+
75+
text = input(
76+
"Enter a new I2C address (as a decimal from 8 to 119 or hex 0x08 to 0x77):"
77+
)
6778

6879
# check to see if hex or decimal value
69-
if '0x' in text:
80+
if "0x" in text:
7081
new_address = int(text, 16)
7182
else:
7283
new_address = int(text)
7384

74-
print('Changing address to ' + str(new_address)
75-
+ ' [' + hex(new_address) + ']')
85+
print("Changing address to " + str(new_address) + " [" + hex(new_address) + "]")
7686

7787
result = joystick.set_i2c_address(new_address)
7888

7989
if result:
80-
print('Address changed to ' + str(new_address)
81-
+ ' [' + hex(new_address) + ']')
90+
print("Address changed to " + str(new_address) + " [" + hex(new_address) + "]")
8291
# After the change check the new connection and show firmware version
8392
if joystick.connected:
84-
print('Connected to Joystick after address change.')
85-
print('Firmware Version: ' + joystick.version)
93+
print("Connected to Joystick after address change.")
94+
print("Firmware Version: " + joystick.version)
8695
else:
87-
print('Error after address change. Cannot connect to Joystick.')
96+
print("Error after address change. Cannot connect to Joystick.")
8897

8998
else:
90-
print('Address change failed.')
99+
print("Address change failed.")
91100

92101
# good advice whether the address changed worked or not
93-
print('Run example3_i2c_scanner.py to verify the Qwiic Joystick address.')
102+
print("Run example3_i2c_scanner.py to verify the Qwiic Joystick address.")

examples/example3_i2c_scanner.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15
# This is example is for the SparkFun Qwiic Joystick.
26
# SparkFun sells these at its website: www.sparkfun.com
37
# Do you like this library? Help support SparkFun. Buy a board!
@@ -17,21 +21,21 @@
1721
"""
1822

1923
import time
20-
2124
import board
22-
import busio
2325

24-
i2c = busio.I2C(board.SCL, board.SDA)
26+
i2c = board.I2C()
2527

2628
while not i2c.try_lock():
2729
pass
2830

29-
print('Press Ctrl-C to exit program')
31+
print("Press Ctrl-C to exit program")
3032

3133
try:
3234
while True:
33-
print('I2C addresses found:',
34-
[hex(device_address) for device_address in i2c.scan()])
35+
print(
36+
"I2C addresses found:",
37+
[hex(device_address) for device_address in i2c.scan()],
38+
)
3539
time.sleep(5)
3640
except KeyboardInterrupt:
3741
pass

examples/example4_joystick_output.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15
# This is example is for the SparkFun Qwiic Joystick.
26
# SparkFun sells these at its website: www.sparkfun.com
37
# Do you like this library? Help support SparkFun. Buy a board!
@@ -14,28 +18,27 @@
1418
This program uses the Qwiic Joystick CircuitPython Library to read the
1519
joystick position and button state, and print them out as directions.
1620
"""
17-
21+
import sys
1822
from time import sleep
1923
import board
20-
import busio
2124
import sparkfun_qwiicjoystick
2225

2326
# Create bus object using our board's I2C port
24-
i2c = busio.I2C(board.SCL, board.SDA)
27+
i2c = board.I2C()
2528

2629
# Create joystick object
2730
joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c)
2831
# joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c, other_addr)
2932

3033
# Check if connected
3134
if joystick.connected:
32-
print('Joystick connected.')
35+
print("Joystick connected.")
3336
else:
34-
print('Joystick does not appear to be connected. Please check wiring.')
35-
exit()
37+
print("Joystick does not appear to be connected. Please check wiring.")
38+
sys.exit()
3639

37-
print('Joystick Version: ' + joystick.version)
38-
print('Type Ctrl-C to exit program.')
40+
print("Joystick Version: " + joystick.version)
41+
print("Type Ctrl-C to exit program.")
3942

4043
try:
4144
while True:
@@ -45,19 +48,19 @@
4548

4649
# print horizontal direction
4750
if x > 575:
48-
print('L')
51+
print("L")
4952
if x < 450:
50-
print('R')
53+
print("R")
5154

5255
# print vertical direction
5356
if y > 575:
54-
print('U')
57+
print("U")
5558
if y < 450:
56-
print('D')
59+
print("D")
5760

5861
# print button state
5962
if b == 0:
60-
print('Button')
63+
print("Button")
6164

6265
# sleep a bit to slow down messages
6366
sleep(0.200)

examples/qwiicjoystick_simpletest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
22
#
3-
# SPDX-License-Identifier: Unlicense
3+
# SPDX-License-Identifier: MIT
44

55
# This is example is for the SparkFun Qwiic Joystick.
66
# SparkFun sells these at its website: www.sparkfun.com
@@ -29,15 +29,15 @@
2929

3030
# Check if connected
3131
if joystick.connected:
32-
print('Joystick connected.')
32+
print("Joystick connected.")
3333
else:
34-
print('Joystick does not appear to be connected. Please check wiring.')
34+
print("Joystick does not appear to be connected. Please check wiring.")
3535
sys.exit()
3636

37-
print('Press Joystick button to exit program.')
37+
print("Press Joystick button to exit program.")
3838

3939
while joystick.button == 1:
40-
print('X = ' + str(joystick.horizontal) + ' Y = ' + str(joystick.vertical))
40+
print("X = " + str(joystick.horizontal) + " Y = " + str(joystick.vertical))
4141
sleep(0.200) # sleep a bit to slow down messages
4242

43-
print('Button pressed.')
43+
print("Button pressed.")

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
],
5959
# What does your project relate to?
6060
keywords="adafruit blinka circuitpython micropython qwiicjoystick sparkfun qwiic joystick",
61-
6261
# You can just specify the packages manually here if your project is
6362
# simple. Or you can use find_packages().
6463
# IF LIBRARY FILES ARE A PACKAGE FOLDER,

0 commit comments

Comments
 (0)