Fix Flake8 issues

This commit is contained in:
Craig Richardson 2018-05-14 21:37:40 +01:00
parent 33a13cbb3b
commit 1cde6aa889
7 changed files with 41 additions and 33 deletions

View file

@ -3,7 +3,7 @@ import time
import digitalio import digitalio
from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode from adafruit_hid.keycode import Keycode
from board import * from board import D12, D11, D10, D9, D6, D5, A0, A1, A2, A3, A4, A5
# A simple neat keyboard demo in circuitpython # A simple neat keyboard demo in circuitpython

View file

@ -8,7 +8,8 @@ import ntptime
import ubinascii import ubinascii
import uhashlib import uhashlib
totp = [("Discord ", 'JBSWY3DPEHPK3PXP'), # https://github.com/pyotp/pyotp exmple # https://github.com/pyotp/pyotp example
totp = [("Discord ", 'JBSWY3DPEHPK3PXP'),
("Gmail ", 'abcdefghijklmnopqrstuvwxyz234567'), ("Gmail ", 'abcdefghijklmnopqrstuvwxyz234567'),
("Accounts", 'asfdkwefoaiwejfa323nfjkl')] ("Accounts", 'asfdkwefoaiwejfa323nfjkl')]
ssid = 'my_wifi_ssid' ssid = 'my_wifi_ssid'
@ -164,7 +165,7 @@ t = None
while not t: while not t:
try: try:
t = ntptime.time() t = ntptime.time()
except: except Exception:
pass pass
time.sleep(0.1) time.sleep(0.1)
@ -195,7 +196,7 @@ while ALWAYS_ON or (countdown > 0):
print(name + " OTP output: ", otp) # serial debugging output print(name + " OTP output: ", otp) # serial debugging output
oled.text(name + ": " + str(otp), 0, y) # display name & OTP on OLED oled.text(name + ": " + str(otp), 0, y) # display name & OTP on OLED
y += 10 # Go to next line on OLED y += 10 # Go to next line on OLED
# We'll display a little bar that 'counts down' how many seconds you have left # Display a little bar that 'counts down' how many seconds you have left
oled.framebuf.line(0, 31, 128 - (unix_time % 30) * 4, 31, True) oled.framebuf.line(0, 31, 128 - (unix_time % 30) * 4, 31, True)
oled.show() oled.show()
# We'll update every 1/4 second, we can hash very fast so its no biggie! # We'll update every 1/4 second, we can hash very fast so its no biggie!

View file

@ -96,9 +96,9 @@ try:
except OSError as e: except OSError as e:
if e.args[0] == 28: if e.args[0] == 28:
halt("OS Error 28", 0.25) raise OSError("OS Error 28 0.25")
else: else:
halt("OS Error ", 0.5) raise OSError("OS Error 0.5")
except BMPError as e: except BMPError as e:
print("Failed to parse BMP: " + e.args[0]) print("Failed to parse BMP: " + e.args[0])

View file

