-
Notifications
You must be signed in to change notification settings - Fork 2
Sourcery refactored main branch #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,12 @@ | |
| import ubinascii | ||
|
|
||
| def mac2eui(mac): | ||
| mac = mac[0:6] + 'fffe' + mac[6:] | ||
| return hex(int(mac[0:2], 16) ^ 2)[2:] + mac[2:] | ||
| mac = f'{mac[:6]}fffe{mac[6:]}' | ||
| return hex(int(mac[:2], 16) ^ 2)[2:] + mac[2:] | ||
|
|
||
| def get_millis(): | ||
| millisecond = time.ticks_ms() | ||
| return millisecond | ||
| return time.ticks_ms() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def get_nodename(): | ||
| uuid = ubinascii.hexlify(machine.unique_id()).decode() | ||
| node_name = "ESP_" + uuid | ||
| return node_name | ||
| return f"ESP_{uuid}" | ||
|
Comment on lines
-17
to
+16
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,6 @@ def receive(lora): | |
| print('something here') | ||
| payload = lora.read_payload() | ||
| print(payload) | ||
| screen[0] = "pkt: {}".format(payload) | ||
| screen[0] = f"pkt: {payload}" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| write_screen(oled, screen) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ def init_oled(): | |
| def write_screen(oled, screen): | ||
| oled.fill(0) | ||
| for row, text in enumerate(screen): | ||
| print("{} - {}".format(row, text)) | ||
| print(f"{row} - {text}") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| line = 12 * row | ||
| oled.text(text, 0, line, 1) | ||
| oled.show() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,14 +114,14 @@ def __init__(self, | |
| re_try = 0 | ||
| while init_try and re_try < 5: | ||
| version = self.read_register(REG_VERSION) | ||
| re_try = re_try + 1 | ||
| re_try += 1 | ||
| if version != 0: | ||
| init_try = False | ||
| #if version != 0x12: | ||
| # raise Exception('Invalid version.') | ||
|
|
||
| if __DEBUG__: | ||
| print("SX version: {}".format(version)) | ||
| print(f"SX version: {version}") | ||
|
Comment on lines
-117
to
+124
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # put in LoRa and sleep mode | ||
| self.sleep() | ||
|
|
@@ -252,7 +252,7 @@ def set_tx_power(self, level, outputPin = PA_OUTPUT_PA_BOOST_PIN): | |
| def set_frequency(self, frequency): | ||
| self._frequency = frequency | ||
|
|
||
| freq_reg = int(int(int(frequency) << 19) / 32000000) & 0xFFFFFF | ||
| freq_reg = int(int(frequency) << 19) // 32000000 & 0xFFFFFF | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| self.write_register(REG_FRF_MSB, (freq_reg & 0xFF0000) >> 16) | ||
| self.write_register(REG_FRF_MID, (freq_reg & 0xFF00) >> 8) | ||
|
|
@@ -268,13 +268,13 @@ def set_spreading_factor(self, sf): | |
| ) | ||
|
|
||
| def set_signal_bandwidth(self, sbw): | ||
| bins = (7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3, 41.7E3, 62.5E3, 125E3, 250E3) | ||
|
|
||
| bw = 9 | ||
|
|
||
| if sbw < 10: | ||
| bw = sbw | ||
| else: | ||
| bins = (7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3, 41.7E3, 62.5E3, 125E3, 250E3) | ||
|
|
||
|
Comment on lines
-271
to
+277
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for i in range(len(bins)): | ||
| if sbw <= bins[i]: | ||
| bw = i | ||
|
|
@@ -453,7 +453,7 @@ def read_payload(self): | |
| packet_length = self.read_register(REG_RX_NB_BYTES) | ||
|
|
||
| payload = bytearray() | ||
| for i in range(packet_length): | ||
| for _ in range(packet_length): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| payload.append(self.read_register(REG_FIFO)) | ||
|
|
||
| self.collect_garbage() | ||
|
|
@@ -480,7 +480,7 @@ def transfer(self, address, value = 0x00): | |
| return response | ||
|
|
||
| def blink_led(self, times = 1, on_seconds = 0.1, off_seconds = 0.1): | ||
| for i in range(times): | ||
| for _ in range(times): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if self._led_status: | ||
| self._led_status.value(True) | ||
| sleep(on_seconds) | ||
|
|
@@ -490,4 +490,4 @@ def blink_led(self, times = 1, on_seconds = 0.1, off_seconds = 0.1): | |
| def collect_garbage(self): | ||
| gc.collect() | ||
| if __DEBUG__: | ||
| print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc())) | ||
| print(f'[Memory - free: {gc.mem_free()} allocated: {gc.mem_alloc()}]') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
mac2euirefactored with the following changes:remove-redundant-slice-index)use-fstring-for-concatenation)