Skip to content

Commit 19d95c0

Browse files
authored
Merge pull request #113 from SummerGGift/723
【完善】MicroPython 自动补全优化
2 parents 8809ebf + 244cdad commit 19d95c0

File tree

11 files changed

+130
-98
lines changed

11 files changed

+130
-98
lines changed

docs/code-completion/array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self) -> None:
2020
"""
2121
...
2222

23-
def append(val) -> None:
23+
def append(self, val) -> None:
2424
"""
2525
将一个新元素追加到数组的末尾。
2626
示例:
@@ -34,7 +34,7 @@ def append(val) -> None:
3434
"""
3535
...
3636

37-
def extend(iterable) -> None:
37+
def extend(self, iterable) -> None:
3838
"""
3939
将一个新的数组追加到数组的末尾,注意追加的数组和原来数组的数据类型要保持一致。
4040
示例:

docs/code-completion/machine.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class Pin(object):
7878
LOW_POWER = ... # type: int
7979
MED_POWER = ... # type: int
8080
HIGH_POWER = ... # type: int
81+
OUT_PP = ... # type: int
82+
OUT_OD = ... # type: int
8183

8284
def __init__(self, id: Any, mode: int = -1, pull: int = -1, *,
8385
value: Optional[int] = None,
@@ -157,7 +159,7 @@ def init(self, value: int, drive: int, alt: int, mode: int = -1, pull: int = -1)
157159
"""
158160
...
159161

160-
def value(self, x: Optional[int]) -> Optional[int]:
162+
def value(self, x: Optional[int] = None) -> Optional[int]:
161163
"""This method allows to set and get the value of the pin, depending on
162164
whether the argument **x** is supplied or not.
163165
@@ -343,7 +345,7 @@ def any(self) -> int:
343345
"""
344346
...
345347

346-
def read(self, nbytes: Optional[int]) -> bytes:
348+
def read(self, nbytes: Optional[int] = None) -> bytes:
347349
"""Read characters. If ``nbytes`` is specified then read at most that many
348350
bytes, otherwise read as much data as possible.
349351
@@ -390,7 +392,9 @@ class SPI(object):
390392
LSB = ... # type: int
391393
MSB = ... # type: int
392394

393-
def __init__(self, id: int) -> None:
395+
def __init__(self, id: int, baudrate: int = 1000000, polarity: int = 0, phase: int = 0,
396+
bits: int = 8, firstbit: int = MSB, sck: Optional[Pin] = None,
397+
mosi: Optional[Pin] = None, miso: Optional[Pin] = None) -> None:
394398
"""
395399
Construct an SPI object on the given bus, ``id``. Values of id depend
396400
on a particular port and its hardware. Values 0, 1, etc. are commonly
@@ -463,7 +467,7 @@ def write_readinto(self, write_buf: bytearray, read_buf: bytearray) -> None:
463467

464468

465469
class I2C(object):
466-
def __init__(self, id: int, *, scl: Pin, sda: Pin, freq: int = 400000) -> None:
470+
def __init__(self, id: int, scl: Pin = None, sda: Pin = None, freq: int = 400000) -> None:
467471
"""Construct and return a new I2C object.
468472
469473
:param id: Particular I2C peripheral (-1 for software implementation).
@@ -580,7 +584,7 @@ def readfrom_mem_into(self, addr: int, memaddr: int, buf, *, addrsize=8) -> None
580584
"""
581585
...
582586

583-
def writeto_mem(self, addr: int, memaddr: int, *, addrsize=8) -> None:
587+
def writeto_mem(self, addr: int, memaddr: int, addrsize=8) -> None:
584588
"""Write ``buf`` to the slave specified by ``addr`` starting from the
585589
memory address specified by ``memaddr``. The argument ``addrsize`` specifies
586590
the address size in bits (on ESP8266 this argument is not recognised
@@ -676,7 +680,7 @@ def __init__(self, id: int) -> None:
676680
:param id: Timer ID.
677681
"""
678682

679-
def init(mode : Timer.PERIODIC, period : int, callback : func) -> None:
683+
def init(self, mode : Timer.PERIODIC, period : int, callback : func) -> None:
680684
"""
681685
Init the timer. Start the timer, and enable the timer peripheral.
682686
"""
@@ -699,7 +703,7 @@ def __init__(self, id: int, channel: int) -> None:
699703
"""
700704
"""
701705

702-
def init(channel) -> None:
706+
def init(self, channel : int) -> None:
703707
"""
704708
根据输入的层参数初始化 ADC 对象,入参为使用的 ADC 对象通道号;
705709
"""
@@ -711,7 +715,7 @@ def deinit(self) -> None:
711715
"""
712716
...
713717

714-
def read() -> None:
718+
def read(self) -> None:
715719
"""
716720
用于获取并返回当前 ADC 对象的采样值。例如当前采样值为 2048,对应设备的分辨率为 12位,当前设备参考电压为 3.3V ,则该 ADC 对象通道上实际电压值的计算公式为:采样值 * 参考电压 / (1 << 分辨率位数),即 vol = 2048 / 4096 * 3.3 V = 1.15V。
717721
"""
@@ -733,7 +737,7 @@ def __init__(self, id: int, channel: int, freq: int, duty: int) -> None:
733737
"""
734738
"""
735739

736-
def init(channel, freq, duty) -> None:
740+
def init(self, channel : int, freq : int, duty : int) -> None:
737741
"""
738742
根据输入的参数初始化 PWM 对象。
739743
"""
@@ -745,13 +749,13 @@ def deinit(self) -> None:
745749
"""
746750
...
747751

748-
def freq(freq)-> None:
752+
def freq(self, freq : int = None)-> None:
749753
"""
750754
用于获取或者设置 PWM 对象的频率,频率的范围为 [1, 156250]。如果参数为空,返回当前 PWM 对象的频率;如果参数非空,则使用该参数设置当前 PWM 对象的频率。
751755
"""
752756
...
753757

754-
def duty(duty) -> None:
758+
def duty(self, duty : int = None) -> None:
755759
"""
756760
用于获取或者设置 PWM 对象的占空比数值,占空比数值的范围为 [0, 255],例如 duty = 100,表示当前设备占空比为 100/255 = 39.22% 。如果参数为空,返回当前 PWM 对象的占空比数值;如果参数非空,则使用该参数设置当前 PWM 对象的占空比数值。
757761
"""
@@ -784,46 +788,53 @@ def __init__(self) -> None:
784788
"""
785789
"""
786790

787-
def light(value) -> None:
791+
def light(self, value : int) -> None:
788792
"""
789793
控制是否开启 LCD 背光,入参为 True 则打开 LCD 背光,入参为 False 则关闭 LCD 背光。
790794
"""
791795
...
792796

793-
def fill(color) -> None:
797+
def fill(self, color : int) -> None:
794798
"""
795799
根据给定的颜色填充整个屏幕,支持多种颜色,可以传入的参数有:
796800
797801
- WHITE BLACK BLUE BRED GRED GBLUE RED MAGENTA GREEN CYAN YELLOW BROWN BRRED GRAY GRAY175 GRAY151 GRAY240
798802
"""
799803
...
800804

801-
def pixel(x, y, color) -> None:
805+
def pixel(self, x : int, y : int , color : int) -> None:
802806
"""
803807
向指定的位置(x, y)画点,点的颜色为 color 指定的颜色,可指定的颜色和上一个功能相同。
804808
注意:(x, y) 坐标的范围是 0 - 239,使用下面的方法对坐标进行操作时同样需要遵循此限制。
805809
"""
806810
...
807811

808-
def text(str, x, y, size) -> None:
812+
def set_color(self, back_color : int, fore_color : int) -> None:
813+
"""
814+
设置 LCD 屏幕的前景色和背景色。
815+
"""
816+
...
817+
818+
819+
def text(self, input_str : str, x : int, y : int, size : int) -> None:
809820
"""
810821
在指定的位置(x,y)写入字符串,字符串由 str 指定,字体的大小由 size 指定,size 的大小可为 16,24,32。
811822
"""
812823
...
813824

814-
def line(x1, y1, x2, y2) -> None:
825+
def line(self, x1 : int, y1 : int, x2 : int, y2 : int) -> None:
815826
"""
816827
在 LCD 上画一条直线,起始地址为 (x1, y1),终点为(x2, y2)。
817828
"""
818829
...
819830

820-
def rectangle(x1, y1, x2, y2) -> None:
831+
def rectangle(self, x1 : int, y1 : int, x2 : int, y2 : int) -> None:
821832
"""
822833
在 LCD 上画一个矩形,左上角的位置为(x1, y1),右下角的位置为(x2, y2)。
823834
"""
824835
...
825836

826-
def circle(x1, y1, r) -> None:
837+
def circle(self, x1 : int, y1 : int, r : int) -> None:
827838
"""
828839
在 LCD 上画一个圆形,圆心的位置为(x1, y1),半径长度为 r。。
829840
"""
@@ -832,7 +843,7 @@ def circle(x1, y1, r) -> None:
832843

833844
class WDT(object):
834845

835-
def __init__(self) -> None:
846+
def __init__(self, timeout : int) -> None:
836847
"""
837848
Construct a new watchdog object.
838849
"""

docs/code-completion/network.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,34 @@ class WLAN(object):
2020
STAT_CONNECT_FAIL = ... # type: int
2121
STAT_GOT_IP = ... # type: int
2222

23-
def __init__(self, interface_id: int) -> None:
24-
"""
25-
"""
26-
...
23+
def __init__(self, interface_id : int) -> None:
24+
"""初始化一个 wlan 对象"""
25+
...
2726

28-
def active(is_active : int) -> None:
27+
def active(self, is_active : int) -> None:
2928
"""
3029
- active([is_active])
3130
如果向该方法传入布尔数值,传入 True 则使能卡,传入 False 则禁止网卡。否则,如果不传入参数,则查询当前网卡的状态。
3231
"""
3332
...
3433

35-
def connect(ssid, password) -> None:
34+
def connect(self, ssid: str, password : str) -> None:
3635
"""使用指定的账号和密码链接指定的无线热点。"""
3736
...
3837

39-
def disconnect() -> None:
38+
def disconnect(self) -> None:
4039
"""从当前链接的无线网络中断开。"""
4140
...
4241

43-
def scan() -> None:
42+
def scan(self) -> None:
4443
"""
4544
扫描当前可以连接的无线网络。
4645
只能在 STA 模式下进行扫描,使用元组列表的形式返回 WiFi 接入点的相关信息。
4746
(ssid, bssid, channel, rssi, authmode, hidden)
4847
"""
4948
...
5049

51-
def status(param) -> None:
50+
def status(self, param : str) -> None:
5251
"""
5352
- status([param])
5453
返回当前无线连接的状态。
@@ -59,13 +58,13 @@ def status(param) -> None:
5958
"""
6059
...
6160

62-
def isconnected() -> None:
61+
def isconnected(self) -> None:
6362
"""
6463
在 STA 模式时,如果已经连接到 WiFi 网络,并且获得了 IP 地址,则返回 True。
6564
如果处在 AP 模式,此时已经与客户端建立连接,则返回 True。其他情况下都返回 False。"""
6665
...
6766

68-
def ifconfig(config: tuple) -> None:
67+
def ifconfig(self, config: tuple) -> None:
6968
"""
7069
ifconfig([(ip, subnet, gateway, dns)])
7170
获取或者设置网络接口的参数,IP 地址,子网掩码,网关,DNS 服务器。
@@ -75,7 +74,7 @@ def ifconfig(config: tuple) -> None:
7574
"""
7675
...
7776

78-
def config(param) -> None:
77+
def config(self, mac : str = None, essid : str = None, password : str = None, hidden : int = 0, channel : int = 0) -> None:
7978
"""
8079
- config(param=value, ...)
8180
获取或者设置一般网络接口参数,这些方法允许处理标准的 ip 配置之外的其他参数,如 WLAN.ifconfig() 函数处理的参数。

docs/code-completion/select.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class poll(string):
4040
def __init__(self) -> None:
4141
...
4242

43-
def register(obj) -> None:
43+
def register(self, obj) -> None:
4444
"""
4545
- register(obj[, eventmask])
4646
注册一个用以监控的对象,并设置被监控对象的监控标志位 flag。
@@ -54,7 +54,7 @@ def register(obj) -> None:
5454
"""
5555
...
5656

57-
def unregister(obj) -> None:
57+
def unregister(self, obj) -> None:
5858
"""
5959
解除监控的对象的注册。
6060
@@ -69,7 +69,7 @@ def unregister(obj) -> None:
6969
"""
7070
...
7171

72-
def modify(obj, eventmask) -> None:
72+
def modify(self, obj, eventmask) -> None:
7373
"""
7474
修改已注册的对象监控标志。
7575
@@ -85,7 +85,7 @@ def modify(obj, eventmask) -> None:
8585
"""
8686
...
8787

88-
def poll(timeout) -> None:
88+
def poll(self, timeout) -> None:
8989
"""
9090
- poll([timeout])
9191
等待至少一个已注册的对象准备就绪。

docs/code-completion/uctypes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class struct(addr, descriptor, type):
3131
def __init__(self) -> None:
3232
...
3333

34-
def sizeof(struct) -> None:
34+
def sizeof(self, struct) -> None:
3535
"""
3636
按字节返回数据的大小。参数可以是类或者数据对象 (或集合)。 示例:
3737
@@ -44,7 +44,7 @@ def sizeof(struct) -> None:
4444
"""
4545
...
4646

47-
def addressof(obj) -> None:
47+
def addressof(self, obj) -> None:
4848
"""
4949
返回对象地址。参数需要是 bytes, bytearray 。 示例:
5050
@@ -54,7 +54,7 @@ def addressof(obj) -> None:
5454
"""
5555
...
5656

57-
def bytes_at(addr, size)-> None:
57+
def bytes_at(self, addr, size)-> None:
5858
"""
5959
捕捉从 addr 开始到 size 个地址偏移量结束的内存数据为 bytearray 对象并返回。 示例:
6060
@@ -64,7 +64,7 @@ def bytes_at(addr, size)-> None:
6464
"""
6565
...
6666

67-
def bytearray_at(addr, size) -> None:
67+
def bytearray_at(self, addr, size) -> None:
6868
"""
6969
捕捉给定大小和地址内存为 bytearray 对象。与 bytes_at() 函数不同的是,它可以被再次写入,可以访问给定地址的参数。 示例:
7070

docs/code-completion/uhashlib.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class sha256(data):
1515
def __init__(self) -> None:
1616
...
1717

18-
def update(data) -> None:
18+
def update(self, data) -> None:
1919
"""将更多二进制数据放入哈希表中。"""
2020
...
2121

22-
def digest() -> None:
22+
def digest(self) -> None:
2323
"""返回字节对象哈希的所有数据。调用此方法后,将无法将更多数据送入哈希。"""
2424
...
2525

26-
def hexdigest() -> None:
26+
def hexdigest(self) -> None:
2727
"""此方法没有实现, 使用 ubinascii.hexlify(hash.digest()) 达到类似效果。"""
2828
...
2929

@@ -36,15 +36,15 @@ class sha1(data):
3636
def __init__(self) -> None:
3737
...
3838

39-
def update(data) -> None:
39+
def update(self, data) -> None:
4040
"""将更多二进制数据放入哈希表中。"""
4141
...
4242

43-
def digest() -> None:
43+
def digest(self) -> None:
4444
"""返回字节对象哈希的所有数据。调用此方法后,将无法将更多数据送入哈希。"""
4545
...
4646

47-
def hexdigest() -> None:
47+
def hexdigest(self) -> None:
4848
"""此方法没有实现, 使用 ubinascii.hexlify(hash.digest()) 达到类似效果。"""
4949
...
5050

@@ -58,14 +58,14 @@ class md5(data):
5858
def __init__(self) -> None:
5959
...
6060

61-
def update(data) -> None:
61+
def update(self, data) -> None:
6262
"""将更多二进制数据放入哈希表中。"""
6363
...
6464

65-
def digest() -> None:
65+
def digest(self) -> None:
6666
"""返回字节对象哈希的所有数据。调用此方法后,将无法将更多数据送入哈希。"""
6767
...
6868

69-
def hexdigest() -> None:
69+
def hexdigest(self) -> None:
7070
"""此方法没有实现, 使用 ubinascii.hexlify(hash.digest()) 达到类似效果。"""
7171
...

0 commit comments

Comments
 (0)