Skip to content

Commit 09001ee

Browse files
committed
style: code format
Signed-off-by: lbuque <[email protected]>
1 parent 13558f3 commit 09001ee

File tree

11 files changed

+122
-90
lines changed

11 files changed

+122
-90
lines changed

m5stack/libs/driver/mfrc522/__init__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def picc_select(self, uid, validBits=0):
521521
rxAlign=rxAlign,
522522
)
523523
if responseBuffer1:
524-
responseBuffer[0:len(responseBuffer1)] = responseBuffer1
524+
responseBuffer[0 : len(responseBuffer1)] = responseBuffer1
525525

526526
if status == self.STATUS_COLLISION:
527527
# More than one PICC in the field => collision.
@@ -735,7 +735,12 @@ def mifare_get_value(self, blockAddr):
735735
status = self.mifare_read(blockAddr, self._BUFFER18)
736736
if status == self.STATUS_OK:
737737
# Extract the value
738-
value = (self._BUFFER18[3] << 24) | (self._BUFFER18[2] << 16) | (self._BUFFER18[1] << 8) | (self._BUFFER18[0])
738+
value = (
739+
(self._BUFFER18[3] << 24)
740+
| (self._BUFFER18[2] << 16)
741+
| (self._BUFFER18[1] << 8)
742+
| (self._BUFFER18[0])
743+
)
739744
return status, value
740745

741746
def mifare_set_value(self, blockAddr, value):
@@ -773,7 +778,9 @@ def pcd_mifare_transceive(self, sendData, acceptTimeout=False):
773778
cmdBuffer = sendData + self._CRC_BUFFER
774779

775780
# Transceive the data, store the reply in cmdBuffer[]
776-
status, rspBuffer, validBits = self.pcd_communicate_with_picc(PCD_TRANSCEIVE, 0x30, cmdBuffer, validBits=0)
781+
status, rspBuffer, validBits = self.pcd_communicate_with_picc(
782+
PCD_TRANSCEIVE, 0x30, cmdBuffer, validBits=0
783+
)
777784
# print("pcd_communicate_with_picc() status:", status)
778785
if acceptTimeout and status == self.STATUS_TIMEOUT:
779786
return self.STATUS_OK
@@ -1049,7 +1056,7 @@ def mifare_open_uid_backdoor(self, logErrors=False) -> bool:
10491056
bytearray([0x40]), validBits=validBits
10501057
)
10511058
if response1:
1052-
response[:len(response1)] = response1
1059+
response[: len(response1)] = response1
10531060
if status != self.STATUS_OK:
10541061
logErrors and print(
10551062
"Card did not respond to 0x40 after HALT command. Are you sure it is a UID changeable one?"
@@ -1069,7 +1076,7 @@ def mifare_open_uid_backdoor(self, logErrors=False) -> bool:
10691076
bytearray([0x43]), validBits=validBits, rxAlign=0, rxAlign=False
10701077
)
10711078
if response1:
1072-
response[:len(response1)] = response1
1079+
response[: len(response1)] = response1
10731080
if status != self.STATUS_OK:
10741081
logErrors and print(
10751082
"Error in communication at command 0x43, after successfully executing 0x40"
@@ -1110,7 +1117,9 @@ def mifare_set_uid(self, newUid, logErrors=False) -> bool:
11101117
)
11111118
return False
11121119
else:
1113-
logErrors and print("PCD_Authenticate() failed:", self.get_status_code_name(status))
1120+
logErrors and print(
1121+
"PCD_Authenticate() failed:", self.get_status_code_name(status)
1122+
)
11141123

11151124
# Read block 0
11161125
block0_buffer = bytearray(18)

m5stack/libs/driver/mfrc522/cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
# Commands sent to the PICC.
3636
# The commands used by the PCD to manage communication with several PICCs (ISO 14443-3, Type A, section 6.4)
3737

38-
# REQuest command, Type A.
38+
# REQuest command, Type A.
3939
# Invites PICCs in state IDLE to go to READY and prepare for anticollision or
4040
# selection. 7 bit frame.
4141
PICC_CMD_REQA = const(0x26)
4242

