Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting fixes #161

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modules/app_components/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def draw(self, ctx):

# Current menu item
ctx.font_size = self.item_font_size + animation_progress * (
self.focused_item_font_size_arr[self.position % num_menu_items if num_menu_items > 0 else 1] - self.item_font_size
self.focused_item_font_size_arr[
self.position % num_menu_items if num_menu_items > 0 else 1
]
- self.item_font_size
)

label = ""
Expand Down
4 changes: 2 additions & 2 deletions modules/firmware_apps/patterninhibit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from events.input import Buttons, BUTTON_TYPES
from system.eventbus import eventbus
from system.patterndisplay.events import *
from system.patterndisplay.events import PatternEnable, PatternDisable

from tildagonos import tildagonos

Expand All @@ -18,7 +18,7 @@ def __init__(self):
def _make_red(self):
asyncio.sleep(0.5)
for i in range(1, 13):
tildagonos.leds[i] = (int(i * (255/12)), 0, 0)
tildagonos.leds[i] = (int(i * (255 / 12)), 0, 0)
tildagonos.leds.write()

def update(self, delta):
Expand Down
26 changes: 14 additions & 12 deletions modules/fusb302b.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def get_status1a(self):
("RXSOP", 0),
("RXSOP1DB", 0),
("RXSOP2DB", 0),
("TOGSS", 0 ),
("TOGSS", 0),
]
)
status["RXSOP"] = (read & self.rx_sop.mask) >> self.ocp.position
Expand All @@ -444,8 +444,8 @@ def get_status1a(self):
status["RXSOP2DB"] = (
read & self.rx_sop_double_debug.mask
) >> self.rx_sop_double_debug.position
status["TOGSS"] = (
read & self.toggle_status.mask
status["TOGSS"] = (
read & self.toggle_status.mask
) >> self.toggle_status.position
return status

Expand All @@ -462,9 +462,9 @@ def get_interrupts(self):
Interruptb = self.i2c.readfrom_mem(
self.ADDRESS, self.good_crc_sent_int.register, 1
)[0]
Interrupt = self.i2c.readfrom_mem(
self.ADDRESS, self.bc_level_int.register, 1
)[0]
Interrupt = self.i2c.readfrom_mem(self.ADDRESS, self.bc_level_int.register, 1)[
0
]
Comment on lines +465 to +467
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the more generally accepted way of splitting this line

Suggested change
Interrupt = self.i2c.readfrom_mem(self.ADDRESS, self.bc_level_int.register, 1)[
0
]
Interrupt = self.i2c.readfrom_mem(
self.ADDRESS, self.bc_level_int.register, 1)[0]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, i tried this (and the ones above are more readable than the autogenerated one here imo) but ruff keeps reformatting it back to its preferred option - are we happy enough to leave this as is and just merge accepting it looks a little odd?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny. Sure feel free to merge

current_interrupts = dict(
[
("I_HARDRST", 0),
Expand All @@ -473,7 +473,7 @@ def get_interrupts(self):
("I_HARDSENT", 0),
("I_RETRYFAIL", 0),
("I_SOFTFAIL", 0),
("I_TOGDONE", 0 ),
("I_TOGDONE", 0),
("I_OCP_TEMP", 0),
("I_GCRCSENT", 0),
("I_BC_LVL", 0),
Expand Down Expand Up @@ -507,8 +507,8 @@ def get_interrupts(self):
current_interrupts["I_OCP_TEMP"] = (
Interrupta & self.ocp_temp_int.mask
) >> self.ocp_temp_int.position
current_interrupts['I_TOGDONE '] = (
Interrupta & self.toggle_done_int.mask
current_interrupts["I_TOGDONE "] = (
Interrupta & self.toggle_done_int.mask
) >> self.toggle_done_int.position
current_interrupts["I_GCRCSENT"] = (
Interruptb & self.good_crc_sent_int.mask
Expand Down Expand Up @@ -798,7 +798,7 @@ def parse_pdo(self, pdo):
limited,
)

def request_capability(self, msg_id = 0):
def request_capability(self, msg_id=0):
"""
ask for the power supply options
"""
Expand All @@ -809,7 +809,7 @@ def request_capability(self, msg_id = 0):
self.TX_SOP2,
self.TX_PACKSYM | 0x02,
0x47,
( 0x00 | ( ( msg_id & 0x07 ) << 1 ) ),
(0x00 | ((msg_id & 0x07) << 1)),
self.TX_JAM_CRC,
self.TX_EOP,
self.TX_OFF,
Expand All @@ -822,7 +822,9 @@ def soft_reset(self):
"""
reset the protocol layer on other port
"""
self.i2c.writeto_mem(self.ADDRESS, self.rxtx_fifo.register, bytes(self.TX_RESET1))
self.i2c.writeto_mem(
self.ADDRESS, self.rxtx_fifo.register, bytes(self.TX_RESET1)
)


if __name__ == "__main__":
Expand Down
16 changes: 13 additions & 3 deletions modules/lib/flash_spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@

_SEC_SIZE = const(4096) # Flash sector size 0x1000


# Logical Flash device comprising one or more physical chips sharing an SPI bus.
class FLASH(FlashDevice):
def __init__(
self, spi, cspins, size=None, verbose=True, sec_size=_SEC_SIZE, block_size=9, cmd5=None
self,
spi,
cspins,
size=None,
verbose=True,
sec_size=_SEC_SIZE,
block_size=9,
cmd5=None,
):
self._spi = spi
self._cspins = cspins
Expand All @@ -44,7 +52,7 @@ def __init__(
super().__init__(block_size, len(cspins), size * 1024, sec_size)

# Select the correct command set
if (cmd5 is None and size <= 4096) or (cmd5 == False):
if (cmd5 is None and size <= 4096) or (not cmd5):
self._cmds = _CMDS3BA
self._cmdlen = 4
else:
Expand All @@ -67,7 +75,9 @@ def scan(self, verbose, size):
if size is None:
size = scansize # Save size of 1st chip
if size != scansize: # Mismatch passed size or 1st chip.
raise ValueError(f"Flash size mismatch: expected {size}KiB, found {scansize}KiB")
raise ValueError(
f"Flash size mismatch: expected {size}KiB, found {scansize}KiB"
)
if not 0x10 < mvp[3] < 0x22:
raise ValueError(f"Invalid chip size {size}KiB. Specify size arg.")

Expand Down
16 changes: 8 additions & 8 deletions modules/lib/simple_tildagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import time


class led():

class led:
@staticmethod
def _setup_leds():
tildagonos.set_led_power(True)
Expand All @@ -24,8 +23,7 @@ def set(led_number, state):
tildagonos.leds.write()


class button():

class button:
@staticmethod
def get(button_letter):
button_letter = button_letter.lower()
Expand All @@ -41,11 +39,13 @@ def get(button_letter):
# Note the button must be flipped, as will return True when not pressed
return not tildagonos.check_egpio_state(button_letters[button_letter])
else:
raise ValueError("button_letter must be a string of a single letter from a to f")
raise ValueError(
"button_letter must be a string of a single letter from a to f"
)


class imu():
class ImuData():
class imu:
class ImuData:
def __init__(self, x, y, z):
self.x = x
self.y = y
Expand All @@ -66,7 +66,7 @@ def __str__(self):

@staticmethod
def _magnitude(acc_read):
return math.sqrt(sum(i ** 2 for i in acc_read))
return math.sqrt(sum(i**2 for i in acc_read))

@staticmethod
def is_tilted_forward():
Expand Down
8 changes: 4 additions & 4 deletions modules/patterns/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class BasePattern():
class BasePattern:
def __init__(self):
self._current_frame_id = 0
self.fps = 1
self.frames = [[(255,255,255)] * 12]
self.frames = [[(255, 255, 255)] * 12]

def next(self):
self._current_frame_id += 1
if self._current_frame_id == len(self.frames):
self._current_frame_id = 0
return(self.frames[self._current_frame_id])
return self.frames[self._current_frame_id]

def current(self):
return(self.frames[self._current_frame_id])
return self.frames[self._current_frame_id]
Loading
Loading