Skip to content

Commit

Permalink
Updated files with Black and Pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
fourstix committed Nov 13, 2021
1 parent 7fe9b77 commit f331486
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 93 deletions.
15 changes: 6 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Introduction
:target: https://github.com/psf/black
:alt: Code Style: Black

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

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

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



Dependencies
Expand All @@ -49,7 +49,7 @@ Raspberry Pi Setup
------------------
Adafruit has an excellent tutorial on `Installing CircuitPython Libraries on Raspberry Pi
<https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi/>`_.

Quick Start Summary:
--------------------
* Start with the latest version of Raspbian with Wifi configured.
Expand Down Expand Up @@ -200,15 +200,12 @@ Then run the build:
License Information
-----------------------
This product is **open source**!
This product is **open source**!

Please review the LICENSE.md file for license information.
Please review the LICENSE.md file for license information.

Please use, reuse, and modify these files as you see fit.
Please use, reuse, and modify these files as you see fit.

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

Distributed as-is; no warranty is given.



7 changes: 5 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@


intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),"BusDevice": ("https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", None),

"python": ("https://docs.python.org/3.4", None),
"BusDevice": (
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
None,
),
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
}

Expand Down
30 changes: 19 additions & 11 deletions examples/example1_basic_readings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
#
# SPDX-License-Identifier: MIT

# This is example is for the SparkFun Qwiic Joystick.
# SparkFun sells these at its website: www.sparkfun.com
# Do you like this library? Help support SparkFun. Buy a board!
Expand All @@ -14,33 +18,37 @@
This program uses the Qwiic Joystick CircuitPython Library to read and
print the current joystick position and button state.
"""

import sys
from time import sleep
import board
import busio
import sparkfun_qwiicjoystick

# Create bus object using our board's I2C port
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

# Create joystick object
joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c)

# Check if connected
if joystick.connected:
print('Joystick connected.')
print("Joystick connected.")
else:
print('Joystick does not appear to be connected. Please check wiring.')
exit()
print("Joystick does not appear to be connected. Please check wiring.")
sys.exit()

print('Joystick Version: ' + joystick.version)
print('Type Ctrl-C to exit program.')
print("Joystick Version: " + joystick.version)
print("Type Ctrl-C to exit program.")

try:
while True:
print('X: ' + str(joystick.horizontal)
+ ' Y: ' + str(joystick.vertical)
+ ' Button: ' + str(joystick.button))
print(
"X: "
+ str(joystick.horizontal)
+ " Y: "
+ str(joystick.vertical)
+ " Button: "
+ str(joystick.button)
)
# sleep a bit to slow down messages
sleep(0.200)
except KeyboardInterrupt:
Expand Down
57 changes: 33 additions & 24 deletions examples/example2_change_i2c_address.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
#
# SPDX-License-Identifier: MIT

# This is example is for the SparkFun Qwiic Joystick.
# SparkFun sells these at its website: www.sparkfun.com
# Do you like this library? Help support SparkFun. Buy a board!
Expand Down Expand Up @@ -25,7 +29,6 @@

import sys
import board
import busio
import sparkfun_qwiicjoystick

# The default QwiicJoystick i2c address is 0x20 (32)
Expand All @@ -38,56 +41,62 @@
if len(sys.argv) > 1:
try:
# check to see if hex or decimal arguement
if '0x' in sys.argv[1]:
if "0x" in sys.argv[1]:
i2c_address = int(sys.argv[1], 16)
else:
i2c_address = int(sys.argv[1])
except ValueError:
print('Ignoring invalid arguement: ' + str(sys.argv[1]))
print("Ignoring invalid arguement: " + str(sys.argv[1]))

# Show the initial address
print('Current i2c address = ' + str(i2c_address)
+ ' [' + hex(i2c_address) + ']')
print("Current i2c address = " + str(i2c_address) + " [" + hex(i2c_address) + "]")

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c, i2c_address)

if joystick.connected:
print('Qwiic Joystick Example.')
print("Qwiic Joystick Example.")
else:
# if we can't connecct, something is wrong so just quit
print('Joystick does not appear to be connected. Please check wiring.')
exit()

print('Address: ' + str(i2c_address) + ' [' + hex(i2c_address) + ']'
+ ' Version: ' + joystick.version)

text = input('Enter a new I2C address (as a decimal from 8 to 119 or hex 0x08 to 0x77):')
print("Joystick does not appear to be connected. Please check wiring.")
sys.exit()

print(
"Address: "
+ str(i2c_address)
+ " ["
+ hex(i2c_address)
+ "]"
+ " Version: "
+ joystick.version
)

text = input(
"Enter a new I2C address (as a decimal from 8 to 119 or hex 0x08 to 0x77):"
)

# check to see if hex or decimal value
if '0x' in text:
if "0x" in text:
new_address = int(text, 16)
else:
new_address = int(text)

print('Changing address to ' + str(new_address)
+ ' [' + hex(new_address) + ']')
print("Changing address to " + str(new_address) + " [" + hex(new_address) + "]")

result = joystick.set_i2c_address(new_address)

if result:
print('Address changed to ' + str(new_address)
+ ' [' + hex(new_address) + ']')
print("Address changed to " + str(new_address) + " [" + hex(new_address) + "]")
# After the change check the new connection and show firmware version
if joystick.connected:
print('Connected to Joystick after address change.')
print('Firmware Version: ' + joystick.version)
print("Connected to Joystick after address change.")
print("Firmware Version: " + joystick.version)
else:
print('Error after address change. Cannot connect to Joystick.')
print("Error after address change. Cannot connect to Joystick.")

else:
print('Address change failed.')
print("Address change failed.")

# good advice whether the address changed worked or not
print('Run example3_i2c_scanner.py to verify the Qwiic Joystick address.')
print("Run example3_i2c_scanner.py to verify the Qwiic Joystick address.")
16 changes: 10 additions & 6 deletions examples/example3_i2c_scanner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
#
# SPDX-License-Identifier: MIT

# This is example is for the SparkFun Qwiic Joystick.
# SparkFun sells these at its website: www.sparkfun.com
# Do you like this library? Help support SparkFun. Buy a board!
Expand All @@ -17,21 +21,21 @@
"""