43-
# Wake-UP command, Type A.
44-
# Invites PICCs in state IDLE and HALT to go to READY(*) and prepare for
43+
# Wake-UP command, Type A.
44+
# Invites PICCs in state IDLE and HALT to go to READY(*) and prepare for
4545
# anticollision or selection. 7 bit frame.
4646
PICC_CMD_WUPA = const(0x52)
4747

m5stack/libs/hardware/rfid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from machine import I2C, Pin
22
from unit import RFIDUnit
33

4+
45
class RFID(RFIDUnit):
56
def __init__(self) -> None:
67
in_i2c = I2C(1, scl=Pin(12), sda=Pin(11))

m5stack/libs/unit/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141
"SCALESUnit": "scales",
4242
}
4343

44+
4445
def __getattr__(attr):
4546
mod = _attrs.get(attr, None)
4647
if mod is None:
4748
raise AttributeError(attr)
4849
value = getattr(__import__(mod, None, None, True, 1), attr)
4950
globals()[attr] = value
50-
return value
51+
return value

m5stack/libs/unit/limit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
SWITCH = 1
55
COUNTER = 2
66

7+
78
class LIMITUnit(Button):
89
def __init__(self, port, active_low=True, type=SWITCH):
910
self.count_value = 0
@@ -18,7 +19,7 @@ def _cb_irq(self, arg):
1819
self.curr_status = self.pin.value()
1920
if self.curr_status != self.prev_status:
2021
self.count_value += 1
21-
self.prev_status = self.curr_status
22+
self.prev_status = self.curr_status
2223

2324
def count_reset(self):
24-
self.count_value = 0
25+
self.count_value = 0

