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

Remove numpy from deps & some fixes #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
69 changes: 22 additions & 47 deletions flipperzero_protobuf/cli_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import hashlib
from collections.abc import Iterator

import numpy

from .flipper_base import InputTypeException

__ALL__ = [
Expand All @@ -24,8 +22,8 @@ def print_hex(bytes_data) -> None:
print("".join(f"{x:02x} " for x in bytes_data))


_SCREEN_H = 128
_SCREEN_W = 64
_SCREEN_H = 64
doomwastaken marked this conversation as resolved.
Show resolved Hide resolved
_SCREEN_W = 128


def calc_file_md5(fname) -> str:
Expand All @@ -48,37 +46,32 @@ def calc_file_md5(fname) -> str:


def _write_screen(dat) -> None:
"""write image data to terminal screen"""
for y in range(0, _SCREEN_W, 2):
for x in range(1, _SCREEN_H + 1):
if int(dat[x][y]) == 1 and int(dat[x][y + 1]) == 1:
print("\u2588", end="")
if int(dat[x][y]) == 0 and int(dat[x][y + 1]) == 1:
print("\u2584", end="")
if int(dat[x][y]) == 1 and int(dat[x][y + 1]) == 0:
print("\u2580", end="")
if int(dat[x][y]) == 0 and int(dat[x][y + 1]) == 0:
print(" ", end="")
"""Print image to terminal"""
c = [" ", "▄", "▀", "█"]
for y in range(0, _SCREEN_H, 2):
for x in range(_SCREEN_W):
print(c[dat[y][x] * 2 + dat[y + 1][x]], end="")
print()


def _write_pbm_file(dat, dest) -> None:
"""write Black & White bitmap in simple Netpbm format"""
with open(dest, "w", encoding="utf-8") as fd:
print(f"P1\n{_SCREEN_H + 1} {_SCREEN_W}", file=fd)
for y in range(0, _SCREEN_W):
print(numpy.array2string(dat[:, y], max_line_width=300)[1:-1], file=fd)
print(f"P1\n{_SCREEN_W} {_SCREEN_H}", file=fd)
for y in range(_SCREEN_H):
print(" ".join([str(i) for i in dat[y]]), file=fd)


def _write_ppm_file(dat, dest) -> None:
"""write Orange and Black color RGB image stored in PPM format"""
with open(dest, "w", encoding="utf-8") as fd:
print(f"P3\n{_SCREEN_H + 1} {_SCREEN_W}\n255", file=fd)
for y in range(0, _SCREEN_W):
print(f"P3\n{_SCREEN_W} {_SCREEN_H}\n255", file=fd)
for y in range(_SCREEN_H):
print(
" ".join(
["255 165 000" if c == "1" else "000 000 000" for c in dat[:, y]]
)
["000 000 000" if c else "255 165 000" for c in dat[y]]
),
file=fd
)


Expand All @@ -87,7 +80,7 @@ def print_screen(screen_bytes, dest=None) -> None:

Parameters
----------
screen_bytes: numpy array
screen_bytes: list
dest : str
filename (optional)

Expand Down Expand Up @@ -120,7 +113,7 @@ def print_screen(screen_bytes, dest=None) -> None:
raise InputTypeException("invalid filename: {dest}")


def _dump_screen(screen_bytes) -> numpy.ndarray:
def _dump_screen(screen_bytes):
"""process` screendump data

Parameters
Expand All @@ -129,33 +122,15 @@ def _dump_screen(screen_bytes) -> numpy.ndarray:

Returns
-------
numpy array
list[y][x]

"""

# pylint: disable=multiple-statements

def get_bin(x) -> str:
return format(x, "08b")

scr = numpy.zeros((_SCREEN_H + 1, _SCREEN_W + 1), dtype=int)
data = screen_bytes

x = y = 0
basey = 0

for i in range(0, int(_SCREEN_H * _SCREEN_W / 8)):
tmp = get_bin(data[i])[::-1]

y = basey
x += 1
for c in tmp:
scr[x][y] = c
y += 1
scr = [[0] * _SCREEN_W for _ in range(_SCREEN_H)]

if (i + 1) % _SCREEN_H == 0:
basey += 8
x = 0
for i, b in enumerate(screen_bytes):
for j in range(8):
scr[i // _SCREEN_W * 8 + j][i % _SCREEN_W] = b >> j & 1

return scr

Expand Down
2 changes: 1 addition & 1 deletion flipperzero_protobuf/flipperCmd/flipperCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def do_print_screen(self, cmd, argv):
PRINT-SCREEN [filename.pbm]
"""
outf = None
if len(argv) == 0 or argv[0] == "?" or len(argv) > 1:
if (argv and argv[0] == "?") or len(argv) > 1:
raise cmdException(
f"Syntax:\n\t{cmd} [filename.pbm]\n"
"\tfile has to end in .pbm\n"
Expand Down
1 change: 0 additions & 1 deletion flipperzero_protobuf/flipper_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

# from nis import match
# from google.protobuf.internal.encoder import _VarintBytes
# from numpy import mat

# pylint: disable=line-too-long, no-member

Expand Down
1 change: 0 additions & 1 deletion flipperzero_protobuf/flipper_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# import pprint

# from nis import match
# from numpy import mat

# pylint: disable=line-too-long, no-member

Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ authors = [
description = "Python bindings for Flipper Zero protobuf protocol"

dependencies = [
"numpy==1.21.5",
"protobuf==4.21.3",
"pyserial",
#"protoletariat"
Expand All @@ -31,7 +30,6 @@ classifiers = [
"Operating System :: OS Independent",
"Requires-Dist: protoletariat",
"Requires-Dist: pyserial",
"Requires-Dist: numpy (>=3.21.5)",
"Requires-Dist: protobuf (>=3.12.4)",
]

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
numpy==1.22.3
protobuf==3.20.2
protoletariat
Pillow
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
# cmdclass = { 'install_scripts': install_scripts_and_symlinks }
install_requires=[
'pyreadline; platform_system == "Windows"',
"numpy==1.22.3",
"protobuf==3.20.2",
"pyserial",
],
Expand Down