import time

import board
import busio

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

while not i2c.try_lock():
pass

print('Press Ctrl-C to exit program')
print("Press Ctrl-C to exit program")

try:
while True:
print('I2C addresses found:',
[hex(device_address) for device_address in i2c.scan()])
print(
"I2C addresses found:",
[hex(device_address) for device_address in i2c.scan()],
)
time.sleep(5)
except KeyboardInterrupt:
pass
Expand Down
29 changes: 16 additions & 13 deletions examples/example4_joystick_output.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
#
# SPDX-License-Identifier: MIT

# This is example is for the SparkFun Qwiic Joystick.
# SparkFun sells these at its website: www.sparkfun.com
# Do you like this library? Help support SparkFun. Buy a board!
Expand All @@ -14,28 +18,27 @@
This program uses the Qwiic Joystick CircuitPython Library to read the
joystick position and button state, and print them out as directions.
"""

import sys
from time import sleep
import board
import busio
import sparkfun_qwiicjoystick

# Create bus object using our board's I2C port
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

# Create joystick object
joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c)
# joystick = sparkfun_qwiicjoystick.Sparkfun_QwiicJoystick(i2c, other_addr)

# Check if connected
if joystick.connected:
print('Joystick connected.')
print("Joystick connected.")
else:
print('Joystick does not appear to be connected. Please check wiring.')
exit()
print("Joystick does not appear to be connected. Please check wiring.")
sys.exit()

print('Joystick Version: ' + joystick.version)
print('Type Ctrl-C to exit program.')
print("Joystick Version: " + joystick.version)
print("Type Ctrl-C to exit program.")

try:
while True:
Expand All @@ -45,19 +48,19 @@

# print horizontal direction
if x > 575:
print('L')
print("L")
if x < 450:
print('R')
print("R")

# print vertical direction
if y > 575:
print('U')
print("U")
if y < 450:
print('D')
print("D")

# print button state
if b == 0:
print('Button')
print("Button")

# sleep a bit to slow down messages
sleep(0.200)
Expand Down
12 changes: 6 additions & 6 deletions examples/qwiicjoystick_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
#
# SPDX-License-Identifier: Unlicense
# SPDX-License-Identifier: MIT

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

# Check if connected
if joystick.connected:
print('Joystick connected.')
print("Joystick connected.")
else:
print('Joystick does not appear to be connected. Please check wiring.')
print("Joystick does not appear to be connected. Please check wiring.")
sys.exit()

print('Press Joystick button to exit program.')
print("Press Joystick button to exit program.")

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

print('Button pressed.')
print("Button pressed.")
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
],
# What does your project relate to?
keywords="adafruit blinka circuitpython micropython qwiicjoystick sparkfun qwiic joystick",

# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
# IF LIBRARY FILES ARE A PACKAGE FOLDER,
Expand Down
Loading

0 comments on commit f331486

Please sign in to comment.