@ -96,7 +96,8 @@ class DirectoryNode(object):
def __get_files(self): def __get_files(self):
"""Return a list of the files in this directory. """Return a list of the files in this directory.
If this is not the top directory on the SD card, a ".." entry is the first element. If this is not the top directory on the SD card, a
".." entry is the first element.
Any directories have a slash appended to their name.""" Any directories have a slash appended to their name."""
if len(self.files) == 0: if len(self.files) == 0:
self.files = os.listdir(self.__path()) self.files = os.listdir(self.__path())
@ -112,7 +113,9 @@ class DirectoryNode(object):
if self.top_offset != self.old_top_offset: if self.top_offset != self.old_top_offset:
self.__get_files() self.__get_files()
self.display.fill(0) self.display.fill(0)
for i in range(self.top_offset, min(self.top_offset + 4, self.__number_of_files())): min_offset = min(self.top_offset + 4, self.__number_of_files())
for i in range(self.top_offset, min_offset):
self.display.text(self.files[i], 10, (i - self.top_offset) * 8) self.display.text(self.files[i], 10, (i - self.top_offset) * 8)
self.display.show() self.display.show()
self.old_top_offset = self.top_offset self.old_top_offset = self.top_offset
@ -121,10 +124,12 @@ class DirectoryNode(object):
"""Update the selected file lighlight if required.""" """Update the selected file lighlight if required."""
if self.selected_offset != self.old_selected_offset: if self.selected_offset != self.old_selected_offset:
if self.old_selected_offset > -1: if self.old_selected_offset > -1:
self.display.text( old_offset = (self.old_selected_offset - self.top_offset) * 8
">", 0, (self.old_selected_offset - self.top_offset) * 8, 0)
self.display.text( self.display.text(">", 0, old_offset, 0)
">", 0, (self.selected_offset - self.top_offset) * 8, 1)
new_offset = (self.selected_offset - self.top_offset) * 8
self.display.text(">", 0, new_offset, 1)
self.display.show() self.display.show()
self.old_selected_offset = self.selected_offset self.old_selected_offset = self.selected_offset
@ -153,8 +158,8 @@ class DirectoryNode(object):
self.__update_selection() self.__update_selection()
def down(self): def down(self):
"""Move down in the file list if possible, adjusting the selected file indicator """Move down in the file list if possible, adjusting the selected file
and scrolling the display as required.""" indicator and scrolling the display as required."""
if self.selected_offset < self.__number_of_files() - 1: if self.selected_offset < self.__number_of_files() - 1:
self.selected_offset += 1 self.selected_offset += 1
if self.selected_offset == self.top_offset + 4: if self.selected_offset == self.top_offset + 4:
@ -174,7 +179,8 @@ class DirectoryNode(object):
def click(self): def click(self):
"""Handle a selection and return the new current directory. """Handle a selection and return the new current directory.
If the selected file is the parent, i.e. "..", return to the parent directory. If the selected file is the parent, i.e. "..", return to the parent
directory.
If the selected file is a directory, go into it.""" If the selected file is a directory, go into it."""
if self.selected_filename == "..": if self.selected_filename == "..":
if self.parent: if self.parent:

View file

@ -68,6 +68,6 @@ while True:
vlvl = remapRangeSafe(lvl, 0, 255, wheelStart, wheelEnd) vlvl = remapRangeSafe(lvl, 0, 255, wheelStart, wheelEnd)
for i in range(0, len(strip)): for i in range(0, len(strip)):
strip[i] = wheel(vlvl) strip[i] = wheel(vlvl)
# Set strip brightness based on audio level # Set strip brightness based oncode audio level
strip.brightness = float(remapRangeSafe(lvl, 50, 255, 0, maxbrt)) / 255.0 strip.brightness = float(remapRangeSafe(lvl, 50, 255, 0, maxbrt)) / 255.0
strip.show() strip.show()

View file

