Fix Flake8 issues
This commit is contained in:
parent
33a13cbb3b
commit
1cde6aa889
7 changed files with 41 additions and 33 deletions
|
|
@ -3,7 +3,7 @@ import time
|
|||
import digitalio
|
||||
from adafruit_hid.keyboard import Keyboard
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import ntptime
|
|||
import ubinascii
|
||||
import uhashlib
|
||||
|
||||
totp = [("Discord ", 'JBSWY3DPEHPK3PXP'), # https://github.com/pyotp/pyotp exmple
|
||||
# https://github.com/pyotp/pyotp example
|
||||
totp = [("Discord ", 'JBSWY3DPEHPK3PXP'),
|
||||
("Gmail ", 'abcdefghijklmnopqrstuvwxyz234567'),
|
||||
("Accounts", 'asfdkwefoaiwejfa323nfjkl')]
|
||||
ssid = 'my_wifi_ssid'
|
||||
|
|
@ -164,7 +165,7 @@ t = None
|
|||
while not t:
|
||||
try:
|
||||
t = ntptime.time()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(0.1)
|
||||
|
||||
|
|
@ -195,7 +196,7 @@ while ALWAYS_ON or (countdown > 0):
|
|||
print(name + " OTP output: ", otp) # serial debugging output
|
||||
oled.text(name + ": " + str(otp), 0, y) # display name & OTP 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.show()
|
||||
# We'll update every 1/4 second, we can hash very fast so its no biggie!
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ try:
|
|||
|
||||
except OSError as e:
|
||||
if e.args[0] == 28:
|
||||
halt("OS Error 28", 0.25)
|
||||
raise OSError("OS Error 28 0.25")
|
||||
else:
|
||||
halt("OS Error ", 0.5)
|
||||
raise OSError("OS Error 0.5")
|
||||
except BMPError as e:
|
||||
print("Failed to parse BMP: " + e.args[0])
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,8 @@ class DirectoryNode(object):
|
|||
|
||||
def __get_files(self):
|
||||
"""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."""
|
||||
if len(self.files) == 0:
|
||||
self.files = os.listdir(self.__path())
|
||||
|
|
@ -112,7 +113,9 @@ class DirectoryNode(object):
|
|||
if self.top_offset != self.old_top_offset:
|
||||
self.__get_files()
|
||||
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.show()
|
||||
self.old_top_offset = self.top_offset
|
||||
|
|
@ -121,10 +124,12 @@ class DirectoryNode(object):
|
|||
"""Update the selected file lighlight if required."""
|
||||
if self.selected_offset != self.old_selected_offset:
|
||||
if self.old_selected_offset > -1:
|
||||
self.display.text(
|
||||
">", 0, (self.old_selected_offset - self.top_offset) * 8, 0)
|
||||
self.display.text(
|
||||
">", 0, (self.selected_offset - self.top_offset) * 8, 1)
|
||||
old_offset = (self.old_selected_offset - self.top_offset) * 8
|
||||
|
||||
self.display.text(">", 0, old_offset, 0)
|
||||
|
||||
new_offset = (self.selected_offset - self.top_offset) * 8
|
||||
self.display.text(">", 0, new_offset, 1)
|
||||
self.display.show()
|
||||
self.old_selected_offset = self.selected_offset
|
||||
|
||||
|
|
@ -153,8 +158,8 @@ class DirectoryNode(object):
|
|||
self.__update_selection()
|
||||
|
||||
def down(self):
|
||||
"""Move down in the file list if possible, adjusting the selected file indicator
|
||||
and scrolling the display as required."""
|
||||
"""Move down in the file list if possible, adjusting the selected file
|
||||
indicator and scrolling the display as required."""
|
||||
if self.selected_offset < self.__number_of_files() - 1:
|
||||
self.selected_offset += 1
|
||||
if self.selected_offset == self.top_offset + 4:
|
||||
|
|
@ -174,7 +179,8 @@ class DirectoryNode(object):
|
|||
|
||||
def click(self):
|
||||
"""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 self.selected_filename == "..":
|
||||
if self.parent:
|
||||
|
|
|
|||
|
|
@ -68,6 +68,6 @@ while True:
|
|||
vlvl = remapRangeSafe(lvl, 0, 255, wheelStart, wheelEnd)
|
||||
for i in range(0, len(strip)):
|
||||
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.show()
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ def Move(upDown_axis, isBackward):
|
|||
# If you are touching A4, walk backwards, else walk forwards
|
||||
if isBackward:
|
||||
print("backwards") # Debugging
|
||||
if (axis_new > 1.2): # walk threshold
|
||||
if (axis_new > 2.5): # run threshold
|
||||
if axis_new > 1.2: # walk threshold
|
||||
if axis_new > 2.5: # run threshold
|
||||
kbd.press(Keycode.LEFT_CONTROL, Keycode.S)
|
||||
time.sleep(0.1)
|
||||
kbd.release_all()
|
||||
|
|
@ -85,8 +85,8 @@ def Move(upDown_axis, isBackward):
|
|||
time.sleep(0.1)
|
||||
kbd.release_all()
|
||||
else:
|
||||
if (axis_new > 1.2): # walk threshold
|
||||
if (axis_new > 2.5): # run threshold
|
||||
if axis_new > 1.2: # walk threshold
|
||||
if axis_new > 2.5: # run threshold
|
||||
kbd.press(Keycode.LEFT_CONTROL)
|
||||
time.sleep(0.1)
|
||||
kbd.release_all()
|
||||
|
|
@ -96,12 +96,12 @@ def Move(upDown_axis, isBackward):
|
|||
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
|
||||
upDown_adj = int(upDown_axis) # currently y_axis
|
||||
|
||||
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)
|
||||
else:
|
||||
upDown_new = 0
|
||||
|
|
@ -113,7 +113,7 @@ def Turn(upDown_axis, frontBack_axis, leftRight_axis, lookUp):
|
|||
|
||||
def Jump(upDown_axis):
|
||||
upDown = abs(upDown_axis)
|
||||
if (upDown > 3):
|
||||
if upDown > 3:
|
||||
kbd.press(Keycode.SPACE, Keycode.W)
|
||||
kbd.release_all()
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ def Jump(upDown_axis):
|
|||
def Give(upDown_axis, frontBack_axis):
|
||||
frontBack_new = abs(frontBack_axis)
|
||||
if abs(upDown_axis) < 1:
|
||||
if (frontBack_new > 2):
|
||||
if frontBack_new > 2:
|
||||
print("give")
|
||||
mouse.click(Mouse.RIGHT_BUTTON)
|
||||
mouse.release_all()
|
||||
|
|
@ -163,7 +163,7 @@ def readAxes():
|
|||
###########################
|
||||
while True:
|
||||
# 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
|
||||
if touch_a1.value:
|
||||
|
|
@ -175,14 +175,14 @@ while True:
|
|||
if touch_a3.value:
|
||||
ESC()
|
||||
|
||||
isBackward = touch_a4.value
|
||||
lookUp = touch_a4.value
|
||||
is_backward = touch_a4.value
|
||||
look_up = touch_a4.value
|
||||
|
||||
# Run through the motions! .. literally :)
|
||||
Move(y, isBackward)
|
||||
Turn(y, x, z, lookUp)
|
||||
Jump(y)
|
||||
Give(y, x)
|
||||
Move(pos_y, is_backward)
|
||||
Turn(pos_y, pos_z, look_up)
|
||||
Jump(pos_y)
|
||||
Give(pos_y, pos_x)
|
||||
|
||||
# Small delay to keep things responsive but give time for interrupt processing.
|
||||
time.sleep(0.01)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ while True:
|
|||
# Draw a black filled box to clear the image.
|
||||
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"
|
||||
IP = subprocess.check_output(cmd, shell=True)
|
||||
cmd = "hostname"
|
||||
|
|
@ -90,7 +91,7 @@ while True:
|
|||
DNSQUERIES = data['dns_queries_today']
|
||||
ADSBLOCKED = data['ads_blocked_today']
|
||||
CLIENTS = data['unique_clients']
|
||||
except:
|
||||
except KeyError:
|
||||
time.sleep(1)
|
||||
continue
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue