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

added poethepoet package to manage repetitive development tasks #304

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
dccfe92
added poethepoet package to manage repetitive development tasks
Dec 31, 2023
a148d1d
added more poe tasks for simulation on amigo and dock
Jan 4, 2024
a4ca983
added TODO listing task for checking TODOS in some files
Jan 4, 2024
01c3209
improved list-todos* tasks
Jan 4, 2024
5e53d09
added some TODOs to firmware scripts
Jan 5, 2024
28a6cf0
Added some lint and improved docstrings to src/krux/encryption_ui.py
Jan 5, 2024
895e62f
added some lint and improved docstrings on src/krux/pages/pub_key_vie…
Jan 5, 2024
8a02cfa
added lint, formatting and improved docstrings on src/krux/pages/qr_v…
Jan 5, 2024
4a2f3f0
added some lint to tests/conftest.py
Dec 31, 2023
f986ab1
added some black formating to tests/conftest.py
Dec 31, 2023
ce4c028
fixed some multiline pylint macro
Jan 5, 2024
5618d85
tests/shared_mocks.py formated and linted
Jan 2, 2024
94291f2
added some formatting and lint to tests/test_baseconv.py to better re…
Jan 2, 2024
a65142e
fix line-long lint on tests/test_baseconv.py after black formating th…
Jan 3, 2024
9419440
added black formatting and lints to test/test_camera.py
Jan 3, 2024
179c345
added some black formatting and lint to test/test_context.py
Jan 4, 2024
16cf12c
added black formatting and lint to tests/test_display.py
Jan 4, 2024
6336561
added docstrings and some lint to tests/test_encryption.py
Jan 6, 2024
82ad974
added some linting and docstrings to tests/test_firmware.py
Jan 7, 2024
7f6cc74
added a :param docstring to src/krux/format.py
Jan 7, 2024
11d173a
Merge branch 'integrated_changes' into integrated_changes
qlrd Jan 8, 2024
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
7 changes: 6 additions & 1 deletion firmware/scripts/krux_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@
import sys


# TODO: create typings for color param and return step
def rgb888torgb565(color):
"""convert to gggbbbbbrrrrrggg to tuple"""
"""
Convert to gggbbbbbrrrrrggg to tuple

:param color: tuple
"""
red, green, blue = color
red *= 31
red //= 255
Expand Down
5 changes: 5 additions & 0 deletions firmware/scripts/minify.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# TODO: what this script do?
"""
Some documentation about this script
Copy link
Contributor

Choose a reason for hiding this comment

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

It is self explanatory I think, it minifies the files passed as arguments. The output is the file minified (without extra new lines or code comments)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think i wanted more details how this is done (and projected it), sorry

"""
import ast
import sys
import astor
Expand Down
72 changes: 57 additions & 15 deletions firmware/scripts/rgbconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
Color conversions between 24-bit-rgb888 and 16-bit-rgb565
"""

from binascii import hexlify, unhexlify
from binascii import unhexlify


def rgb24_to_rgb16(rgb, big=False):
"""
convert 3 bytes of rgb888 into 2 bytes of rgb565
default to little-endian, so rgb565 becomes gbrg3553
convert 3 bytes of rgb888 into 2 bytes of rgb565
default to little-endian, so rgb565 becomes gbrg3553.

:param rgb: bytes
:param big: boolean flag to assert big or little-endian format
:returns int
"""

# TODO: this throw a pylint warn C0123: Use isinstance() rather than type() for a typecheck.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @qlrd These are just helpers (scripts) to serve as a tool to do something not direct related to the Krux code (like creating values to put those on code, or to help with the build process). These scripts will not ship into the Krux device... I think if you really want to change this, you could use isinstance() without any problems. We already use it a lot on the code, see for example the file wallet.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Put this because pylint was warning

# check if micropython support isinstance or typings
# pylint: disable=unidiomatic-typecheck
assert type(rgb) == bytes and len(rgb) == 3

# 5 significant bits of red shifted to far left
Expand All @@ -25,12 +34,25 @@ def rgb24_to_rgb16(rgb, big=False):

def rgb16_to_rgb24(rgb, big=False):
"""
convert 2 bytes of rgb565 into 3 bytes of rgb888
default from little-endian, so rgb565 becomes gbrg3553
Convert 2 bytes of rgb565 into 3 bytes of rgb888
default from little-endian, so rgb565 becomes gbrg3553.

:param rgb: bytes
:param big: boolean flag to assert big or little-endian format
:returns bytes in string format
"""
def maxv(number_of_bits):
return (2 ** number_of_bits) -1

def maxv(number_of_bits):
"""
Return 2^number_of_bits - 1

:returns int
"""
return (2**number_of_bits) - 1

# TODO: this throw a pylint warn C0123: Use isinstance() rather than type() for a typecheck.
Copy link
Contributor

Choose a reason for hiding this comment

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

plz see the comment above

# check if micropython support isinstance or typings
# pylint: disable=unidiomatic-typecheck
assert type(rgb) == bytes and len(rgb) == 2

rgb_int = int.from_bytes(rgb, "big" if big else "little")
Expand All @@ -44,20 +66,26 @@ def maxv(number_of_bits):
# right 5 bits of blue multiplied to fill 8 bit space
blue = round((rgb_int & maxv(5)) * maxv(8) / maxv(5))

return b''.join([x.to_bytes(1, "big") for x in [red, green, blue]])
return b"".join([x.to_bytes(1, "big") for x in [red, green, blue]])


def main(*args):
"""
Main function to convert integer in bytes format

:param *args: bytes in a 0x or integer format
:returns bytes: the byte representation of color
"""
rgb = None

if len(args) == 1:
arg = args[0]
if arg[:2] == "0x":
rgb = unhexlify(arg[2:])
else:
rgb = (abs(int(args[0])) % 65536).to_bytes(2, 'big')
rgb = (abs(int(args[0])) % 65536).to_bytes(2, "big")
else:
rgb = b''.join([(abs(int(x)) % 256).to_bytes(1, 'big') for x in args])
rgb = b"".join([(abs(int(x)) % 256).to_bytes(1, "big") for x in args])

if rgb:
if len(rgb) == 2:
Expand All @@ -67,21 +95,35 @@ def main(*args):
else:
answer = None

return(answer)
return answer


if __name__ == '__main__':
Copy link
Contributor

Choose a reason for hiding this comment

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

For those type of changes (from single quotes to double quotes), it is nice to read about it here. Basically I think we already uses single quotes for fixed small strings or constants, and double quotes to the other uses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was black autoformating 😵‍💫

if __name__ == "__main__":
import sys

def help():
# Do not name the function below `help`
# it can throw a pylint warning
# W0622: Redefining built-in 'help' (redefined-builtin)
def rgb_convert_help():
"""
Simple print help
"""
print("syntax: {} integer-bytes-or-0xhex-color".format(sys.argv[0]))

if len(sys.argv) > 1:
try:
print('0x' + main(*sys.argv[1:]).hex())
print("0x" + main(*sys.argv[1:]).hex())
except:
help()
rgb_convert_help()

# TODO: this throw a pylint warn R1722: Consider using 'sys.exit'instead
# check if if in micropython is better to call sys.exit
# pylint: disable=consider-using-sys-exit
exit(1)
else:
help()

# TODO: this throw a pylint warn R1722: Consider using 'sys.exit'instead
# check if if in micropython is better to call sys.exit
# pylint: disable=consider-using-sys-exit
exit(1)
Loading
Loading