@ -75,8 +75,8 @@ def Move(upDown_axis, isBackward):
# If you are touching A4, walk backwards, else walk forwards # If you are touching A4, walk backwards, else walk forwards
if isBackward: if isBackward:
print("backwards") # Debugging print("backwards") # Debugging
if (axis_new > 1.2): # walk threshold if axis_new > 1.2: # walk threshold
if (axis_new > 2.5): # run threshold if axis_new > 2.5: # run threshold
kbd.press(Keycode.LEFT_CONTROL, Keycode.S) kbd.press(Keycode.LEFT_CONTROL, Keycode.S)
time.sleep(0.1) time.sleep(0.1)
kbd.release_all() kbd.release_all()
@ -85,8 +85,8 @@ def Move(upDown_axis, isBackward):
time.sleep(0.1) time.sleep(0.1)
kbd.release_all() kbd.release_all()
else: else:
if (axis_new > 1.2): # walk threshold if axis_new > 1.2: # walk threshold
if (axis_new > 2.5): # run threshold if axis_new > 2.5: # run threshold
kbd.press(Keycode.LEFT_CONTROL) kbd.press(Keycode.LEFT_CONTROL)
time.sleep(0.1) time.sleep(0.1)
kbd.release_all() kbd.release_all()
@ -96,12 +96,12 @@ def Move(upDown_axis, isBackward):
kbd.release_all() kbd.release_all()
def Turn(upDown_axis, frontBack_axis, leftRight_axis, lookUp): def Turn(upDown_axis, leftRight_axis, lookUp):
leftRight_adj = int(leftRight_axis) # currently z_axis leftRight_adj = int(leftRight_axis) # currently z_axis
upDown_adj = int(upDown_axis) # currently y_axis upDown_adj = int(upDown_axis) # currently y_axis
leftRight_new = Map(leftRight_adj, -3, 3, -100, 100) leftRight_new = Map(leftRight_adj, -3, 3, -100, 100)
if (lookUp and abs(upDown_adj) < 1.2): if lookUp and abs(upDown_adj) < 1.2:
upDown_new = Map(upDown_adj, -1, 1, -100, 100) upDown_new = Map(upDown_adj, -1, 1, -100, 100)
else: else:
upDown_new = 0 upDown_new = 0
@ -113,7 +113,7 @@ def Turn(upDown_axis, frontBack_axis, leftRight_axis, lookUp):
def Jump(upDown_axis): def Jump(upDown_axis):
upDown = abs(upDown_axis) upDown = abs(upDown_axis)
if (upDown > 3): if upDown > 3:
kbd.press(Keycode.SPACE, Keycode.W) kbd.press(Keycode.SPACE, Keycode.W)
kbd.release_all() kbd.release_all()
@ -121,7 +121,7 @@ def Jump(upDown_axis):
def Give(upDown_axis, frontBack_axis): def Give(upDown_axis, frontBack_axis):
frontBack_new = abs(frontBack_axis) frontBack_new = abs(frontBack_axis)
if abs(upDown_axis) < 1: if abs(upDown_axis) < 1:
if (frontBack_new > 2): if frontBack_new > 2:
print("give") print("give")
mouse.click(Mouse.RIGHT_BUTTON) mouse.click(Mouse.RIGHT_BUTTON)
mouse.release_all() mouse.release_all()
@ -163,7 +163,7 @@ def readAxes():
########################### ###########################
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
x, y, z = readAxes() pos_x, pos_y, pos_z = readAxes()
# Read finger pads and act accordingly # Read finger pads and act accordingly
if touch_a1.value: if touch_a1.value:
@ -175,14 +175,14 @@ while True:
if touch_a3.value: if touch_a3.value:
ESC() ESC()
isBackward = touch_a4.value is_backward = touch_a4.value
lookUp = touch_a4.value look_up = touch_a4.value
# Run through the motions! .. literally :) # Run through the motions! .. literally :)
Move(y, isBackward) Move(pos_y, is_backward)
Turn(y, x, z, lookUp) Turn(pos_y, pos_z, look_up)
Jump(y) Jump(pos_y)
Give(y, 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)

View file

@ -71,7 +71,8 @@ while True:
# Draw a black filled box to clear the image. # Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=0) draw.rectangle((0, 0, width, height), outline=0, fill=0)
# Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load # Shell scripts for system monitoring from here :
# https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
cmd = "hostname -I | cut -d\' \' -f1" cmd = "hostname -I | cut -d\' \' -f1"
IP = subprocess.check_output(cmd, shell=True) IP = subprocess.check_output(cmd, shell=True)
cmd = "hostname" cmd = "hostname"
@ -90,7 +91,7 @@ while True:
DNSQUERIES = data['dns_queries_today'] DNSQUERIES = data['dns_queries_today']
ADSBLOCKED = data['ads_blocked_today'] ADSBLOCKED = data['ads_blocked_today']
CLIENTS = data['unique_clients'] CLIENTS = data['unique_clients']
except: except KeyError:
time.sleep(1) time.sleep(1)
continue continue