m5stack/libs/unit/lora_e220_jp.py

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
# -*- encoding: utf-8 -*-
2-
'''
2+
"""
33
@File : _imu_pro.py
44
@Time : 2023/11/06 xx:xx:xx
55
@Author : TONG YIHAN
66
77
@License : (C)Copyright 2015-2023, M5STACK
88
@Desc : The LoRaE220 Unit is a LoRa communication module, designed for the 920MHz frequency band.
9-
'''
9+
"""
1010
# UART: ['any', 'read', 'readinto', 'readline', 'write', 'INV_CTS', 'INV_RTS', 'INV_RX', 'INV_TX', 'deinit', 'init', 'sendbreak']
1111
import machine
1212
import time
1313
import _thread
1414

15+
1516
class Def:
1617
# Baud Rate Values
17-
BAUD_1200 = 0b000
18-
BAUD_2400 = 0b001
19-
BAUD_4800 = 0b010
20-
BAUD_9600 = 0b011
21-
BAUD_19200 = 0b100
22-
BAUD_38400 = 0b101
23-
BAUD_57600 = 0b110
18+
BAUD_1200 = 0b000
19+
BAUD_2400 = 0b001
20+
BAUD_4800 = 0b010
21+
BAUD_9600 = 0b011
22+
BAUD_19200 = 0b100
23+
BAUD_38400 = 0b101
24+
BAUD_57600 = 0b110
2425
BAUD_115200 = 0b111
2526

2627
# Data Rate Values
@@ -76,8 +77,9 @@ class Def:
7677
WOR_1500MS = 0b010
7778
WOR_2000MS = 0b011
7879

80+
7981
class LoRaE220JPUnit:
80-
def __init__(self, port, port_id = 1) -> None:
82+
def __init__(self, port, port_id=1) -> None:
8183
# print('Port: ', port)
8284
self.uart = machine.UART(port_id, tx=port[1], rx=port[0])
8385
self.uart.init(9600, bits=0, parity=None, stop=1, rxbuf=1024)
@@ -86,11 +88,24 @@ def __init__(self, port, port_id = 1) -> None:
8688

8789
def _conf_range(self, target, min, max):
8890
return min <= target <= max
89-
90-
def setup(self, own_address = 0, own_channel = 0, encryption_key = 0x2333, air_data_rate = Def.BW125K_SF9, subpacket_size = Def.SUBPACKET_200_BYTE, rssi_ambient_noise_flag = Def.RSSI_AMBIENT_NOISE_ENABLE, transmitting_power = Def.TX_POWER_13dBm,rssi_byte_flag = Def.RSSI_BYTE_ENABLE, transmission_method_type = Def.UART_P2P_MODE, lbt_flag = Def.LBT_DISABLE, wor_cycle = Def.WOR_2000MS):
91+
92+
def setup(
93+
self,
94+
own_address=0,
95+
own_channel=0,
96+
encryption_key=0x2333,
97+
air_data_rate=Def.BW125K_SF9,
98+
subpacket_size=Def.SUBPACKET_200_BYTE,
99+
rssi_ambient_noise_flag=Def.RSSI_AMBIENT_NOISE_ENABLE,
100+
transmitting_power=Def.TX_POWER_13dBm,
101+
rssi_byte_flag=Def.RSSI_BYTE_ENABLE,
102+
transmission_method_type=Def.UART_P2P_MODE,
103+
lbt_flag=Def.LBT_DISABLE,
104+
wor_cycle=Def.WOR_2000MS,
105+
):
91106
if not self._conf_range(own_channel, 0, 30):
92107
return False
93-
108+
94109
self.subpacket_size = subpacket_size
95110
self.max_len = 0
96111
if self.subpacket_size == Def.SUBPACKET_128_BYTE:
@@ -102,9 +117,9 @@ def setup(self, own_address = 0, own_channel = 0, encryption_key = 0x2333, air_d
102117
else:
103118
self.max_len = 200
104119

105-
command = [0xc0, 0x00, 0x08]
120+
command = [0xC0, 0x00, 0x08]
106121
ADDH = own_address >> 8
107-
ADDL = own_address & 0xff
122+
ADDL = own_address & 0xFF
108123
command.extend([ADDH, ADDL])
109124

110125
REG0 = (Def.BAUD_9600 << 5) | air_data_rate
@@ -115,26 +130,30 @@ def setup(self, own_address = 0, own_channel = 0, encryption_key = 0x2333, air_d
115130

116131
command.append(own_channel)
117132

118-
REG3 = (rssi_byte_flag << 7) | (transmission_method_type << 6) | (lbt_flag << 4) | wor_cycle
133+
REG3 = (
134+
(rssi_byte_flag << 7) | (transmission_method_type << 6) | (lbt_flag << 4) | wor_cycle
135+
)
119136
command.append(REG3)
120137

121138
CRYPT_H = encryption_key >> 8
122-
CRYPT_L = encryption_key & 0xff
139+
CRYPT_L = encryption_key & 0xFF
123140
command.extend([CRYPT_H, CRYPT_L])
124141

125142
self.uart.write(bytes(command))
126-
127-
time.sleep_ms(100) # wait for response
143+
144+
time.sleep_ms(100) # wait for response
128145

129146
response = []
130147
if self.uart.any():
131148
response = self.uart.read()
132149

133150
if len(response) != len(command):
134-
print("[WARN] Setup LoRa unit failed, please check connection and wether unit in configuration mode.")
151+
print(
152+
"[WARN] Setup LoRa unit failed, please check connection and wether unit in configuration mode."
153+
)
135154
return False
136155
return True
137-
156+
138157
def _recvCallback(self):
139158
response = bytes()
140159
rssi = 0
@@ -149,7 +168,7 @@ def _recvCallback(self):
149168
self.receive_callback(response[:-1], rssi)
150169
response = bytes()
151170
time.sleep_ms(10)
152-
171+
153172
def receiveNoneBlock(self, receive_callback):
154173
if not self.recv_running:
155174
self.recv_running = True
@@ -160,9 +179,9 @@ def stopReceive(self):
160179
self.recv_running = False
161180
time.sleep_ms(50)
162181
self.receive_callback = None
163-
164-
def receive(self, timeout = 1000):
165-
start = time.ticks_ms()
182+
183+
def receive(self, timeout=1000):
184+
start = time.ticks_ms()
166185
response = bytes()
167186
rssi = 0
168187
while True:
@@ -179,24 +198,24 @@ def receive(self, timeout = 1000):
179198
break
180199
time.sleep_ms(10)
181200
return response[:-1], rssi
182-
201+
183202
def send(self, target_address, target_channel, send_data):
184203
if type(send_data) is str:
185-
send_data = send_data.encode('utf-8')
204+
send_data = send_data.encode("utf-8")
186205

187206
if type(send_data) is list:
188207
send_data = bytearray(send_data)
189-
208+
190209
if len(send_data) > self.max_len: # Adjust based on allowed packet size
191-
print('ERROR: Length of send_data over %d bytes.' %self.max_len)
210+
print("ERROR: Length of send_data over %d bytes." % self.max_len)
192211
return False
193212

194213
target_address_H = target_address >> 8
195-
target_address_L = target_address & 0xff
214+
target_address_L = target_address & 0xFF
196215

197216
frame = bytearray([target_address_H, target_address_L, target_channel])
198217
frame.extend(send_data)
199218

200219
self.uart.write(frame)
201220

202-
return True
221+
return True

m5stack/libs/unit/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# "can.py",
3838
"limit.py",
3939
"op.py",
40-
'lora_e220_jp.py',
40+
"lora_e220_jp.py",
4141
"rfid.py",
4242
"weight.py",
4343
"scales.py",

m5stack/libs/unit/op.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
SWITCH = 1
55
COUNTER = 2
66

7+
78
class OPUnit(Button):
89
def __init__(self, port, active_low=True, type=SWITCH):
910
self.count_value = 0
@@ -18,7 +19,7 @@ def _cb_irq(self, arg):
1819
self.curr_status = self.pin.value()
1920
if self.curr_status != self.prev_status:
2021
self.count_value += 1
21-
self.prev_status = self.curr_status
22+
self.prev_status = self.curr_status
2223

2324
def count_reset(self):
2425
self.count_value = 0

m5stack/libs/unit/rfid.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from driver.mfrc522 import MFRC522
22

3+
34
class RFIDUnit(MFRC522):
45
def __init__(self, i2c, addr=0x28) -> None:
56
super().__init__(i2c, addr)
@@ -19,15 +20,15 @@ def read_card_uid(self):
1920

2021
def read(self, block_addr):
2122
buffer = bytearray(16)
22-
self.pcd_authenticate(0x60, block_addr, bytearray(b'\xFF\xFF\xFF\xFF\xFF\xFF'), self._uid)
23+
self.pcd_authenticate(0x60, block_addr, bytearray(b"\xFF\xFF\xFF\xFF\xFF\xFF"), self._uid)
2324
if self.mifare_read(block_addr, buffer) == self.STATUS_OK:
2425
return buffer
2526
else:
2627
return None
2728

2829
def write(self, block_addr, buffer) -> int:
2930
BUFFER16 = bytearray(16)
30-
self.pcd_authenticate(0x60, block_addr, bytearray(b'\xFF\xFF\xFF\xFF\xFF\xFF'), self._uid)
31+
self.pcd_authenticate(0x60, block_addr, bytearray(b"\xFF\xFF\xFF\xFF\xFF\xFF"), self._uid)
3132
self.mifare_read(block_addr, BUFFER16)
3233
l = 16 if len(buffer) > 16 else len(buffer)
3334
BUFFER16[:l] = buffer[:l]
@@ -48,4 +49,4 @@ def wakeup_all(self) -> bool:
4849
return self.picc_wakeup_a(bufferATQA) == self.STATUS_OK
4950

5051
def picc_select_card(self) -> bool:
51-
return self.picc_select(self._uid) == self.STATUS_OK
52+
return self.picc_select(self._uid) == self.STATUS_OK

0 commit comments

Comments
 (0)