From c7086527c4127c929d840ec2434459fb42fb8be7 Mon Sep 17 00:00:00 2001 From: Craig Richardson Date: Mon, 14 May 2018 22:12:24 +0100 Subject: [PATCH] Fix PEP8 compliance --- .../CircuitPython_NeoPixel_RGBW.py | 4 +- CircuitPython_Essentials/PWM_Test_Script.py | 2 +- .../CircuitPython_NeoPixel_RGBW.py | 3 +- CircuitPython_Quick_Starts/PWM_Test_Script.py | 2 +- .../DataLogger.py | 6 ++- Giant_Mechanical_Keyboard/code.py | 14 +++--- Minecraft_Gesture_Controller/main.py | 46 ++++++++----------- Pi_Hole_Ad_Blocker/stats.py | 12 +++-- 8 files changed, 45 insertions(+), 44 deletions(-) diff --git a/CircuitPython_Essentials/CircuitPython_NeoPixel_RGBW.py b/CircuitPython_Essentials/CircuitPython_NeoPixel_RGBW.py index 8347e62f7..289efca21 100644 --- a/CircuitPython_Essentials/CircuitPython_NeoPixel_RGBW.py +++ b/CircuitPython_Essentials/CircuitPython_NeoPixel_RGBW.py @@ -1,6 +1,7 @@ # CircuitPython demo - NeoPixel RGBW import time + import board import neopixel @@ -8,7 +9,8 @@ pixel_pin = board.A1 num_pixels = 8 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): diff --git a/CircuitPython_Essentials/PWM_Test_Script.py b/CircuitPython_Essentials/PWM_Test_Script.py index 91cb90107..d1a9f47c6 100644 --- a/CircuitPython_Essentials/PWM_Test_Script.py +++ b/CircuitPython_Essentials/PWM_Test_Script.py @@ -9,5 +9,5 @@ for pin_name in dir(board): print("PWM on:", pin_name) # Prints the valid, PWM-capable pins! except ValueError: # This is the error returned when the pin is invalid. 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. diff --git a/CircuitPython_Quick_Starts/CircuitPython_NeoPixel_RGBW.py b/CircuitPython_Quick_Starts/CircuitPython_NeoPixel_RGBW.py index ad88e5ef9..289efca21 100644 --- a/CircuitPython_Quick_Starts/CircuitPython_NeoPixel_RGBW.py +++ b/CircuitPython_Quick_Starts/CircuitPython_NeoPixel_RGBW.py @@ -9,7 +9,8 @@ pixel_pin = board.A1 num_pixels = 8 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): diff --git a/CircuitPython_Quick_Starts/PWM_Test_Script.py b/CircuitPython_Quick_Starts/PWM_Test_Script.py index 91cb90107..d1a9f47c6 100644 --- a/CircuitPython_Quick_Starts/PWM_Test_Script.py +++ b/CircuitPython_Quick_Starts/PWM_Test_Script.py @@ -9,5 +9,5 @@ for pin_name in dir(board): print("PWM on:", pin_name) # Prints the valid, PWM-capable pins! except ValueError: # This is the error returned when the pin is invalid. 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. diff --git a/Data_Logging_with_Feather_and_CircuitPython/DataLogger.py b/Data_Logging_with_Feather_and_CircuitPython/DataLogger.py index 2d3bd5c7d..cb0ea5949 100644 --- a/Data_Logging_with_Feather_and_CircuitPython/DataLogger.py +++ b/Data_Logging_with_Feather_and_CircuitPython/DataLogger.py @@ -42,8 +42,10 @@ while True: print("Humidity:", humidity) print("VBat voltage: {:.2f}".format(battery_voltage)) print() - sdc.write("{}, {}, {}, {:.2f}\n".format(int(time_stamp), temperature, - humidity, battery_voltage)) + sdc.write("{}, {}, {}, {:.2f}\n".format( + int(time_stamp), temperature, + humidity, battery_voltage) + ) time.sleep(3) except OSError: pass diff --git a/Giant_Mechanical_Keyboard/code.py b/Giant_Mechanical_Keyboard/code.py index 5a9b89ec5..d09d5e8e8 100644 --- a/Giant_Mechanical_Keyboard/code.py +++ b/Giant_Mechanical_Keyboard/code.py @@ -59,16 +59,16 @@ print("Waiting for button presses") 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 - l.value = True # turn on LED + switch_led.value = True # turn on LED kbd.press(k) # send keycode 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 - l.value = False # turn on LED + switch_led.value = False # turn on LED kbd.release(k) # send keycode @@ -98,15 +98,15 @@ while True: # check each button for button in buttons: 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 # was button not pressed last time? - if buttonspressedlast[i] == False: + if buttonspressedlast[i] is False: print("Pressed #%d" % i) pressbutton(i) else: 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) releasebutton(i) lightneopixels() diff --git a/Minecraft_Gesture_Controller/main.py b/Minecraft_Gesture_Controller/main.py index 48b3832ab..2882d0099 100644 --- a/Minecraft_Gesture_Controller/main.py +++ b/Minecraft_Gesture_Controller/main.py @@ -1,4 +1,3 @@ -############################################### # Minecraft Gesture Controller # # Written by @@ -7,11 +6,9 @@ # Super awesome thanks to: # Richard Albritton, Tony DiCola, John Parker # All the awesome people who wrote the libraries -################################################ -########################## -## Libraries ## -########################## +# Libraries + import time @@ -27,9 +24,7 @@ from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.keycode import Keycode from adafruit_hid.mouse import Mouse -####################### -# CPX Setup # -####################### +# CPX Setup touch_a1 = touchio.TouchIn(board.A1) touch_a1.threshold = 2000 touch_a2 = touchio.TouchIn(board.A2) @@ -39,9 +34,8 @@ touch_a3.threshold = 2000 touch_a4 = touchio.TouchIn(board.A4) touch_a4.threshold = 2000 -############################ -# Keyboard & Mouse Setup # -############################ +# Keyboard & Mouse Setup + # The keyboard object! kbd = Keyboard() # we're americans :) @@ -49,25 +43,23 @@ layout = KeyboardLayoutUS(kbd) # The mouse object! mouse = Mouse() -####################### -# Accelerometer Setup # -####################### +# Accelerometer Setup + # Initialize Accelerometer i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) 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 -########################### -## Controller Functions ## -########################### +# Controller Functions # A helper to 'remap' an input range to an output range - - 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): @@ -158,9 +150,7 @@ def readAxes(): return (x / 9.806, y / 9.806, z / 9.806) # 9.806 m/s^2 per G -########################### -## Main Function ## -########################### +# Main Function while True: # Read accelerometer values (in G). Returns a 3-tuple of x, y, x axis pos_x, pos_y, pos_z = readAxes() @@ -184,11 +174,13 @@ while True: Jump(pos_y) 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) - ## Debugging Ahead!! ## - # Use the following 2 lines to figure out which axis is upDown, frontBack, or LeftRight + # Debugging Ahead!! + # Use the following 2 lines to figure out which + # axis is upDown, frontBack, or LeftRight # and also for debugging! # print('x = {}G, y = {}G, z = {}G'.format(x, y, z)) # time.sleep(0.3) diff --git a/Pi_Hole_Ad_Blocker/stats.py b/Pi_Hole_Ad_Blocker/stats.py index 2db7c4db0..9076bc2da 100644 --- a/Pi_Hole_Ad_Blocker/stats.py +++ b/Pi_Hole_Ad_Blocker/stats.py @@ -61,7 +61,8 @@ draw.rectangle((0, 0, width, height), outline=0, fill=0) padding = -2 top = 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 # Load nice silkscreen font @@ -77,11 +78,14 @@ while True: IP = subprocess.check_output(cmd, shell=True) cmd = "hostname" 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) - 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) - 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) # Pi Hole data!