Fix PEP8 compliance

This commit is contained in:
Craig Richardson 2018-05-14 22:12:24 +01:00
parent 0da6d60d5b
commit c7086527c4
8 changed files with 45 additions and 44 deletions

View file

@ -1,6 +1,7 @@
# CircuitPython demo - NeoPixel RGBW # CircuitPython demo - NeoPixel RGBW
import time import time
import board import board
import neopixel import neopixel
@ -8,7 +9,8 @@ pixel_pin = board.A1
num_pixels = 8 num_pixels = 8
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, pixels = neopixel.NeoPixel(pixel_pin, num_pixels,
brightness=0.3, auto_write=False, pixel_order=(1, 0, 2, 3)) brightness=0.3, auto_write=False,
pixel_order=(1, 0, 2, 3))
def wheel(pos): def wheel(pos):

View file

@ -9,5 +9,5 @@ for pin_name in dir(board):
print("PWM on:", pin_name) # Prints the valid, PWM-capable pins! print("PWM on:", pin_name) # Prints the valid, PWM-capable pins!
except ValueError: # This is the error returned when the pin is invalid. except ValueError: # This is the error returned when the pin is invalid.
print("No PWM on:", pin_name) # Prints the invalid pins. print("No PWM on:", pin_name) # Prints the invalid pins.
except RuntimeError: # This is the error returned when there is a timer conflict. except RuntimeError: # Timer conflict error.
print("Timers in use:", pin_name) # Prints the timer conflict pins. print("Timers in use:", pin_name) # Prints the timer conflict pins.

View file

@ -9,7 +9,8 @@ pixel_pin = board.A1
num_pixels = 8 num_pixels = 8
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, pixels = neopixel.NeoPixel(pixel_pin, num_pixels,
brightness=0.3, auto_write=False, pixel_order=(1, 0, 2, 3)) brightness=0.3, auto_write=False,
pixel_order=(1, 0, 2, 3))
def wheel(pos): def wheel(pos):

View file

@ -9,5 +9,5 @@ for pin_name in dir(board):
print("PWM on:", pin_name) # Prints the valid, PWM-capable pins! print("PWM on:", pin_name) # Prints the valid, PWM-capable pins!
except ValueError: # This is the error returned when the pin is invalid. except ValueError: # This is the error returned when the pin is invalid.
print("No PWM on:", pin_name) # Prints the invalid pins. print("No PWM on:", pin_name) # Prints the invalid pins.
except RuntimeError: # This is the error returned when there is a timer conflict. except RuntimeError: # Timer conflict error.
print("Timers in use:", pin_name) # Prints the timer conflict pins. print("Timers in use:", pin_name) # Prints the timer conflict pins.

View file

@ -42,8 +42,10 @@ while True:
print("Humidity:", humidity) print("Humidity:", humidity)
print("VBat voltage: {:.2f}".format(battery_voltage)) print("VBat voltage: {:.2f}".format(battery_voltage))
print() print()
sdc.write("{}, {}, {}, {:.2f}\n".format(int(time_stamp), temperature, sdc.write("{}, {}, {}, {:.2f}\n".format(
humidity, battery_voltage)) int(time_stamp), temperature,
humidity, battery_voltage)
)
time.sleep(3) time.sleep(3)
except OSError: except OSError:
pass pass

View file

@ -59,16 +59,16 @@ print("Waiting for button presses")
def pressbutton(i): def pressbutton(i):
l = leds[i] # find the switch LED switch_led = leds[i] # find the switch LED
k = buttonkeys[i] # get the corresp. keycode/str k = buttonkeys[i] # get the corresp. keycode/str
l.value = True # turn on LED switch_led.value = True # turn on LED
kbd.press(k) # send keycode kbd.press(k) # send keycode
def releasebutton(i): def releasebutton(i):
l = leds[i] # find the switch LED switch_led = leds[i] # find the switch LED
k = buttonkeys[i] # get the corresp. keycode/str k = buttonkeys[i] # get the corresp. keycode/str
l.value = False # turn on LED switch_led.value = False # turn on LED
kbd.release(k) # send keycode kbd.release(k) # send keycode
@ -98,15 +98,15 @@ while True:
# check each button # check each button
for button in buttons: for button in buttons:
i = buttons.index(button) i = buttons.index(button)
if button.value == False: # button is pressed? if button.value is False: # button is pressed?
buttonspressed[i] = True # save pressed button buttonspressed[i] = True # save pressed button
# was button not pressed last time? # was button not pressed last time?
if buttonspressedlast[i] == False: if buttonspressedlast[i] is False:
print("Pressed #%d" % i) print("Pressed #%d" % i)
pressbutton(i) pressbutton(i)
else: else:
buttonspressed[i] = False # button was not pressed buttonspressed[i] = False # button was not pressed
if buttonspressedlast[i] == True: # was button pressed last time? if buttonspressedlast[i] is True: # was button pressed last time?
print("Released #%d" % i) print("Released #%d" % i)
releasebutton(i) releasebutton(i)
lightneopixels() lightneopixels()

View file

