Skip to content

Commit

Permalink
fix: formatting (python)
Browse files Browse the repository at this point in the history
  • Loading branch information
StellaLupus committed Aug 10, 2024
1 parent 51975bb commit 5f84d59
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tools/serial_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import serial.tools.list_ports


def substring_after(str: str, search_str: str):
return str[str.index(search_str) + len(search_str):]


def get_port():
"""Allow user to select com port to connect device"""
ports = sorted(serial.tools.list_ports.comports())
print("Available ports to listing:")
for id, port_info in enumerate(ports):
Expand All @@ -26,10 +23,11 @@ def get_port():
zero = 756
one = 2149
space = 752
interv = 0.2
interv = 0.25


def get_bit_from_interv(value: int):
"""Returning zero or one from value or 2 if not recognized"""
if value > zero - zero * interv and value < zero + zero * interv:
return 0
elif value > one - one * interv and value < one + one * interv:
Expand All @@ -39,13 +37,15 @@ def get_bit_from_interv(value: int):


def bit_list_to_int(bit_list):
"""Convert list of bits to int"""
out = 0
for bit in bit_list:
out = (out << 1) | bit
return out


def main():
"""Main method"""
port = get_port()
print("Selected port:" + port.device)

Expand All @@ -54,12 +54,12 @@ def main():
baudrate=115200,
)

zero_sum = 0
zero_count = 0
one_sum = 0
one_cnt = 0
space_sum = 0
space_cnt = 0
ZERO_SUM = 0
ZERO_COUNT = 0
ONE_SUM = 0
ONE_CNT = 0
SPACE_SUM = 0
SPACE_CNT = 0

while True:
try:
Expand All @@ -77,15 +77,15 @@ def main():

for idd, d in enumerate(data):
if idd % 2 == 0:
space_sum += d
space_cnt += 1
SPACE_SUM += d
SPACE_CNT += 1
else:
if get_bit_from_interv(d) == 0:
zero_sum += d
zero_count += 1
ZERO_SUM += d
ZERO_COUNT += 1
elif get_bit_from_interv(d) == 1:
one_sum += d
one_cnt += 1
ONE_SUM += d
ONE_CNT += 1

print("Bit data = " + "".join([str(i) for i in bit_data]))
print("Clear bit data = " +
Expand Down

0 comments on commit 5f84d59

Please sign in to comment.