@ -1,4 +1,3 @@
###############################################
# Minecraft Gesture Controller # Minecraft Gesture Controller
# #
# Written by <jenfoxbot@gmail.com> # Written by <jenfoxbot@gmail.com>
@ -7,11 +6,9 @@
# Super awesome thanks to: # Super awesome thanks to:
# Richard Albritton, Tony DiCola, John Parker # Richard Albritton, Tony DiCola, John Parker
# All the awesome people who wrote the libraries # All the awesome people who wrote the libraries
################################################
########################## # Libraries
## Libraries ##
##########################
import time import time
@ -27,9 +24,7 @@ from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode from adafruit_hid.keycode import Keycode
from adafruit_hid.mouse import Mouse from adafruit_hid.mouse import Mouse
####################### # CPX Setup
# CPX Setup #
#######################
touch_a1 = touchio.TouchIn(board.A1) touch_a1 = touchio.TouchIn(board.A1)
touch_a1.threshold = 2000 touch_a1.threshold = 2000
touch_a2 = touchio.TouchIn(board.A2) touch_a2 = touchio.TouchIn(board.A2)
@ -39,9 +34,8 @@ touch_a3.threshold = 2000
touch_a4 = touchio.TouchIn(board.A4) touch_a4 = touchio.TouchIn(board.A4)
touch_a4.threshold = 2000 touch_a4.threshold = 2000
############################ # Keyboard & Mouse Setup
# Keyboard & Mouse Setup #
############################
# The keyboard object! # The keyboard object!
kbd = Keyboard() kbd = Keyboard()
# we're americans :) # we're americans :)
@ -49,25 +43,23 @@ layout = KeyboardLayoutUS(kbd)
# The mouse object! # The mouse object!
mouse = Mouse() mouse = Mouse()
####################### # Accelerometer Setup
# Accelerometer Setup #
#######################
# Initialize Accelerometer # Initialize Accelerometer
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=25) lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=25)
# Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G). # Set range of accelerometer
# (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G).
lis3dh.range = adafruit_lis3dh.RANGE_8_G lis3dh.range = adafruit_lis3dh.RANGE_8_G
########################### # Controller Functions
## Controller Functions ##
###########################
# A helper to 'remap' an input range to an output range # A helper to 'remap' an input range to an output range
def Map(x, in_min, in_max, out_min, out_max): def Map(x, in_min, in_max, out_min, out_max):
return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min) return int(
(x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
)
def Move(upDown_axis, isBackward): def Move(upDown_axis, isBackward):
@ -158,9 +150,7 @@ def readAxes():
return (x / 9.806, y / 9.806, z / 9.806) # 9.806 m/s^2 per G return (x / 9.806, y / 9.806, z / 9.806) # 9.806 m/s^2 per G
########################### # Main Function
## Main Function ##
###########################
while True: while True:
# Read accelerometer values (in G). Returns a 3-tuple of x, y, x axis # Read accelerometer values (in G). Returns a 3-tuple of x, y, x axis
pos_x, pos_y, pos_z = readAxes() pos_x, pos_y, pos_z = readAxes()
@ -184,11 +174,13 @@ while True:
Jump(pos_y) Jump(pos_y)
Give(pos_y, pos_x) Give(pos_y, pos_x)
# Small delay to keep things responsive but give time for interrupt processing. # Small delay to keep things responsive but
# give time for interrupt processing.
time.sleep(0.01) time.sleep(0.01)
## Debugging Ahead!! ## # Debugging Ahead!!
# Use the following 2 lines to figure out which axis is upDown, frontBack, or LeftRight # Use the following 2 lines to figure out which
# axis is upDown, frontBack, or LeftRight
# and also for debugging! # and also for debugging!
# print('x = {}G, y = {}G, z = {}G'.format(x, y, z)) # print('x = {}G, y = {}G, z = {}G'.format(x, y, z))
# time.sleep(0.3) # time.sleep(0.3)

View file

@ -61,7 +61,8 @@ draw.rectangle((0, 0, width, height), outline=0, fill=0)
padding = -2 padding = -2
top = padding top = padding
bottom = height - padding bottom = height - padding
# Move left to right keeping track of the current x position for drawing shapes. # Move left to right keeping track of the current x position
# for drawing shapes.
x = 0 x = 0
# Load nice silkscreen font # Load nice silkscreen font
@ -77,11 +78,14 @@ while True:
IP = subprocess.check_output(cmd, shell=True) IP = subprocess.check_output(cmd, shell=True)
cmd = "hostname" cmd = "hostname"
HOST = subprocess.check_output(cmd, shell=True) HOST = subprocess.check_output(cmd, shell=True)
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'" cmd = "top -bn1 | grep load | awk " \
"'{printf \"CPU Load: %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True) CPU = subprocess.check_output(cmd, shell=True)
cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'" cmd = "free -m | awk 'NR==2{printf " \
"\"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True) MemUsage = subprocess.check_output(cmd, shell=True)
cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3,$2,$5}'" cmd = "df -h | awk '$NF==\"/\"{printf " \
"\"Disk: %d/%dGB %s\", $3,$2,$5}'"
Disk = subprocess.check_output(cmd, shell=True) Disk = subprocess.check_output(cmd, shell=True)
# Pi Hole data! # Pi Hole data!