├── .gitignore ├── README.md ├── README_EN.md ├── code-completion ├── MicroWebSrv2 │ ├── __init__.py │ ├── httpRequest.py │ ├── httpResponse.py │ ├── libs │ │ ├── XAsyncSockets.py │ │ └── urlUtils.py │ ├── microWebSrv2.py │ ├── mods │ │ ├── PyhtmlTemplate.py │ │ └── WebSockets.py │ └── webRoute.py ├── _onewire.py ├── _thread.py ├── array.py ├── binascii.py ├── builtins.py ├── cmath.py ├── collections.py ├── dht.py ├── ds18x20.py ├── errno.py ├── framebuf.py ├── gc.py ├── hashlib.py ├── heapq.py ├── io.py ├── json.py ├── lcd160cr.py ├── lcd160cr_test.py ├── machine.py ├── math.py ├── microDNSSrv.py ├── micropython.py ├── network.py ├── onewire.py ├── os.py ├── pyb.py ├── random.py ├── re.py ├── rtthread.py ├── select.py ├── socket.py ├── stm.py ├── struct.py ├── sys.py ├── time.py ├── ubinascii.py ├── ucollections.py ├── uctypes.py ├── uerrno.py ├── uhashlib.py ├── uheapq.py ├── uio.py ├── ujson.py ├── umachine.py ├── umqtt │ └── simple.py ├── uos.py ├── urandom.py ├── ure.py ├── urequests.py ├── uselect.py ├── usocket.py ├── ussl.py ├── ustruct.py ├── utime.py ├── utimeq.py ├── uzlib.py └── zlib.py ├── demo └── weather_show │ ├── .mpyproject.json │ ├── main_demo.py │ ├── pictures │ ├── bingbao.bmp │ ├── lei.bmp │ ├── micropython.bmp │ ├── qing.bmp │ ├── shachen.bmp │ ├── weather.bmp │ ├── wifi_middle.bmp │ ├── wifi_strong.bmp │ ├── wifi_week.bmp │ ├── wu.bmp │ ├── xue.bmp │ ├── yin.bmp │ ├── yu.bmp │ ├── yujiaxue.bmp │ └── yun.bmp │ └── urequests.py ├── docs └── MicroPythonPlug-in │ ├── README.md │ ├── README_EN.md │ └── assets │ ├── check_example_en.png │ ├── direct_run_files_en.gif │ ├── download_file_floder_en.gif │ ├── en_connect_board.gif │ ├── en_create_blank_project.gif │ ├── en_run_example_files.gif │ ├── en_run_snippets.gif │ ├── en_select_powershell.gif │ ├── install_python_plug_en.png │ ├── more_deep_docs.png │ ├── plug_pic │ ├── 01_select_powershell.gif │ ├── 02_install_python_plug.png │ ├── 03_create_blank_prj.gif │ ├── 04_create_demo_prj.gif │ ├── 05_demo_express.png │ ├── 06_uart_connect.gif │ ├── 07_check_example.png │ ├── 08_direct_run_files.gif │ ├── 09_run_code_snippet.gif │ ├── 10_download_file_floder.gif │ ├── 11_sync_files.gif │ └── 12_auto_complete.gif │ └── sync_files_en.gif ├── examples ├── 00.learning │ ├── 00.hello_python.py │ ├── 01.basic_grammar.py │ ├── 02.number.py │ ├── 03.string.py │ ├── 04.list.py │ ├── 05.tuple.py │ ├── 06.set.py │ ├── 07.dict.py │ ├── 08.condition.py │ └── 09.loops.py ├── 01.basic │ ├── _thread.py │ ├── array.py │ ├── main.py │ ├── math.py │ ├── random.py │ ├── rmdir.py │ ├── sys.py │ ├── ucollections.py │ ├── uos.py │ └── utime.py ├── 02.network │ ├── tcp_client.py │ └── tcp_server.py ├── 03.board │ ├── 1.stm32l4_pandora │ │ ├── adc.py │ │ ├── beeper.py │ │ ├── blink.py │ │ ├── i2c.py │ │ ├── key.py │ │ ├── lcd.py │ │ ├── pin.py │ │ ├── pin_irq.py │ │ ├── pin_num.py │ │ ├── pwm.py │ │ ├── rgb_led.py │ │ ├── rtc.py │ │ ├── rtthread.py │ │ ├── spi.py │ │ ├── timer.py │ │ ├── uart.py │ │ ├── wdt.py │ │ ├── wifi_ap.py │ │ └── wifi_sta.py │ ├── 2.w601_iot_board │ │ ├── adc.py │ │ ├── beeper.py │ │ ├── blink.py │ │ ├── i2c.py │ │ ├── key.py │ │ ├── lcd.py │ │ ├── pin.py │ │ ├── pin_irq.py │ │ ├── pin_map.py │ │ ├── pwm.py │ │ ├── rgb_led.py │ │ ├── rtc.py │ │ ├── rtthread.py │ │ ├── spi.py │ │ ├── timer.py │ │ ├── uart.py │ │ ├── wdt.py │ │ ├── wifi_ap.py │ │ └── wifi_sta.py │ ├── 3.esp8266 │ │ └── blink.py │ ├── 4.esp32 │ │ └── blink.py │ ├── 5.pyboard │ │ └── blink.py │ └── 6.sparrow_one_board │ │ ├── camera_snapshot.py │ │ ├── camera_web.py │ │ ├── lcd.py │ │ ├── pin.py │ │ ├── pin_irq.py │ │ ├── player.py │ │ ├── recorder.py │ │ └── sound_recorder.py └── _README.md ├── firmware ├── l475_pandora_iot_board │ ├── stm32l475-atk-pandora-mpy-v1.10.2-20190919.bin │ └── stm32l475-atk-pandora-mpy-v1.10.2-20190921.bin ├── stm32f407-atk-explorer │ └── stm32f407-atk-explorer-mpy-v1.10.2-20190802.bin └── w601_iot_board │ ├── w601-atk-board-mpy-v1.10.2-20190919.FLS │ └── w601-atk-board-mpy-v1.10.2-20190921.FLS └── library ├── _README.md ├── aht10 ├── aht10.py └── aht10_example.py ├── ap3216c ├── ap3216c.py └── ap3216c_example.py ├── benchmark ├── benchmark.py ├── factorial.py └── pi_test.py ├── filetree ├── tree.py └── tree_example.py ├── icm20608 ├── icm20608.py └── icm20608_example.py ├── lcd_image ├── ball.img ├── show_bmp_example.py ├── show_bytes_image_example.py └── sun.bmp ├── mpu9250 ├── ak8963.py ├── mpu6500.py ├── mpu9250.py └── mpu9250_example.py ├── ssd1306 ├── font.py ├── ssd1306.py └── ssd1306_example.py ├── umqtt ├── example_pub.py ├── example_sub.py └── umqtt │ └── simple.py ├── urequests ├── urequests.py └── urequests_example.py └── webserver ├── _config.yml ├── fxos8700.py ├── hc2.png ├── microWebSocket.py ├── microWebSrv.py ├── microWebTemplate.py └── start.py /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/settings.json 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RT-Thread MicroPython 资源仓库 ([English](README_EN.md)) 2 | 3 | 本仓库用来存放在 [RT-Thread MicroPython 开发环境](https://marketplace.visualstudio.com/items?itemName=RT-Thread.rt-thread-micropython) 中所使用或者展示的资源文件,包含内容如下表所示: 4 | 5 | | 文件夹名称 | 介绍 | 6 | | --------------- | ---------------------------------------------------- | 7 | | code-completion | MicroPython 自动补全相关源文件 | 8 | | demo | demo 示例 | 9 | | docs | 说明文档 | 10 | | examples | 示例程序,包括通用示例以及特定于开发板的示例代码文件 | 11 | | firmware | RT-Thread 官方支持的固件 | 12 | | library | 通用库文件 | 13 | 14 | ## 贡献您的代码 15 | 16 | 您可以通过向 [RT-Thread mpy-snippets 仓库](https://github.com/RT-Thread/mpy-snippets) 提交 PR 的方式来为开源项目作出贡献,我们非常期待并感谢您的提交。欢迎各位开发者向 demo、examples 以及 library 项目中提交常用的示例文件或者自己编写的代码库。 17 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | # RT-Thread MicroPython repository 2 | 3 | The repository be used to store resources in [RT-Thread MicroPython development environment](https://marketplace.visualstudio.com/items?itemName=RT-Thread.rt-thread-micropython), as shown in the following table: 4 | 5 | | folder name | introduction | 6 | | --------------- | ----------------------------------------------------| 7 | | code-completion | MicroPython auto-completion of related source files | 8 | | demo | demo example | 9 | | docs | specification document | 10 | | examples | examples of programs, including generic examples and, a sample code file specific to the development board | 11 | | firmware | RT - Thread official support firmware | 12 | | library | general library file | 13 | 14 | ## Contribution 15 | 16 | You are welcome to make contributions to open source project [RT-Thread mpy-snippets repository](https://github.com/RT-Thread/mpy-snippets) by submitting your PR. We look forward to it and thank you for your submission. 17 | 18 | Developers are welcome to submit common sample files or code libraries to demo, examples, and library projects. -------------------------------------------------------------------------------- /code-completion/MicroWebSrv2/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright © 2019 Jean-Christophe Bos & HC² (www.hc2.fr) 4 | """ 5 | 6 | from .libs.XAsyncSockets import * 7 | from .libs.urlUtils import * 8 | from .webRoute import * 9 | from .microWebSrv2 import * 10 | -------------------------------------------------------------------------------- /code-completion/MicroWebSrv2/httpResponse.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright © 2019 Jean-Christophe Bos & HC² (www.hc2.fr) 4 | """ 5 | 6 | class HttpResponse : 7 | _RESPONSE_CODES = ... 8 | _CODE_CONTENT_TMPL = ... 9 | 10 | def __init__(self, microWebSrv2, request) : 11 | """ 12 | __init__ 13 | 14 | - microWebSrv2 15 | - request 16 | """ 17 | ... 18 | 19 | def SetHeader(self, name, value) : 20 | """ 21 | SetHeader 22 | 23 | - name 24 | - value 25 | """ 26 | ... 27 | 28 | def _onDataSent(self, xasCli, arg) : 29 | """ 30 | _onDataSent 31 | 32 | - xasCli 33 | - arg 34 | """ 35 | ... 36 | 37 | def _onClosed(self, xasCli, closedReason) : 38 | """ 39 | _onClosed 40 | 41 | - xasCli 42 | - closedReason 43 | """ 44 | ... 45 | 46 | def _makeBaseResponseHdr(self, code) : 47 | """ 48 | _makeBaseResponseHdr 49 | 50 | - code 51 | """ 52 | ... 53 | 54 | def _makeResponseHdr(self, code) : 55 | """ 56 | _makeResponseHdr 57 | 58 | - code 59 | """ 60 | ... 61 | 62 | def SwitchingProtocols(self, upgrade) : 63 | """ 64 | SwitchingProtocols 65 | 66 | - upgrade 67 | """ 68 | ... 69 | 70 | def ReturnStream(self, code, stream) : 71 | """ 72 | ReturnStream 73 | 74 | - code 75 | - stream 76 | """ 77 | ... 78 | 79 | def Return(self, code, content=None) : 80 | """ 81 | Return 82 | 83 | - code 84 | - content 85 | """ 86 | ... 87 | 88 | def ReturnJSON(self, code, obj) : 89 | """ 90 | ReturnJSON 91 | 92 | - code 93 | - obj 94 | """ 95 | ... 96 | 97 | def ReturnOk(self, content=None) : 98 | """ 99 | ReturnOk 100 | 101 | - content 102 | """ 103 | ... 104 | 105 | def ReturnOkJSON(self, obj) : 106 | """ 107 | ReturnOkJSON 108 | 109 | - obj 110 | """ 111 | ... 112 | 113 | def ReturnFile(self, filename, attachmentName=None) : 114 | """ 115 | ReturnFile 116 | 117 | - filename 118 | - attachmentName 119 | """ 120 | ... 121 | 122 | def ReturnNotModified(self) : 123 | """ 124 | ReturnNotModified 125 | 126 | - None 127 | """ 128 | ... 129 | 130 | def ReturnRedirect(self, location) : 131 | """ 132 | ReturnRedirect 133 | 134 | - location 135 | """ 136 | ... 137 | 138 | def ReturnBadRequest(self) : 139 | """ 140 | ReturnBadRequest 141 | 142 | - None 143 | """ 144 | ... 145 | 146 | def ReturnUnauthorized(self, typeName, realm=None) : 147 | """ 148 | ReturnUnauthorized 149 | 150 | - typeName 151 | - realm 152 | """ 153 | ... 154 | 155 | def ReturnForbidden(self) : 156 | """ 157 | ReturnForbidden 158 | 159 | - None 160 | """ 161 | ... 162 | 163 | def ReturnNotFound(self) : 164 | """ 165 | ReturnNotFound 166 | 167 | - None 168 | """ 169 | ... 170 | 171 | def ReturnMethodNotAllowed(self) : 172 | """ 173 | ReturnMethodNotAllowed 174 | 175 | - None 176 | """ 177 | ... 178 | 179 | def ReturnEntityTooLarge(self) : 180 | """ 181 | ReturnEntityTooLarge 182 | 183 | - None 184 | """ 185 | ... 186 | 187 | def ReturnInternalServerError(self) : 188 | """ 189 | ReturnInternalServerError 190 | 191 | - None 192 | """ 193 | ... 194 | 195 | def ReturnNotImplemented(self) : 196 | """ 197 | ReturnNotImplemented 198 | 199 | - None 200 | """ 201 | ... 202 | 203 | def ReturnServiceUnavailable(self) : 204 | """ 205 | ReturnServiceUnavailable 206 | 207 | - None 208 | """ 209 | ... 210 | 211 | def ReturnBasicAuthRequired(self) : 212 | """ 213 | ReturnBasicAuthRequired 214 | 215 | - None 216 | """ 217 | ... 218 | 219 | def ReturnBearerAuthRequired(self) : 220 | """ 221 | ReturnBearerAuthRequired 222 | 223 | - None 224 | """ 225 | ... 226 | 227 | @property 228 | def Request(self) : 229 | """ 230 | Request 231 | 232 | - None 233 | """ 234 | ... 235 | 236 | @property 237 | def UserAddress(self) : 238 | """ 239 | UserAddress 240 | 241 | - None 242 | """ 243 | ... 244 | 245 | @property 246 | def IsSSL(self) : 247 | """ 248 | IsSSL 249 | 250 | - None 251 | """ 252 | ... 253 | 254 | @property 255 | def AllowCaching(self) : 256 | """ 257 | AllowCaching 258 | 259 | - None 260 | """ 261 | ... 262 | 263 | @AllowCaching.setter 264 | def AllowCaching(self, value) : 265 | """ 266 | AllowCaching 267 | 268 | - value 269 | """ 270 | ... 271 | 272 | @property 273 | def ContentType(self) : 274 | """ 275 | ContentType 276 | 277 | - None 278 | """ 279 | ... 280 | 281 | @ContentType.setter 282 | def ContentType(self, value) : 283 | """ 284 | ContentType 285 | 286 | - value 287 | """ 288 | ... 289 | 290 | @property 291 | def ContentCharset(self) : 292 | """ 293 | ContentCharset 294 | 295 | - None 296 | """ 297 | ... 298 | 299 | @ContentCharset.setter 300 | def ContentCharset(self, value) : 301 | """ 302 | ContentCharset 303 | 304 | - value 305 | """ 306 | ... 307 | 308 | @property 309 | def ContentLength(self) : 310 | """ 311 | ContentLength 312 | 313 | - None 314 | """ 315 | ... 316 | 317 | @ContentLength.setter 318 | def ContentLength(self, value) : 319 | """ 320 | ContentLength 321 | 322 | - value 323 | """ 324 | ... 325 | 326 | @property 327 | def HeadersSent(self) : 328 | """ 329 | HeadersSent 330 | 331 | - None 332 | """ 333 | ... 334 | 335 | @property 336 | def OnSent(self) : 337 | """ 338 | OnSent 339 | 340 | - None 341 | """ 342 | ... 343 | 344 | @OnSent.setter 345 | def OnSent(self, value) : 346 | """ 347 | OnSent 348 | 349 | - value 350 | """ 351 | ... 352 | -------------------------------------------------------------------------------- /code-completion/MicroWebSrv2/libs/urlUtils.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright © 2019 Jean-Christophe Bos & HC² (www.hc2.fr) 4 | """ 5 | 6 | class UrlUtils : 7 | @staticmethod 8 | def Quote(s, safe='/') : 9 | """ 10 | Quote 11 | 12 | - safe 13 | """ 14 | ... 15 | 16 | @staticmethod 17 | def UrlEncode(s) : 18 | """ 19 | UrlEncode 20 | 21 | - None 22 | """ 23 | ... 24 | 25 | @staticmethod 26 | def Unquote(s) : 27 | """ 28 | Unquote 29 | 30 | - s 31 | """ 32 | ... 33 | 34 | @staticmethod 35 | def UnquotePlus(s) : 36 | """ 37 | UnquotePlus 38 | 39 | - s 40 | """ 41 | ... 42 | 43 | class Url : 44 | def __init__(self, url='') : 45 | """ 46 | __init__ 47 | 48 | - url 49 | """ 50 | ... 51 | 52 | def __repr__(self) : 53 | """ 54 | __repr__ 55 | 56 | - None 57 | """ 58 | ... 59 | 60 | def IsHttps(self) : 61 | """ 62 | IsHttps 63 | 64 | - None 65 | """ 66 | ... 67 | 68 | @property 69 | def URL(self) : 70 | """ 71 | URL 72 | 73 | - None 74 | """ 75 | ... 76 | 77 | @URL.setter 78 | def URL(self, value) : 79 | """ 80 | URL 81 | 82 | - value 83 | """ 84 | ... 85 | 86 | @property 87 | def Proto(self) : 88 | """ 89 | Proto 90 | 91 | - None 92 | """ 93 | ... 94 | 95 | @Proto.setter 96 | def Proto(self, value) : 97 | """ 98 | Proto 99 | 100 | - value 101 | """ 102 | ... 103 | 104 | @property 105 | def Host(self) : 106 | """ 107 | Host 108 | 109 | - None 110 | """ 111 | ... 112 | 113 | @Host.setter 114 | def Host(self, value) : 115 | """ 116 | Host 117 | 118 | - value 119 | """ 120 | ... 121 | 122 | @property 123 | def Port(self) : 124 | """ 125 | Port 126 | 127 | - None 128 | """ 129 | ... 130 | 131 | @Port.setter 132 | def Port(self, value) : 133 | """ 134 | Port 135 | 136 | - value 137 | """ 138 | ... 139 | 140 | @property 141 | def Path(self) : 142 | """ 143 | Path 144 | 145 | - None 146 | """ 147 | ... 148 | 149 | @Path.setter 150 | def Path(self, value) : 151 | """ 152 | Path 153 | 154 | - value 155 | """ 156 | ... 157 | 158 | @property 159 | def QueryString(self) : 160 | """ 161 | QueryString 162 | 163 | - None 164 | """ 165 | ... 166 | 167 | @QueryString.setter 168 | def QueryString(self, value) : 169 | """ 170 | QueryString 171 | 172 | - value 173 | """ 174 | ... 175 | 176 | @property 177 | def QueryParams(self) : 178 | """ 179 | QueryParams 180 | 181 | - None 182 | """ 183 | ... 184 | 185 | @QueryParams.setter 186 | def QueryParams(self, value) : 187 | """ 188 | QueryParams 189 | 190 | - value 191 | """ 192 | ... 193 | -------------------------------------------------------------------------------- /code-completion/MicroWebSrv2/mods/PyhtmlTemplate.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright © 2019 Jean-Christophe Bos & HC² (www.hc2.fr) 4 | """ 5 | 6 | class PyhtmlTemplate : 7 | _CODE_CONTENT_DEBUG = ... 8 | 9 | def __init__(self) : 10 | """ 11 | __init__ 12 | 13 | - None 14 | """ 15 | ... 16 | 17 | def OnRequest(self, microWebSrv2, request) : 18 | """ 19 | OnRequest 20 | 21 | - microWebSrv2 22 | - request 23 | """ 24 | ... 25 | 26 | def SetGlobalVar(self, globalVarName, globalVar) : 27 | """ 28 | SetGlobalVar 29 | 30 | - globalVarName 31 | - globalVar 32 | """ 33 | ... 34 | 35 | def GetGlobalVar(self, globalVarName) : 36 | """ 37 | GetGlobalVar 38 | 39 | - globalVarName 40 | """ 41 | ... 42 | 43 | @property 44 | def ShowDebug(self) : 45 | """ 46 | ShowDebug 47 | 48 | - None 49 | """ 50 | ... 51 | 52 | @ShowDebug.setter 53 | def ShowDebug(self, value) : 54 | """ 55 | ShowDebug 56 | 57 | - value 58 | """ 59 | ... 60 | 61 | class CodeTemplateException(Exception) : 62 | ... 63 | 64 | class CodeTemplate : 65 | TOKEN_OPEN = ... 66 | TOKEN_CLOSE = ... 67 | TOKEN_OPEN_LEN = ... 68 | TOKEN_CLOSE_LEN = ... 69 | 70 | INSTRUCTION_PYTHON = ... 71 | INSTRUCTION_IF = ... 72 | INSTRUCTION_ELIF = ... 73 | INSTRUCTION_ELSE = ... 74 | INSTRUCTION_FOR = ... 75 | INSTRUCTION_END = ... 76 | 77 | RE_IDENTIFIER = ... 78 | 79 | 80 | def __init__(self, code, escapeStrFunc=None) : 81 | """ 82 | __init__ 83 | 84 | - code 85 | - escapeStrFunc 86 | """ 87 | ... 88 | 89 | def Validate(self, pyGlobalVars=None, pyLocalVars=None) : 90 | """ 91 | Validate 92 | 93 | - pyGlobalVars 94 | - pyLocalVars 95 | """ 96 | ... 97 | 98 | def Execute(self, pyGlobalVars=None, pyLocalVars=None) : 99 | """ 100 | Execute 101 | 102 | - pyGlobalVars 103 | - pyLocalVars 104 | """ 105 | ... 106 | 107 | def _parseCode(self, pyGlobalVars, pyLocalVars, execute) : 108 | """ 109 | _parseCode 110 | 111 | - pyGlobalVars 112 | - pyLocalVars 113 | - execute 114 | """ 115 | ... 116 | 117 | def _parseBloc(self, execute) : 118 | """ 119 | _parseBloc 120 | 121 | - execute 122 | """ 123 | ... 124 | 125 | def _processToken(self, tokenContent, execute) : 126 | """ 127 | _processToken 128 | 129 | - tokenContent 130 | - execute 131 | """ 132 | ... 133 | 134 | def _processInstructionPYTHON(self, instructionBody, execute) : 135 | """ 136 | _processInstructionPYTHON 137 | 138 | - instructionBody 139 | - execute 140 | """ 141 | ... 142 | 143 | def _processInstructionIF(self, instructionBody, execute) : 144 | """ 145 | _processInstructionIF 146 | 147 | - instructionBody 148 | - execute 149 | """ 150 | ... 151 | 152 | def _processInstructionELIF(self, instructionBody, execute) : 153 | """ 154 | _processInstructionELIF 155 | 156 | - instructionBody 157 | - execute 158 | """ 159 | ... 160 | 161 | def _processInstructionELSE(self, instructionBody, execute) : 162 | """ 163 | _processInstructionELSE 164 | 165 | - instructionBody 166 | - execute 167 | """ 168 | ... 169 | 170 | def _processInstructionFOR(self, instructionBody, execute) : 171 | """ 172 | _processInstructionFOR 173 | 174 | - instructionBody 175 | - execute 176 | """ 177 | ... 178 | 179 | def _processInstructionEND(self, instructionBody, execute) : 180 | """ 181 | _processInstructionEND 182 | 183 | - instructionBody 184 | - execute 185 | """ 186 | ... 187 | -------------------------------------------------------------------------------- /code-completion/MicroWebSrv2/mods/WebSockets.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright © 2019 Jean-Christophe Bos & HC² (www.hc2.fr) 4 | """ 5 | 6 | class WebSockets : 7 | _PROTOCOL_VERSION = ... 8 | _HANDSHAKE_SIGN = ... 9 | 10 | 11 | def __init__(self) : 12 | """ 13 | __init__ 14 | 15 | - None 16 | """ 17 | ... 18 | 19 | def OnRequest(self, microWebSrv2, request) : 20 | """ 21 | OnRequest 22 | 23 | - microWebSrv2 24 | - request 25 | """ 26 | ... 27 | 28 | @property 29 | def OnWebSocketProtocol(self) : 30 | """ 31 | OnWebSocketProtocol 32 | 33 | - None 34 | """ 35 | ... 36 | 37 | @OnWebSocketProtocol.setter 38 | def OnWebSocketProtocol(self, value) : 39 | """ 40 | OnWebSocketProtocol 41 | 42 | - value 43 | """ 44 | ... 45 | 46 | @property 47 | def OnWebSocketAccepted(self) : 48 | """ 49 | OnWebSocketAccepted 50 | 51 | - None 52 | """ 53 | ... 54 | 55 | @OnWebSocketAccepted.setter 56 | def OnWebSocketAccepted(self, value) : 57 | """ 58 | OnWebSocketAccepted 59 | 60 | - value 61 | """ 62 | ... 63 | 64 | class WebSocket : 65 | _OP_FRAME_CONT = ... 66 | _OP_FRAME_TEXT = ... 67 | _OP_FRAME_BIN = ... 68 | _OP_FRAME_CLOSE = ... 69 | _OP_FRAME_PING = ... 70 | _OP_FRAME_PONG = ... 71 | 72 | _MSG_TYPE_TEXT = ... 73 | _MSG_TYPE_BIN = ... 74 | 75 | def __init__(self, wsMod, mws2, request) : 76 | """ 77 | __init__ 78 | 79 | - wsMod 80 | - mws2 81 | - request 82 | """ 83 | ... 84 | 85 | def _recvData(self, onRecv, size=None) : 86 | """ 87 | _recvData 88 | 89 | - onRecv 90 | - size 91 | """ 92 | ... 93 | 94 | def _onXAsCliClosed(self, xasCli, closedReason) : 95 | """ 96 | _onXAsCliClosed 97 | 98 | - xasCli 99 | - closedReason 100 | """ 101 | ... 102 | 103 | def _waitFrame(self) : 104 | """ 105 | _waitFrame 106 | 107 | - None 108 | """ 109 | ... 110 | 111 | def onHdrStartingRecv(xasCli, data, arg) : 112 | """ 113 | onHdrStartingRecv 114 | 115 | - xasCli 116 | - data 117 | - arg 118 | """ 119 | ... 120 | 121 | def endOfHeader(maskingKey) : 122 | """ 123 | endOfHeader 124 | 125 | - maskingKey 126 | """ 127 | ... 128 | 129 | def onPayloadDataRecv(xasCli, data, arg) : 130 | """ 131 | onPayloadDataRecv 132 | 133 | - xasCli 134 | - data 135 | - arg 136 | """ 137 | ... 138 | 139 | def getMaskingKey() : 140 | """ 141 | getMaskingKey 142 | 143 | - None 144 | """ 145 | ... 146 | 147 | def _sendFrame(self, opcode, data=None, fin=True) : 148 | """ 149 | _sendFrame 150 | 151 | - opcode 152 | - data 153 | - fin 154 | """ 155 | ... 156 | 157 | def _close(self, statusCode=None, reason=None, waitCloseFrame=False) : 158 | """ 159 | _close 160 | 161 | - statusCode 162 | - reason 163 | - waitCloseFrame 164 | """ 165 | ... 166 | 167 | def SendTextMessage(self, msg) : 168 | """ 169 | SendTextMessage 170 | 171 | - msg 172 | """ 173 | ... 174 | 175 | def SendBinaryMessage(self, msg) : 176 | """ 177 | SendBinaryMessage 178 | 179 | - msg 180 | """ 181 | ... 182 | 183 | def Close(self) : 184 | """ 185 | Close 186 | 187 | - None 188 | """ 189 | ... 190 | 191 | @property 192 | def Request(self) : 193 | """ 194 | Request 195 | 196 | - None 197 | """ 198 | ... 199 | 200 | @property 201 | def IsClosed(self) : 202 | """ 203 | IsClosed 204 | 205 | - None 206 | """ 207 | ... 208 | 209 | @property 210 | def WaitFrameTimeoutSec(self) : 211 | """ 212 | WaitFrameTimeoutSec 213 | 214 | - None 215 | """ 216 | ... 217 | 218 | @WaitFrameTimeoutSec.setter 219 | def WaitFrameTimeoutSec(self, value) : 220 | """ 221 | WaitFrameTimeoutSec 222 | 223 | - value 224 | """ 225 | ... 226 | 227 | @property 228 | def MaxRecvMessageLength(self) : 229 | """ 230 | MaxRecvMessageLength 231 | 232 | - None 233 | """ 234 | ... 235 | 236 | @MaxRecvMessageLength.setter 237 | def MaxRecvMessageLength(self, value) : 238 | """ 239 | MaxRecvMessageLength 240 | 241 | - value 242 | """ 243 | ... 244 | 245 | @property 246 | def OnTextMessage(self) : 247 | """ 248 | OnTextMessage 249 | 250 | - None 251 | """ 252 | ... 253 | 254 | @OnTextMessage.setter 255 | def OnTextMessage(self, value) : 256 | """ 257 | OnTextMessage 258 | 259 | - value 260 | """ 261 | ... 262 | 263 | @property 264 | def OnBinaryMessage(self) : 265 | """ 266 | OnBinaryMessage 267 | 268 | - None 269 | """ 270 | ... 271 | 272 | @OnBinaryMessage.setter 273 | def OnBinaryMessage(self, value) : 274 | """ 275 | OnBinaryMessage 276 | 277 | - value 278 | """ 279 | ... 280 | 281 | @property 282 | def OnClosed(self) : 283 | """ 284 | OnClosed 285 | 286 | - None 287 | """ 288 | ... 289 | 290 | @OnClosed.setter 291 | def OnClosed(self, value) : 292 | """ 293 | OnClosed 294 | 295 | - value 296 | """ 297 | ... 298 | -------------------------------------------------------------------------------- /code-completion/MicroWebSrv2/webRoute.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | The MIT License (MIT) 4 | Copyright © 2019 Jean-Christophe Bos & HC² (www.hc2.fr) 5 | """ 6 | 7 | def WebRoute(method=None, routePath=None, name=None) : 8 | """ 9 | WebRoute 10 | 11 | - method 12 | - routhPath 13 | - name 14 | """ 15 | ... 16 | 17 | def RegisterRoute(handler, method, routePath, name=None) : 18 | """ 19 | RegisterRoute 20 | 21 | - handler 22 | - method 23 | - routhPath 24 | - name 25 | """ 26 | ... 27 | 28 | def ResolveRoute(method, path) : 29 | """ 30 | ResolveRoute 31 | 32 | - method 33 | - path 34 | """ 35 | ... 36 | 37 | def PathFromRoute(routeName, routeArgs={ }) : 38 | """ 39 | PathFromRoute 40 | 41 | - routeName 42 | - routeArgs 43 | """ 44 | ... 45 | 46 | class RouteResult : 47 | def __init__(self, regRoute, args=None) : 48 | """ 49 | __init__ 50 | 51 | - regRoute 52 | - args 53 | """ 54 | ... 55 | 56 | def __repr__(self) : 57 | """ 58 | __repr__ 59 | 60 | - None 61 | """ 62 | ... 63 | 64 | @property 65 | def Handler(self) : 66 | """ 67 | Handler 68 | 69 | - None 70 | """ 71 | ... 72 | 73 | @property 74 | def Method(self) : 75 | """ 76 | Method 77 | 78 | - None 79 | """ 80 | ... 81 | 82 | @property 83 | def RoutePath(self) : 84 | """ 85 | RoutePath 86 | 87 | - None 88 | """ 89 | ... 90 | 91 | @property 92 | def Name(self) : 93 | """ 94 | Name 95 | 96 | - None 97 | """ 98 | ... 99 | 100 | @property 101 | def Args(self) : 102 | """ 103 | Args 104 | 105 | - None 106 | """ 107 | ... 108 | 109 | GET = ... 110 | HEAD = ... 111 | POST = ... 112 | PUT = ... 113 | DELETE = ... 114 | OPTIONS = ... 115 | PATCH = ... 116 | 117 | _registeredRoutes = ... 118 | 119 | 120 | class _registeredRoute : 121 | def __init__(self, handler, method, routePath, name, regex, argNames) : 122 | """ 123 | __init__ 124 | 125 | - handler 126 | - method 127 | - routePath 128 | - name 129 | - regex 130 | - argNames 131 | """ 132 | ... 133 | -------------------------------------------------------------------------------- /code-completion/_onewire.py: -------------------------------------------------------------------------------- 1 | def crc8(): 2 | pass 3 | 4 | 5 | def readbit(): 6 | pass 7 | 8 | 9 | def readbyte(): 10 | pass 11 | 12 | 13 | def reset(): 14 | pass 15 | 16 | 17 | def writebit(): 18 | pass 19 | 20 | 21 | def writebyte(): 22 | pass 23 | -------------------------------------------------------------------------------- /code-completion/_thread.py: -------------------------------------------------------------------------------- 1 | """ 2 | _thread 模块提供了用于处理多线程的基本方法——多个控制线程共享它们的全局数据空间。 3 | 为了实现同步,提供了简单的锁(也称为互斥锁或二进制信号量)。 4 | """ 5 | 6 | def start_new_thread(testThread) -> None: 7 | """start_new_thread(testThread, ())""" 8 | ... 9 | -------------------------------------------------------------------------------- /code-completion/array.py: -------------------------------------------------------------------------------- 1 | """ 2 | array 模块定义了一个对象类型,它可以简洁地表示基本值的数组:字符、整数、浮点数。支持代码格式: b, B, h, H, i, I, l, L, q, Q, f, d (最后2个需要支持浮点数)。 3 | """ 4 | 5 | class array(object): 6 | def __init__(self) -> None: 7 | """ 8 | 用给定类型的元素创建数组。数组的初始内容由 iterable 提供,如果没有提供,则创建一个空数组。 9 | typecode:数组的类型 10 | iterable:数组初始内容 11 | 示例: 12 | 13 | - import array 14 | - a = array.array('i', [2, 4, 1, 5])' 15 | - b = array.array('f') 16 | - print(a) 17 | - array('i', [2, 4, 1, 5]) 18 | - print(b) 19 | - array('f') 20 | """ 21 | ... 22 | 23 | def append(self, val) -> None: 24 | """ 25 | 将一个新元素追加到数组的末尾。 26 | 示例: 27 | 28 | - a = array.array('f', [3, 6]) 29 | - print(a) 30 | - array('f', [3.0, 6.0]) 31 | - a.append(7.0) 32 | - print(a) 33 | - array('f', [3.0, 6.0, 7.0]) 34 | """ 35 | ... 36 | 37 | def extend(self, iterable) -> None: 38 | """ 39 | 将一个新的数组追加到数组的末尾,注意追加的数组和原来数组的数据类型要保持一致。 40 | 示例: 41 | 42 | - a = array.array('i', [1, 2, 3]) 43 | - b = array.array('i', [4, 5]) 44 | - a.extend(b) 45 | - print(a) 46 | - array('i', [1, 2, 3, 4, 5]) 47 | """ 48 | ... 49 | 50 | -------------------------------------------------------------------------------- /code-completion/binascii.py: -------------------------------------------------------------------------------- 1 | def a2b_base64(): 2 | pass 3 | 4 | 5 | def b2a_base64(): 6 | pass 7 | 8 | 9 | def hexlify(): 10 | pass 11 | 12 | 13 | def unhexlify(): 14 | pass 15 | -------------------------------------------------------------------------------- /code-completion/cmath.py: -------------------------------------------------------------------------------- 1 | """ 2 | cmath 模块提供了对复数的数学函数的访问。这个模块中的函数接受整数、浮点数或复数作为参数。他们还将接受任何有复数或浮点方法的 Python 对象:这些方法分别用于将对象转换成复数或浮点数,然后将该函数应用到转换的结果中。 3 | """ 4 | 5 | e = ... # type: int 6 | pi = ... # type: int 7 | 8 | def cos(z) -> None: 9 | """返回z的余弦。""" 10 | ... 11 | 12 | def exp(z) -> None: 13 | """返回z的指数。""" 14 | ... 15 | 16 | def log(z) -> None: 17 | """返回z的对数。""" 18 | ... 19 | 20 | def log10(z) -> None: 21 | """返回z的常用对数。""" 22 | ... 23 | 24 | def phase(z) -> None: 25 | """返回z的相位, 范围是(-pi, +pi],以弧度表示。""" 26 | ... 27 | 28 | def polar(z) -> None: 29 | """返回z的极坐标。""" 30 | ... 31 | 32 | def rect(r, phi) -> None: 33 | """返回模量r和相位phi的复数。""" 34 | ... 35 | 36 | def sin(z) -> None: 37 | """返回z的正弦。""" 38 | ... 39 | 40 | def sqrt(z) -> None: 41 | """返回z的平方根。""" 42 | ... 43 | 44 | -------------------------------------------------------------------------------- /code-completion/collections.py: -------------------------------------------------------------------------------- 1 | class OrderedDict: 2 | "" 3 | 4 | def clear(): 5 | pass 6 | 7 | def copy(): 8 | pass 9 | 10 | def fromkeys(): 11 | pass 12 | 13 | def get(): 14 | pass 15 | 16 | def items(): 17 | pass 18 | 19 | def keys(): 20 | pass 21 | 22 | def pop(): 23 | pass 24 | 25 | def popitem(): 26 | pass 27 | 28 | def setdefault(): 29 | pass 30 | 31 | def update(): 32 | pass 33 | 34 | def values(): 35 | pass 36 | 37 | 38 | class deque: 39 | "" 40 | 41 | def append(): 42 | pass 43 | 44 | def popleft(): 45 | pass 46 | 47 | 48 | def namedtuple(): 49 | pass 50 | -------------------------------------------------------------------------------- /code-completion/dht.py: -------------------------------------------------------------------------------- 1 | class DHT11: 2 | "" 3 | 4 | def humidity(): 5 | pass 6 | 7 | def measure(): 8 | pass 9 | 10 | def temperature(): 11 | pass 12 | 13 | 14 | class DHT22: 15 | "" 16 | 17 | def humidity(): 18 | pass 19 | 20 | def measure(): 21 | pass 22 | 23 | def temperature(): 24 | pass 25 | 26 | 27 | class DHTBase: 28 | "" 29 | 30 | def measure(): 31 | pass 32 | 33 | 34 | def dht_readinto(): 35 | pass 36 | -------------------------------------------------------------------------------- /code-completion/ds18x20.py: -------------------------------------------------------------------------------- 1 | class DS18X20: 2 | def __init__(self, object): 3 | """ 4 | Initialize object 5 | 6 | - object 7 | """ 8 | ... 9 | 10 | def scan(self): 11 | """ 12 | Scan 13 | 14 | - None 15 | """ 16 | ... 17 | 18 | def convert_temp(self): 19 | """ 20 | Convert temp 21 | 22 | - None 23 | """ 24 | ... 25 | 26 | def read_temp(self, rom: bytes): 27 | """ 28 | Read temp 29 | 30 | - rom 31 | """ 32 | ... 33 | -------------------------------------------------------------------------------- /code-completion/errno.py: -------------------------------------------------------------------------------- 1 | EACCES = 13 2 | EADDRINUSE = 98 3 | EAGAIN = 11 4 | EALREADY = 114 5 | EBADF = 9 6 | ECONNABORTED = 103 7 | ECONNREFUSED = 111 8 | ECONNRESET = 104 9 | EEXIST = 17 10 | EHOSTUNREACH = 113 11 | EINPROGRESS = 115 12 | EINVAL = 22 13 | EIO = 5 14 | EISDIR = 21 15 | ENOBUFS = 105 16 | ENODEV = 19 17 | ENOENT = 2 18 | ENOMEM = 12 19 | ENOTCONN = 107 20 | EOPNOTSUPP = 95 21 | EPERM = 1 22 | ETIMEDOUT = 110 23 | errorcode = None 24 | -------------------------------------------------------------------------------- /code-completion/framebuf.py: -------------------------------------------------------------------------------- 1 | class FrameBuffer: 2 | "" 3 | 4 | def blit(): 5 | pass 6 | 7 | def fill(): 8 | pass 9 | 10 | def fill_rect(): 11 | pass 12 | 13 | def hline(): 14 | pass 15 | 16 | def line(): 17 | pass 18 | 19 | def pixel(): 20 | pass 21 | 22 | def rect(): 23 | pass 24 | 25 | def scroll(): 26 | pass 27 | 28 | def text(): 29 | pass 30 | 31 | def vline(): 32 | pass 33 | 34 | 35 | def FrameBuffer1(): 36 | pass 37 | 38 | 39 | GS2_HMSB = 5 40 | GS4_HMSB = 2 41 | GS8 = 6 42 | MONO_HLSB = 3 43 | MONO_HMSB = 4 44 | MONO_VLSB = 0 45 | MVLSB = 0 46 | RGB565 = 1 47 | -------------------------------------------------------------------------------- /code-completion/gc.py: -------------------------------------------------------------------------------- 1 | """ 2 | gc 模块提供了垃圾收集器的控制接口。 3 | """ 4 | 5 | def enable() -> None: 6 | """允许自动回收内存碎片。""" 7 | ... 8 | 9 | def disable() -> None: 10 | """禁止自动回收,但可以通过collect()函数进行手动回收内存碎片。""" 11 | ... 12 | 13 | def collect() -> None: 14 | """运行一次垃圾回收。""" 15 | ... 16 | 17 | def mem_alloc() -> None: 18 | """返回已分配的内存数量。""" 19 | ... 20 | 21 | def mem_free() -> None: 22 | """返回剩余的内存数量。""" 23 | ... 24 | -------------------------------------------------------------------------------- /code-completion/hashlib.py: -------------------------------------------------------------------------------- 1 | class sha256: 2 | "" 3 | 4 | def digest(): 5 | pass 6 | 7 | def update(): 8 | pass 9 | -------------------------------------------------------------------------------- /code-completion/heapq.py: -------------------------------------------------------------------------------- 1 | def heapify(): 2 | pass 3 | 4 | 5 | def heappop(): 6 | pass 7 | 8 | 9 | def heappush(): 10 | pass 11 | -------------------------------------------------------------------------------- /code-completion/io.py: -------------------------------------------------------------------------------- 1 | class BytesIO: 2 | "" 3 | 4 | def close(): 5 | pass 6 | 7 | def flush(): 8 | pass 9 | 10 | def getvalue(): 11 | pass 12 | 13 | def read(): 14 | pass 15 | 16 | def readinto(): 17 | pass 18 | 19 | def readline(): 20 | pass 21 | 22 | def seek(): 23 | pass 24 | 25 | def write(): 26 | pass 27 | 28 | 29 | class FileIO: 30 | "" 31 | 32 | def close(): 33 | pass 34 | 35 | def flush(): 36 | pass 37 | 38 | def read(): 39 | pass 40 | 41 | def readinto(): 42 | pass 43 | 44 | def readline(): 45 | pass 46 | 47 | def readlines(): 48 | pass 49 | 50 | def seek(): 51 | pass 52 | 53 | def tell(): 54 | pass 55 | 56 | def write(): 57 | pass 58 | 59 | 60 | class StringIO: 61 | "" 62 | 63 | def close(): 64 | pass 65 | 66 | def flush(): 67 | pass 68 | 69 | def getvalue(): 70 | pass 71 | 72 | def read(): 73 | pass 74 | 75 | def readinto(): 76 | pass 77 | 78 | def readline(): 79 | pass 80 | 81 | def seek(): 82 | pass 83 | 84 | def write(): 85 | pass 86 | 87 | 88 | class TextIOWrapper: 89 | "" 90 | 91 | def close(): 92 | pass 93 | 94 | def flush(): 95 | pass 96 | 97 | def read(): 98 | pass 99 | 100 | def readinto(): 101 | pass 102 | 103 | def readline(): 104 | pass 105 | 106 | def readlines(): 107 | pass 108 | 109 | def seek(): 110 | pass 111 | 112 | def tell(): 113 | pass 114 | 115 | def write(): 116 | pass 117 | 118 | 119 | def open(): 120 | pass 121 | -------------------------------------------------------------------------------- /code-completion/json.py: -------------------------------------------------------------------------------- 1 | def dump(): 2 | pass 3 | 4 | 5 | def dumps(): 6 | pass 7 | 8 | 9 | def load(): 10 | pass 11 | 12 | 13 | def loads(): 14 | pass 15 | -------------------------------------------------------------------------------- /code-completion/lcd160cr.py: -------------------------------------------------------------------------------- 1 | LANDSCAPE = 1 2 | LANDSCAPE_UPSIDEDOWN = 3 3 | 4 | 5 | class LCD160CR: 6 | "" 7 | 8 | def _fcmd2(): 9 | pass 10 | 11 | def _fcmd2b(): 12 | pass 13 | 14 | def _send(): 15 | pass 16 | 17 | def _waitfor(): 18 | pass 19 | 20 | def clip_line(): 21 | pass 22 | 23 | def dot(): 24 | pass 25 | 26 | def dot_no_clip(): 27 | pass 28 | 29 | def erase(): 30 | pass 31 | 32 | def fast_spi(): 33 | pass 34 | 35 | def feed_wdt(): 36 | pass 37 | 38 | def get_line(): 39 | pass 40 | 41 | def get_pixel(): 42 | pass 43 | 44 | def get_touch(): 45 | pass 46 | 47 | def iflush(): 48 | pass 49 | 50 | def is_touched(): 51 | pass 52 | 53 | def jpeg(): 54 | pass 55 | 56 | def jpeg_data(): 57 | pass 58 | 59 | def jpeg_start(): 60 | pass 61 | 62 | def line(): 63 | pass 64 | 65 | def line_no_clip(): 66 | pass 67 | 68 | def oflush(): 69 | pass 70 | 71 | def poly_dot(): 72 | pass 73 | 74 | def poly_line(): 75 | pass 76 | 77 | def rect(): 78 | pass 79 | 80 | def rect_interior(): 81 | pass 82 | 83 | def rect_interior_no_clip(): 84 | pass 85 | 86 | def rect_no_clip(): 87 | pass 88 | 89 | def rect_outline(): 90 | pass 91 | 92 | def rect_outline_no_clip(): 93 | pass 94 | 95 | def reset(): 96 | pass 97 | 98 | def rgb(): 99 | pass 100 | 101 | def save_to_flash(): 102 | pass 103 | 104 | def screen_dump(): 105 | pass 106 | 107 | def screen_load(): 108 | pass 109 | 110 | def set_brightness(): 111 | pass 112 | 113 | def set_font(): 114 | pass 115 | 116 | def set_i2c_addr(): 117 | pass 118 | 119 | def set_orient(): 120 | pass 121 | 122 | def set_pen(): 123 | pass 124 | 125 | def set_pixel(): 126 | pass 127 | 128 | def set_pos(): 129 | pass 130 | 131 | def set_power(): 132 | pass 133 | 134 | def set_scroll(): 135 | pass 136 | 137 | def set_scroll_buf(): 138 | pass 139 | 140 | def set_scroll_win(): 141 | pass 142 | 143 | def set_scroll_win_param(): 144 | pass 145 | 146 | def set_spi_win(): 147 | pass 148 | 149 | def set_startup_deco(): 150 | pass 151 | 152 | def set_text_color(): 153 | pass 154 | 155 | def set_uart_baudrate(): 156 | pass 157 | 158 | def show_framebuf(): 159 | pass 160 | 161 | def touch_config(): 162 | pass 163 | 164 | def write(): 165 | pass 166 | 167 | 168 | PORTRAIT = 0 169 | PORTRAIT_UPSIDEDOWN = 2 170 | STARTUP_DECO_INFO = 2 171 | STARTUP_DECO_MLOGO = 1 172 | STARTUP_DECO_NONE = 0 173 | _uart_baud_table = None 174 | 175 | 176 | def calcsize(): 177 | pass 178 | 179 | 180 | def const(): 181 | pass 182 | 183 | 184 | machine = None 185 | 186 | 187 | def pack_into(): 188 | pass 189 | 190 | 191 | def sleep_ms(): 192 | pass 193 | 194 | 195 | uerrno = None 196 | -------------------------------------------------------------------------------- /code-completion/lcd160cr_test.py: -------------------------------------------------------------------------------- 1 | framebuf = None 2 | 3 | 4 | def get_lcd(): 5 | pass 6 | 7 | 8 | lcd160cr = None 9 | math = None 10 | 11 | 12 | def show_adc(): 13 | pass 14 | 15 | 16 | def test_all(): 17 | pass 18 | 19 | 20 | def test_features(): 21 | pass 22 | 23 | 24 | def test_mandel(): 25 | pass 26 | 27 | 28 | time = None 29 | -------------------------------------------------------------------------------- /code-completion/math.py: -------------------------------------------------------------------------------- 1 | """ 2 | math 模块提供了对 C 标准定义的数学函数的访问。 3 | 本模块需要带有硬件 FPU,精度是32位,这个模块需要浮点功能支持。 4 | """ 5 | 6 | e = ... # type: int 7 | pi = ... # type: int 8 | 9 | def acos(x) -> None: 10 | """传入弧度值,计算cos(x)的反三角函数。""" 11 | ... 12 | 13 | def acosh(x) -> None: 14 | """返回 x 的逆双曲余弦。""" 15 | ... 16 | 17 | def asin(x) -> None: 18 | """传入弧度值,计算sin(x)的反三角函数。 示例: 19 | - x = math.asin(0.5) 20 | - print(x) 21 | 0.5235988""" 22 | ... 23 | 24 | def asinh(x) -> None: 25 | """返回 x 的逆双曲正弦。""" 26 | ... 27 | 28 | def atan(x) -> None: 29 | """返回 x 的逆切线。""" 30 | ... 31 | 32 | def atan2(y, x) -> None: 33 | """Return the principal value of the inverse tangent of y/x.""" 34 | ... 35 | 36 | def atanh(x) -> None: 37 | """Return the inverse hyperbolic tangent of x.""" 38 | ... 39 | 40 | def ceil(x) -> None: 41 | """向上取整。 示例: 42 | - x = math.ceil(5.6454) 43 | - print(x) 44 | - 6 45 | """ 46 | ... 47 | 48 | def copysign(x, y) -> None: 49 | """Return x with the sign of y.""" 50 | ... 51 | 52 | def cos(x) -> None: 53 | """传入弧度值,计算余弦。 示例:计算cos60° 54 | - math.cos(math.radians(60)) 55 | - 0.5 56 | """ 57 | ... 58 | 59 | def cosh(x) -> None: 60 | """Return the hyperbolic cosine of x.""" 61 | ... 62 | 63 | def degrees(x) -> None: 64 | """弧度转化为角度。 示例: 65 | - x = math.degrees(1.047198) 66 | - print(x) 67 | - 60.00002""" 68 | ... 69 | 70 | def erf(x) -> None: 71 | """Return the error function of x.""" 72 | ... 73 | 74 | def erfc(x) -> None: 75 | """Return the complementary error function of x.""" 76 | ... 77 | 78 | def exp(x) -> None: 79 | """计算e的x次方(幂)。 80 | 示例: 81 | - x = math.exp(2) 82 | - print(x) 83 | - 7.389056""" 84 | ... 85 | 86 | def expm1(x) -> None: 87 | """计算 math.exp(x) - 1。""" 88 | ... 89 | 90 | def fabs(x) -> None: 91 | """计算绝对值。 示例: 92 | - x = math.fabs(-5) 93 | - print(x) 94 | - 5.0 95 | - y = math.fabs(5.0) 96 | - print(y) 97 | - 5.0 98 | """ 99 | ... 100 | 101 | def floor(x) -> None: 102 | """向下取整。 示例: 103 | - x = math.floor(2.99) 104 | - print(x) 105 | 2 106 | - y = math.floor(-2.34) 107 | - print(y) 108 | -3 109 | """ 110 | ... 111 | 112 | def fmod(x, y) -> None: 113 | """取x除以y的模。 示例: 114 | - x = math.fmod(4, 5) 115 | - print(x) 116 | 4.0 117 | """ 118 | ... 119 | 120 | def frexp(x) -> None: 121 | """Decomposes a floating-point number into its mantissa and exponent. The returned value is the tuple (m, e) such that x == m * 2**e exactly. If x == 0 then the function returns (0.0, 0), otherwise the relation 0.5 <= abs(m) < 1 holds.""" 122 | ... 123 | 124 | def gamma(x) -> None: 125 | """返回伽马函数。 示例: 126 | - x = math.gamma(5.21) 127 | - print(x) 128 | 33.08715。 129 | """ 130 | ... 131 | 132 | def isfinite(x) -> None: 133 | """Return True if x is finite.""" 134 | ... 135 | 136 | def isinf(x) -> None: 137 | """Return True if x is infinite.""" 138 | ... 139 | 140 | def isnan(x) -> None: 141 | """Return True if x is not-a-number""" 142 | ... 143 | 144 | def ldexp(x, exp) -> None: 145 | """Return x * (2**exp).""" 146 | ... 147 | 148 | def lgamma(x) -> None: 149 | """返回伽马函数的自然对数。 示例: 150 | - x = math.lgamma(5.21) 151 | - print(x) 152 | 3.499145""" 153 | ... 154 | 155 | def log(x) -> None: 156 | """计算以e为底的x的对数。 示例: 157 | - x = math.log(10) 158 | - print(x) 159 | 2.302585""" 160 | ... 161 | 162 | def log10(x) -> None: 163 | """计算以10为底的x的对数。 示例: 164 | - x = math.log10(10) 165 | - print(x) 166 | 1.0""" 167 | ... 168 | 169 | def log2(x) -> None: 170 | """计算以2为底的x的对数。 示例: 171 | - x = math.log2(8) 172 | - print(x) 173 | 3.0""" 174 | ... 175 | 176 | def modf(x) -> None: 177 | """Return a tuple of two floats, being the fractional and integral parts of x. Both return values have the same sign as x.""" 178 | ... 179 | 180 | def pow(x, y) -> None: 181 | """计算 x 的 y 次方(幂)。 示例: 182 | - x = math.pow(2, 3) 183 | - print(x) 184 | 8.0""" 185 | ... 186 | 187 | def radians(x) -> None: 188 | """角度转化为弧度。 示例: 189 | - x = math.radians(60) 190 | - print(x) 191 | 1.047198""" 192 | ... 193 | 194 | def sin(x) -> None: 195 | """传入弧度值,计算正弦。 示例:计算sin90° 196 | - math.sin(math.radians(90)) 197 | 1.0""" 198 | ... 199 | 200 | def sinh(x) -> None: 201 | """Return the hyperbolic sine of x.""" 202 | ... 203 | 204 | def sqrt(x) -> None: 205 | """ 206 | 计算平方根。 207 | 示例: 208 | - x = math.sqrt(9) 209 | - print(x) 210 | 3.0""" 211 | ... 212 | 213 | def tan(x) -> None: 214 | """ 215 | 传入弧度值,计算正切。 示例:计算tan60° 216 | - math.tan(math.radians(60)) 217 | 1.732051""" 218 | ... 219 | 220 | def tanh(x) -> None: 221 | """Return the hyperbolic tangent of x.""" 222 | ... 223 | 224 | def trunc(x) -> None: 225 | """ 226 | 取整。 227 | 示例: 228 | - x = math.trunc(5.12) 229 | - print(x) 230 | 5 231 | - y = math.trunc(-6.8) 232 | - print(y) 233 | -6""" 234 | ... 235 | -------------------------------------------------------------------------------- /code-completion/microDNSSrv.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright © 2018 Jean-Christophe Bos & HC² (www.hc2.fr) 4 | """ 5 | 6 | class MicroDNSSrv : 7 | def Create(self, domainsList) : 8 | """ 9 | Speed Creation 10 | 11 | - domainsList 12 | 13 | eg. domainsList = { 14 | "test.com" : "1.1.1.1", 15 | "*test2.com" : "2.2.2.2", 16 | "*google*" : "192.168.4.1", 17 | "*.toto.com" : "192.168.4.1", 18 | "www.site.*" : "192.168.4.1" } 19 | """ 20 | ... 21 | 22 | def _tryStartThread(self, func, args=()) : 23 | """ 24 | _tryStartThread 25 | 26 | - func 27 | - args 28 | """ 29 | ... 30 | 31 | def _ipV4StrToBytes(self, ipStr) : 32 | """ 33 | _ipV4StrToBytes 34 | 35 | - ipStr 36 | """ 37 | ... 38 | 39 | def _getAskedDomainName(self, packet) : 40 | """ 41 | _getAskedDomainName 42 | 43 | - packet 44 | """ 45 | ... 46 | 47 | def _getPacketAnswerA(self, packet, ipV4Bytes) : 48 | """ 49 | _getPacketAnswerA 50 | 51 | - packet 52 | - ipV4Bytes 53 | """ 54 | ... 55 | 56 | def __init__(self) : 57 | """ 58 | Initialize object 59 | 60 | -None 61 | """ 62 | ... 63 | 64 | def _serverProcess(self) : 65 | """ 66 | _serverProcess 67 | 68 | - None 69 | """ 70 | ... 71 | 72 | def Start(self) : 73 | """ 74 | Start dns server 75 | 76 | - None 77 | """ 78 | ... 79 | 80 | def Stop(self) : 81 | """ 82 | Stop dns server 83 | 84 | - None 85 | """ 86 | ... 87 | 88 | def IsStarted(self) : 89 | """ 90 | Dns server start status 91 | 92 | - None 93 | """ 94 | ... 95 | 96 | def SetDomainsList(self, domainsList) : 97 | """ 98 | Set domains list 99 | 100 | - domainsList 101 | """ 102 | ... 103 | -------------------------------------------------------------------------------- /code-completion/micropython.py: -------------------------------------------------------------------------------- 1 | def alloc_emergency_exception_buf(): 2 | pass 3 | 4 | 5 | def const(): 6 | pass 7 | 8 | 9 | def heap_lock(): 10 | pass 11 | 12 | 13 | def heap_unlock(): 14 | pass 15 | 16 | 17 | def kbd_intr(): 18 | pass 19 | 20 | 21 | def mem_info(): 22 | pass 23 | 24 | 25 | def opt_level(): 26 | pass 27 | 28 | 29 | def qstr_info(): 30 | pass 31 | 32 | 33 | def schedule(): 34 | pass 35 | 36 | 37 | def stack_use(): 38 | pass 39 | -------------------------------------------------------------------------------- /code-completion/network.py: -------------------------------------------------------------------------------- 1 | """ 2 | 此模块提供网络驱动程序和路由配置。特定硬件的网络驱动程序在此模块中可用,用于配置硬件网络接口。然后,配置接口提供的网络服务可以通过 usocket 模块使用。 3 | """ 4 | 5 | STA_IF = ... # type: int 6 | AP_IF = ... # type: int 7 | 8 | class WLAN(object): 9 | """ 10 | 创建一个 WLAN 网络接口对象。 11 | 支持的接口是 network.STA_IF(STA 模式,可以连接到上游的 WiFi 热点上) 和 network.AP_IF(AP 模式,允许其他 WiFi 客户端连接到自身的热点)。 12 | 下面方法的可用性取决于接口的类型。 13 | 例如,只有STA 接口可以使用 WLAN.connect() 方法连接到 AP 热点上。 14 | """ 15 | 16 | STAT_IDLE = ... # type: int 17 | STAT_CONNECTING = ... # type: int 18 | STAT_WRONG_PASSWORD = ... # type: int 19 | STAT_NO_AP_FOUND = ... # type: int 20 | STAT_CONNECT_FAIL = ... # type: int 21 | STAT_GOT_IP = ... # type: int 22 | STAT_BEACON_TIMEOUT = ... 23 | STAT_ASSOC_FAIL = ... 24 | STAT_HANDSHAKE_TIMEOUT = ... 25 | 26 | def __init__(self, interface_id : int) -> None: 27 | """初始化一个 wlan 对象""" 28 | ... 29 | 30 | def active(self, is_active : int) -> None: 31 | """ 32 | - active([is_active]) 33 | 如果向该方法传入布尔数值,传入 True 则使能卡,传入 False 则禁止网卡。否则,如果不传入参数,则查询当前网卡的状态。 34 | """ 35 | ... 36 | 37 | def connect(self, ssid: str, password : str) -> None: 38 | """使用指定的账号和密码链接指定的无线热点。""" 39 | ... 40 | 41 | def disconnect(self) -> None: 42 | """从当前链接的无线网络中断开。""" 43 | ... 44 | 45 | def scan(self) -> None: 46 | """ 47 | 扫描当前可以连接的无线网络。 48 | 只能在 STA 模式下进行扫描,使用元组列表的形式返回 WiFi 接入点的相关信息。 49 | (ssid, bssid, channel, rssi, authmode, hidden) 50 | """ 51 | ... 52 | 53 | def status(self, param : str) -> None: 54 | """ 55 | - status([param]) 56 | 返回当前无线连接的状态。 57 | 当调用该方法时没有附带参数,就会返回值描述当前网络连接的状态。 58 | 如果还没有从热点连接中获得 IP 地址,此时的状态为 STATION_IDLE。 59 | 如果已经从连接的无线网络中获得 IP 地址,此时的状态为 STAT_GOT_IP。 60 | 当调用该函数使用的参数为 rssi 时,则返回 rssi 的值,该函数目前只支持这一个参数。 61 | """ 62 | ... 63 | 64 | def isconnected(self) -> None: 65 | """ 66 | 在 STA 模式时,如果已经连接到 WiFi 网络,并且获得了 IP 地址,则返回 True。 67 | 如果处在 AP 模式,此时已经与客户端建立连接,则返回 True。其他情况下都返回 False。""" 68 | ... 69 | 70 | def ifconfig(self, config: tuple) -> None: 71 | """ 72 | ifconfig([(ip, subnet, gateway, dns)]) 73 | 获取或者设置网络接口的参数,IP 地址,子网掩码,网关,DNS 服务器。 74 | 当调用该方法不附带参数时,该方法会返回一个包含四个元素的元组来描述上面的信息。 75 | 想要设置上面的值,传入一个包含上述四个元素的元组,例如: 76 | - nic.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8')) 77 | """ 78 | ... 79 | 80 | def config(self, mac : str = None, essid : str = None, password : str = None, hidden : int = 0, channel : int = 0) -> None: 81 | """ 82 | - config(param=value, ...) 83 | 获取或者设置一般网络接口参数,这些方法允许处理标准的 ip 配置之外的其他参数,如 WLAN.ifconfig() 函数处理的参数。 84 | 这些参数包括特定网络和特定硬件的参数。 85 | 对于参数的设置,应该使用关键字的语法,可以一次性设置多个参数。""" 86 | ... 87 | -------------------------------------------------------------------------------- /code-completion/onewire.py: -------------------------------------------------------------------------------- 1 | class OneWire: 2 | "" 3 | MATCH_ROM = 85 4 | SEARCH_ROM = 240 5 | SKIP_ROM = 204 6 | 7 | def _search_rom(): 8 | pass 9 | 10 | def crc8(): 11 | pass 12 | 13 | def readbit(): 14 | pass 15 | 16 | def readbyte(): 17 | pass 18 | 19 | def readinto(): 20 | pass 21 | 22 | def reset(): 23 | pass 24 | 25 | def scan(): 26 | pass 27 | 28 | def select_rom(): 29 | pass 30 | 31 | def write(): 32 | pass 33 | 34 | def writebit(): 35 | pass 36 | 37 | def writebyte(): 38 | pass 39 | 40 | 41 | class OneWireError: 42 | "" 43 | 44 | 45 | _ow = None 46 | 47 | 48 | def const(): 49 | pass 50 | -------------------------------------------------------------------------------- /code-completion/os.py: -------------------------------------------------------------------------------- 1 | class VfsFat: 2 | "" 3 | 4 | def chdir(): 5 | pass 6 | 7 | def getcwd(): 8 | pass 9 | 10 | def ilistdir(): 11 | pass 12 | 13 | def mkdir(): 14 | pass 15 | 16 | def mkfs(): 17 | pass 18 | 19 | def mount(): 20 | pass 21 | 22 | def open(): 23 | pass 24 | 25 | def remove(): 26 | pass 27 | 28 | def rename(): 29 | pass 30 | 31 | def rmdir(): 32 | pass 33 | 34 | def stat(): 35 | pass 36 | 37 | def statvfs(): 38 | pass 39 | 40 | def umount(): 41 | pass 42 | 43 | 44 | def chdir(): 45 | pass 46 | 47 | 48 | def dupterm(): 49 | pass 50 | 51 | 52 | def getcwd(): 53 | pass 54 | 55 | 56 | def ilistdir(): 57 | pass 58 | 59 | 60 | def listdir(): 61 | pass 62 | 63 | 64 | def mkdir(): 65 | pass 66 | 67 | 68 | def mount(): 69 | pass 70 | 71 | 72 | def remove(): 73 | pass 74 | 75 | 76 | def rename(): 77 | pass 78 | 79 | 80 | def rmdir(): 81 | pass 82 | 83 | 84 | sep = "/" 85 | 86 | 87 | def stat(): 88 | pass 89 | 90 | 91 | def statvfs(): 92 | pass 93 | 94 | 95 | def sync(): 96 | pass 97 | 98 | 99 | def umount(): 100 | pass 101 | 102 | 103 | def uname(): 104 | pass 105 | 106 | 107 | def unlink(): 108 | pass 109 | -------------------------------------------------------------------------------- /code-completion/random.py: -------------------------------------------------------------------------------- 1 | def choice(): 2 | pass 3 | 4 | 5 | def getrandbits(): 6 | pass 7 | 8 | 9 | def randint(): 10 | pass 11 | 12 | 13 | def random(): 14 | pass 15 | 16 | 17 | def randrange(): 18 | pass 19 | 20 | 21 | def seed(): 22 | pass 23 | 24 | 25 | def uniform(): 26 | pass 27 | -------------------------------------------------------------------------------- /code-completion/re.py: -------------------------------------------------------------------------------- 1 | DEBUG = 4096 2 | 3 | 4 | def compile(): 5 | pass 6 | 7 | 8 | def match(): 9 | pass 10 | 11 | 12 | def search(): 13 | pass 14 | -------------------------------------------------------------------------------- /code-completion/rtthread.py: -------------------------------------------------------------------------------- 1 | """ 2 | rtthread 模块提供了与 RT-Thread 操作系统相关的功能,如查看栈使用情况等。 3 | """ 4 | 5 | def current_tid() -> None: 6 | """返回当前线程的 id 。""" 7 | ... 8 | 9 | def is_preempt_thread() -> None: 10 | """返回是否是可抢占线程。""" 11 | ... 12 | 13 | def stacks_analyze() -> None: 14 | """返回当前系统线程和栈使用信息。""" 15 | ... 16 | 17 | def list_device() -> None: 18 | """列出当前板卡上可使用的设备信息,包括设备名和设备类型。""" 19 | ... 20 | -------------------------------------------------------------------------------- /code-completion/select.py: -------------------------------------------------------------------------------- 1 | """ 2 | uselect 模块提供了等待数据流的事件功能。 3 | """ 4 | 5 | def select(rlist, wlist, xlist) -> None: 6 | """ 7 | 监控对象何时可读或可写,一旦监控的对象状态改变,返回结果(阻塞线程)。这个函数是为了兼容,效率不高,推荐用 poll 函数 。 8 | 9 | - select.select(rlist, wlist, xlist[, timeout]) 10 | 11 | - rlist:等待读就绪的文件描述符数组 12 | - wlist:等待写就绪的文件描述符数组 13 | - xlist:等待异常的数组 14 | - timeout:等待时间(单位:秒) 15 | 16 | 示例: 17 | 18 | - def selectTest(): 19 | - global s 20 | - rs, ws, es = select.select([s,], [], []) 21 | - #程序会在此等待直到对象s可读 22 | - print(rs) 23 | - for i in rs: 24 | - if i == s: 25 | - print("s can read now") 26 | - data,addr=s.recvfrom(1024) 27 | - print('received:',data,'from',addr)""" 28 | ... 29 | 30 | class poll(string): 31 | """ 32 | 创建 poll 实例。 33 | 34 | 示例: 35 | 36 | - poller = select.poll() 37 | - print(poller) 38 | - 39 | """ 40 | def __init__(self) -> None: 41 | ... 42 | 43 | def register(self, obj) -> None: 44 | """ 45 | - register(obj[, eventmask]) 46 | 注册一个用以监控的对象,并设置被监控对象的监控标志位 flag。 47 | 48 | - obj:被监控的对象 49 | - flag:被监控的标志 50 | - select.POLLIN — 可读 51 | - select.POLLHUP — 已挂断 52 | - select.POLLERR — 出错 53 | - select.POLLOUT — 可写 54 | """ 55 | ... 56 | 57 | def unregister(self, obj) -> None: 58 | """ 59 | 解除监控的对象的注册。 60 | 61 | - obj:注册过的对象 62 | 63 | 示例: 64 | 65 | - READ_ONLY = select.POLLIN | select.POLLHUP | select.POLLERR 66 | - READ_WRITE = select.POLLOUT | READ_ONLY 67 | - poller.register(s, READ_WRITE) 68 | - poller.unregister(s) 69 | """ 70 | ... 71 | 72 | def modify(self, obj, eventmask) -> None: 73 | """ 74 | 修改已注册的对象监控标志。 75 | 76 | - obj:已注册的被监控对象 77 | - flag:修改为的监控标志 78 | 79 | 示例: 80 | 81 | - READ_ONLY = select.POLLIN | select.POLLHUP | select.POLLERR 82 | - READ_WRITE = select.POLLOUT | READ_ONLY 83 | - poller.register(s, READ_WRITE) 84 | - poller.modify(s, READ_ONLY) 85 | """ 86 | ... 87 | 88 | def poll(self, timeout) -> None: 89 | """ 90 | - poll([timeout]) 91 | 等待至少一个已注册的对象准备就绪。 92 | 返回 (obj, event, ...) 元组, event 元素指定了一个流发生的事件,是上面所描述的 select.POLL*常量组合。 93 | 根据平台和版本的不同,在元组中可能有其他元素,所以不要假定元组的大小是 2 。如果超时,则返回空列表。 94 | """ 95 | ... 96 | 97 | POLLIN = ... # type: int 98 | POLLOUT = ... # type: int 99 | POLLERR = ... # type: int 100 | POLLHUP = ... # type: int 101 | -------------------------------------------------------------------------------- /code-completion/socket.py: -------------------------------------------------------------------------------- 1 | AF_INET = 2 2 | AF_INET6 = 10 3 | SOCK_DGRAM = 2 4 | SOCK_RAW = 3 5 | SOCK_STREAM = 1 6 | 7 | 8 | def getaddrinfo(): 9 | pass 10 | 11 | 12 | class socket: 13 | "" 14 | 15 | def accept(): 16 | pass 17 | 18 | def bind(): 19 | pass 20 | 21 | def close(): 22 | pass 23 | 24 | def connect(): 25 | pass 26 | 27 | def listen(): 28 | pass 29 | 30 | def recv(): 31 | pass 32 | 33 | def recvfrom(): 34 | pass 35 | 36 | def send(): 37 | pass 38 | 39 | def sendto(): 40 | pass 41 | 42 | def setblocking(): 43 | pass 44 | 45 | def setsockopt(): 46 | pass 47 | 48 | def settimeout(): 49 | pass 50 | -------------------------------------------------------------------------------- /code-completion/stm.py: -------------------------------------------------------------------------------- 1 | ADC1 = 1073815552 2 | ADC1_COMMON = 1073816320 3 | ADC_CR1 = 4 4 | ADC_CR2 = 8 5 | ADC_DR = 76 6 | ADC_HTR = 36 7 | ADC_JDR1 = 60 8 | ADC_JDR2 = 64 9 | ADC_JDR3 = 68 10 | ADC_JDR4 = 72 11 | ADC_JOFR1 = 20 12 | ADC_JOFR2 = 24 13 | ADC_JOFR3 = 28 14 | ADC_JOFR4 = 32 15 | ADC_JSQR = 56 16 | ADC_LTR = 40 17 | ADC_SMPR1 = 12 18 | ADC_SMPR2 = 16 19 | ADC_SQR1 = 44 20 | ADC_SQR2 = 48 21 | ADC_SQR3 = 52 22 | ADC_SR = 0 23 | CRC = 1073885184 24 | CRC_CR = 8 25 | CRC_DR = 0 26 | CRC_IDR = 4 27 | DBGMCU = 3758366720 28 | DBGMCU_APB1FZ = 8 29 | DBGMCU_APB2FZ = 12 30 | DBGMCU_CR = 4 31 | DBGMCU_IDCODE = 0 32 | DMA1 = 1073897472 33 | DMA2 = 1073898496 34 | DMA_HIFCR = 12 35 | DMA_HISR = 4 36 | DMA_LIFCR = 8 37 | DMA_LISR = 0 38 | EXTI = 1073822720 39 | EXTI_EMR = 4 40 | EXTI_FTSR = 12 41 | EXTI_IMR = 0 42 | EXTI_PR = 20 43 | EXTI_RTSR = 8 44 | EXTI_SWIER = 16 45 | FLASH = 1073888256 46 | FLASH_ACR = 0 47 | FLASH_CR = 16 48 | FLASH_KEYR = 4 49 | FLASH_OPTCR = 20 50 | FLASH_OPTCR1 = 24 51 | FLASH_OPTKEYR = 8 52 | FLASH_SR = 12 53 | GPIOA = 1073872896 54 | GPIOB = 1073873920 55 | GPIOC = 1073874944 56 | GPIOD = 1073875968 57 | GPIOE = 1073876992 58 | GPIOH = 1073880064 59 | GPIO_AFR0 = 32 60 | GPIO_AFR1 = 36 61 | GPIO_BSRR = 24 62 | GPIO_BSRRH = 26 63 | GPIO_BSRRL = 24 64 | GPIO_IDR = 16 65 | GPIO_LCKR = 28 66 | GPIO_MODER = 0 67 | GPIO_ODR = 20 68 | GPIO_OSPEEDR = 8 69 | GPIO_OTYPER = 4 70 | GPIO_PUPDR = 12 71 | I2C1 = 1073763328 72 | I2C2 = 1073764352 73 | I2C3 = 1073765376 74 | I2C_CCR = 28 75 | I2C_CR1 = 0 76 | I2C_CR2 = 4 77 | I2C_DR = 16 78 | I2C_FLTR = 36 79 | I2C_OAR1 = 8 80 | I2C_OAR2 = 12 81 | I2C_SR1 = 20 82 | I2C_SR2 = 24 83 | I2C_TRISE = 32 84 | I2S2EXT = 1073755136 85 | I2S3EXT = 1073758208 86 | IWDG = 1073754112 87 | IWDG_KR = 0 88 | IWDG_PR = 4 89 | IWDG_RLR = 8 90 | IWDG_SR = 12 91 | PWR = 1073770496 92 | PWR_CR = 0 93 | PWR_CSR = 4 94 | RCC = 1073887232 95 | RCC_AHB1ENR = 48 96 | RCC_AHB1LPENR = 80 97 | RCC_AHB1RSTR = 16 98 | RCC_AHB2ENR = 52 99 | RCC_AHB2LPENR = 84 100 | RCC_AHB2RSTR = 20 101 | RCC_AHB3ENR = 56 102 | RCC_AHB3LPENR = 88 103 | RCC_AHB3RSTR = 24 104 | RCC_APB1ENR = 64 105 | RCC_APB1LPENR = 96 106 | RCC_APB1RSTR = 32 107 | RCC_APB2ENR = 68 108 | RCC_APB2LPENR = 100 109 | RCC_APB2RSTR = 36 110 | RCC_BDCR = 112 111 | RCC_CFGR = 8 112 | RCC_CIR = 12 113 | RCC_CR = 0 114 | RCC_CSR = 116 115 | RCC_DCKCFGR = 140 116 | RCC_PLLCFGR = 4 117 | RCC_PLLI2SCFGR = 132 118 | RCC_SSCGR = 128 119 | RTC = 1073752064 120 | RTC_ALRMAR = 28 121 | RTC_ALRMBR = 32 122 | RTC_BKP0R = 80 123 | RTC_BKP10R = 120 124 | RTC_BKP11R = 124 125 | RTC_BKP12R = 128 126 | RTC_BKP13R = 132 127 | RTC_BKP14R = 136 128 | RTC_BKP15R = 140 129 | RTC_BKP16R = 144 130 | RTC_BKP17R = 148 131 | RTC_BKP18R = 152 132 | RTC_BKP19R = 156 133 | RTC_BKP1R = 84 134 | RTC_BKP2R = 88 135 | RTC_BKP3R = 92 136 | RTC_BKP4R = 96 137 | RTC_BKP5R = 100 138 | RTC_BKP6R = 104 139 | RTC_BKP7R = 108 140 | RTC_BKP8R = 112 141 | RTC_BKP9R = 116 142 | RTC_CALIBR = 24 143 | RTC_CALR = 60 144 | RTC_CR = 8 145 | RTC_DR = 4 146 | RTC_ISR = 12 147 | RTC_PRER = 16 148 | RTC_SHIFTR = 44 149 | RTC_SSR = 40 150 | RTC_TAFCR = 64 151 | RTC_TR = 0 152 | RTC_TSDR = 52 153 | RTC_TSSSR = 56 154 | RTC_TSTR = 48 155 | RTC_WPR = 36 156 | RTC_WUTR = 20 157 | SDIO = 1073818624 158 | SPI1 = 1073819648 159 | SPI2 = 1073756160 160 | SPI3 = 1073757184 161 | SPI4 = 1073820672 162 | SPI5 = 1073827840 163 | SPI_CR1 = 0 164 | SPI_CR2 = 4 165 | SPI_CRCPR = 16 166 | SPI_DR = 12 167 | SPI_I2SCFGR = 28 168 | SPI_I2SPR = 32 169 | SPI_RXCRCR = 20 170 | SPI_SR = 8 171 | SPI_TXCRCR = 24 172 | SYSCFG = 1073821696 173 | SYSCFG_CMPCR = 32 174 | SYSCFG_EXTICR0 = 8 175 | SYSCFG_EXTICR1 = 12 176 | SYSCFG_EXTICR2 = 16 177 | SYSCFG_EXTICR3 = 20 178 | SYSCFG_MEMRMP = 0 179 | SYSCFG_PMC = 4 180 | TIM1 = 1073807360 181 | TIM10 = 1073824768 182 | TIM11 = 1073825792 183 | TIM2 = 1073741824 184 | TIM3 = 1073742848 185 | TIM4 = 1073743872 186 | TIM5 = 1073744896 187 | TIM9 = 1073823744 188 | TIM_ARR = 44 189 | TIM_BDTR = 68 190 | TIM_CCER = 32 191 | TIM_CCMR1 = 24 192 | TIM_CCMR2 = 28 193 | TIM_CCR1 = 52 194 | TIM_CCR2 = 56 195 | TIM_CCR3 = 60 196 | TIM_CCR4 = 64 197 | TIM_CNT = 36 198 | TIM_CR1 = 0 199 | TIM_CR2 = 4 200 | TIM_DCR = 72 201 | TIM_DIER = 12 202 | TIM_DMAR = 76 203 | TIM_EGR = 20 204 | TIM_OR = 80 205 | TIM_PSC = 40 206 | TIM_RCR = 48 207 | TIM_SMCR = 8 208 | TIM_SR = 16 209 | USART1 = 1073811456 210 | USART2 = 1073759232 211 | USART6 = 1073812480 212 | USART_BRR = 8 213 | USART_CR1 = 12 214 | USART_CR2 = 16 215 | USART_CR3 = 20 216 | USART_DR = 4 217 | USART_GTPR = 24 218 | USART_SR = 0 219 | WWDG = 1073753088 220 | WWDG_CFR = 4 221 | WWDG_CR = 0 222 | WWDG_SR = 8 223 | mem16 = None 224 | mem32 = None 225 | mem8 = None 226 | -------------------------------------------------------------------------------- /code-completion/struct.py: -------------------------------------------------------------------------------- 1 | def calcsize(): 2 | pass 3 | 4 | 5 | def pack(): 6 | pass 7 | 8 | 9 | def pack_into(): 10 | pass 11 | 12 | 13 | def unpack(): 14 | pass 15 | 16 | 17 | def unpack_from(): 18 | pass 19 | -------------------------------------------------------------------------------- /code-completion/sys.py: -------------------------------------------------------------------------------- 1 | """ 2 | sys 模块提供系统特有的功能。 3 | """ 4 | 5 | def exit(retval=0) -> None: 6 | """终止当前程序给定的退出代码。 函数会抛出 SystemExit 异常。""" 7 | ... 8 | 9 | def print_exception(exc, file=sys.stdout) -> None: 10 | """打印异常与追踪到一个类似文件的对象 file (或者缺省 sys.stdout ).""" 11 | ... 12 | 13 | def exit(retval=0) -> None: 14 | """终止当前程序给定的退出代码。 函数会抛出 SystemExit 异常。""" 15 | ... 16 | 17 | def exit(retval=0) -> None: 18 | """终止当前程序给定的退出代码。 函数会抛出 SystemExit 异常。""" 19 | ... 20 | 21 | def exit(retval=0) -> None: 22 | """终止当前程序给定的退出代码。 函数会抛出 SystemExit 异常。""" 23 | ... 24 | 25 | argv = ... # type: str 26 | byteorder = ... # type: str 27 | implementation = ... # type: tuple 28 | modules = ... # type: list 29 | path = ... # type: str 30 | platform = ... # type: str 31 | stderr = ... # type: stream 32 | stdin = ... # type: stream 33 | version = ... # type: str 34 | version_info = ... # type: str 35 | -------------------------------------------------------------------------------- /code-completion/time.py: -------------------------------------------------------------------------------- 1 | def localtime(): 2 | pass 3 | 4 | 5 | def mktime(): 6 | pass 7 | 8 | 9 | def sleep(): 10 | pass 11 | 12 | 13 | def sleep_ms(): 14 | pass 15 | 16 | 17 | def sleep_us(): 18 | pass 19 | 20 | 21 | def ticks_add(): 22 | pass 23 | 24 | 25 | def ticks_cpu(): 26 | pass 27 | 28 | 29 | def ticks_diff(): 30 | pass 31 | 32 | 33 | def ticks_ms(): 34 | pass 35 | 36 | 37 | def ticks_us(): 38 | pass 39 | 40 | 41 | def time(): 42 | pass 43 | -------------------------------------------------------------------------------- /code-completion/ubinascii.py: -------------------------------------------------------------------------------- 1 | """ 2 | ubinascii 模块包含许多在二进制和各种 ascii 编码的二进制表示之间转换的方法。 3 | """ 4 | 5 | def hexlify(data]) -> None: 6 | """ 7 | - hexlify(data[, sep]) 8 | 将字符串转换为十六进制表示的字符串。 9 | 10 | - 示例: 11 | 12 | - ubinascii.hexlify('hello RT-Thread') 13 | - b'68656c6c6f2052542d546872656164' 14 | - ubinascii.hexlify('summer') 15 | - b'73756d6d6572' 16 | 如果指定了第二个参数sep,它将用于分隔两个十六进制数。 17 | 18 | - 示例: 19 | 20 | 如果指定了第二个参数sep,它将用于分隔两个十六进制数。 21 | - ubinascii.hexlify('hello RT-Thread'," ") 22 | - b'68 65 6c 6c 6f 20 52 54 2d 54 68 72 65 61 64' 23 | - ubinascii.hexlify('hello RT-Thread',",") 24 | - b'68,65,6c,6c,6f,20,52,54,2d,54,68,72,65,61,64' 25 | """ 26 | ... 27 | 28 | def unhexlify(data) -> None: 29 | """ 30 | 转换十六进制字符串为二进制字符串,功能和 hexlify 相反。 31 | 32 | 示例: 33 | 34 | - ubinascii.unhexlify('73756d6d6572') 35 | - b'summer'""" 36 | ... 37 | 38 | def a2b_base64(data) -> None: 39 | """Base64编码的数据转换为二进制表示。返回字节串。""" 40 | ... 41 | 42 | def b2a_base64(data) -> None: 43 | """编码base64格式的二进制数据。返回的字符串。""" 44 | ... 45 | -------------------------------------------------------------------------------- /code-completion/ucollections.py: -------------------------------------------------------------------------------- 1 | """ 2 | ucollections 模块实现了专门的容器数据类型,它提供了 Python 的通用内置容器的替代方案,包括了字典、列表、集合和元组。 3 | """ 4 | 5 | class namedtuple(name, fields): 6 | """ 7 | 这是工厂函数创建一个新的 namedtuple 型与一个特定的字段名称和集合。namedtuple 是元组允许子类要访问它的字段不仅是数字索引,而且还具有属性使用符号字段名访问语法。 字段是字符串序列指定字段名称。为了兼容的实现也可以用空间分隔的字符串命名的字段(但效率较低) 。 8 | 代码示例: 9 | 10 | - from ucollections import namedtuple 11 | - MyTuple = namedtuple("MyTuple", ("id", "name")) 12 | - t1 = MyTuple(1, "foo") 13 | - t2 = MyTuple(2, "bar") 14 | - print(t1.name) 15 | - assert t2.name == t2[1] 16 | - ucollections.OrderedDict(...) 17 | """ 18 | ... 19 | 20 | class OrderedDict(...): 21 | """ 22 | 字典类型的子类,会记住并保留键/值的追加顺序。当有序的字典被迭代输出时,键/值 会按照他们被添加的顺序返回 : 23 | from ucollections import OrderedDict 24 | 25 | # To make benefit of ordered keys, OrderedDict should be initialized 26 | # from sequence of (key, value) pairs. 27 | - d = OrderedDict([("z", 1), ("a", 2)]) 28 | # More items can be added as usual 29 | - d["w"] = 5 30 | - d["b"] = 3 31 | - for k, v in d.items(): 32 | - print(k, v) 33 | 输出: 34 | 35 | - z 1 a 2 w 5 b 3 36 | """ 37 | ... 38 | -------------------------------------------------------------------------------- /code-completion/uctypes.py: -------------------------------------------------------------------------------- 1 | """ 2 | uctypes 模块用来访问二进制数据结构,它提供 C 兼容的数据类型。 3 | """ 4 | 5 | LITTLE_ENDIAN = ... # type: int 6 | BIG_ENDIAN = ... # type: int 7 | NATIVE = ... # type: int 8 | 9 | class struct(addr, descriptor, type): 10 | """ 11 | 将内存中以 c 形式打包的结构体或联合体转换为字典,并返回该字典。 12 | 13 | - addr:开始转换的地址 14 | - descriptor:转换描述符 15 | 格式:"field_name":offset|uctypes.UINT32 16 | - offset:偏移量, 17 | 单位:字节、VOID、UINT8、INT8、UINT16、INT16、UINT32、INT32、UINT64、INT64、BFUINT8、BFINT8、BFUINT16、BFINT16、BFUINT32、BFINT32、BF_POS、BF_LEN、FLOAT32、FLOAT64、PTR、ARRAY 18 | - type:c 结构体或联合体存储类型,默认为本地存储类型 19 | 示例: 20 | 21 | - a = b"0123" 22 | - s = uctypes.struct(uctypes.addressof(a), {"a": uctypes.UINT8 | 0, "b": uctypes.UINT16 | 1}, uctypes.LITTLE_ENDIAN) 23 | - print(s) 24 | - 25 | - print(s.a) 26 | - 48 27 | - s.a = 49 28 | - print(a) 29 | - b'1123' 30 | """ 31 | def __init__(self) -> None: 32 | ... 33 | 34 | def sizeof(self, struct) -> None: 35 | """ 36 | 按字节返回数据的大小。参数可以是类或者数据对象 (或集合)。 示例: 37 | 38 | - a = b"0123" 39 | - b = uctypes.struct(uctypes.addressof(a), {"a": uctypes.UINT8 | 0, "b": uctypes.UINT16 | 1}, uctypes.LITTLE_ENDIAN) 40 | - b.a 41 | - 48 42 | - print(uctypes.sizeof(b)) 43 | - 3 44 | """ 45 | ... 46 | 47 | def addressof(self, obj) -> None: 48 | """ 49 | 返回对象地址。参数需要是 bytes, bytearray 。 示例: 50 | 51 | - a = b"0123" 52 | - print(uctypes.addressof(a)) 53 | - 1073504048 54 | """ 55 | ... 56 | 57 | def bytes_at(self, addr, size)-> None: 58 | """ 59 | 捕捉从 addr 开始到 size 个地址偏移量结束的内存数据为 bytearray 对象并返回。 示例: 60 | 61 | - a = b"0123" 62 | - print( uctypes.bytes_at(uctypes.addressof(a), 4)) 63 | - b'0123' 64 | """ 65 | ... 66 | 67 | def bytearray_at(self, addr, size) -> None: 68 | """ 69 | 捕捉给定大小和地址内存为 bytearray 对象。与 bytes_at() 函数不同的是,它可以被再次写入,可以访问给定地址的参数。 示例: 70 | 71 | - a = b"0123" 72 | - print(uctypes.bytearray_at(uctypes.addressof(a), 2)) 73 | - bytearray(b'01') 74 | """ 75 | ... 76 | 77 | 78 | -------------------------------------------------------------------------------- /code-completion/uerrno.py: -------------------------------------------------------------------------------- 1 | """ 2 | uerrno 模块提供了标准的 errno 系统符号,每个符号都有对应的整数值。 3 | """ 4 | 5 | errorcode = ... # type: int 6 | EEXIST = ... # type: int 7 | EAGAIN = ... # type: int 8 | -------------------------------------------------------------------------------- /code-completion/uhashlib.py: -------------------------------------------------------------------------------- 1 | """ 2 | uhashlib 模块实现了二进制数据哈希算法。 3 | """ 4 | 5 | SHA256 = ... # type: int 6 | SHA1 = ... # type: int 7 | MD5 = ... # type: int 8 | 9 | class sha256(data): 10 | """ 11 | - sha256([data]) 12 | 创建一个SHA256哈希对象并提供 data 赋值。 13 | """ 14 | 15 | def __init__(self) -> None: 16 | ... 17 | 18 | def update(self, data) -> None: 19 | """将更多二进制数据放入哈希表中。""" 20 | ... 21 | 22 | def digest(self) -> None: 23 | """返回字节对象哈希的所有数据。调用此方法后,将无法将更多数据送入哈希。""" 24 | ... 25 | 26 | def hexdigest(self) -> None: 27 | """此方法没有实现, 使用 ubinascii.hexlify(hash.digest()) 达到类似效果。""" 28 | ... 29 | 30 | class sha1(data): 31 | """ 32 | - sha1([data]) 33 | 创建一个SHA1哈希对象并提供 data 赋值。 34 | """ 35 | 36 | def __init__(self) -> None: 37 | ... 38 | 39 | def update(self, data) -> None: 40 | """将更多二进制数据放入哈希表中。""" 41 | ... 42 | 43 | def digest(self) -> None: 44 | """返回字节对象哈希的所有数据。调用此方法后,将无法将更多数据送入哈希。""" 45 | ... 46 | 47 | def hexdigest(self) -> None: 48 | """此方法没有实现, 使用 ubinascii.hexlify(hash.digest()) 达到类似效果。""" 49 | ... 50 | 51 | 52 | class md5(data): 53 | """ 54 | - md5([data]) 55 | 创建一个MD5哈希对象并提供 data 赋值。 56 | """ 57 | 58 | def __init__(self) -> None: 59 | ... 60 | 61 | def update(self, data) -> None: 62 | """将更多二进制数据放入哈希表中。""" 63 | ... 64 | 65 | def digest(self) -> None: 66 | """返回字节对象哈希的所有数据。调用此方法后,将无法将更多数据送入哈希。""" 67 | ... 68 | 69 | def hexdigest(self) -> None: 70 | """此方法没有实现, 使用 ubinascii.hexlify(hash.digest()) 达到类似效果。""" 71 | ... 72 | -------------------------------------------------------------------------------- /code-completion/uheapq.py: -------------------------------------------------------------------------------- 1 | """ 2 | uheapq 模块提供了堆排序相关算法,堆队列是一个列表,它的元素以特定的方式存储。 3 | """ 4 | 5 | def heappush(heap, item) -> None: 6 | """将对象压入堆中。""" 7 | ... 8 | 9 | def heappop(heap) -> None: 10 | """从 heap 弹出第一个元素并返回。 如果是堆时空的会抛出 IndexError。""" 11 | ... 12 | 13 | def heapify(x) -> None: 14 | """将列表 x 转换成堆。""" 15 | ... 16 | -------------------------------------------------------------------------------- /code-completion/uio.py: -------------------------------------------------------------------------------- 1 | """ 2 | uio 模块包含流类型 (类似文件) 对象和帮助函数。 3 | """ 4 | 5 | def open(name, mode='r', **kwargs) -> None: 6 | """打开一个文件,关联到内建函数open()。所有端口 (用于访问文件系统) 需要支持模式参数,但支持其他参数不同的端口。""" 7 | ... 8 | 9 | class FileIO(...): 10 | """这个文件类型用二进制方式打开文件,等于使用open(name, “rb”)。 不应直接使用这个实例。""" 11 | ... 12 | 13 | class TextIOWrapper(...): 14 | """这个类型以文本方式打开文件,等同于使用open(name, “rt”)不应直接使用这个实例。""" 15 | ... 16 | 17 | class StringIO(string): 18 | """这个类型以文本方式打开文件,等同于使用open(name, “rt”)不应直接使用这个实例。""" 19 | ... 20 | 21 | class BytesIO(string): 22 | """ 23 | 内存文件对象。StringIO 用于文本模式 I/O (用 “t” 打开文件),BytesIO 用于二进制方式 (用 “b” 方式)。 24 | 文件对象的初始内容可以用字符串参数指定(stringio用普通字符串,bytesio用bytes对象)。 25 | 所有的文件方法,如 read(), write(), seek(), flush(), close() 都可以用在这些对象上。 26 | """ 27 | def __init__(self) -> None: 28 | ... 29 | 30 | def getvalue(self) -> None: 31 | """获取缓存区内容。""" 32 | ... 33 | -------------------------------------------------------------------------------- /code-completion/ujson.py: -------------------------------------------------------------------------------- 1 | """ 2 | ujson 模块提供 Python 对象到 JSON(JavaScript Object Notation) 数据格式的转换。 3 | """ 4 | 5 | def dumps(obj) -> str: 6 | return str 7 | """ 8 | 将 dict 类型转换成 str。 9 | 10 | - obj:要转换的对象 11 | 12 | 示例: 13 | 14 | - obj = {1:2, 3:4, "a":6} 15 | - print(type(obj), obj) #原来为dict类型 16 | - {3: 4, 1: 2, 'a': 6} 17 | - jsObj = json.dumps(obj) #将dict类型转换成str 18 | - print(type(jsObj), jsObj) 19 | - {3: 4, 1: 2, "a": 6}""" 20 | ... 21 | 22 | def loads(str) -> obj: 23 | return obj 24 | """ 25 | 解析 JSON 字符串并返回对象。如果字符串格式错误将引发 ValueError 异常。 26 | 27 | 示例: 28 | 29 | - obj = {1:2, 3:4, "a":6} 30 | - jsDumps = json.dumps(obj) 31 | - jsLoads = json.loads(jsDumps) 32 | - print(type(obj), obj) 33 | - {3: 4, 1: 2, 'a': 6} 34 | - print(type(jsDumps), jsDumps) 35 | - {3: 4, 1: 2, "a": 6} 36 | - print(type(jsLoads), jsLoads) 37 | - {'a': 6, 1: 2, 3: 4} 38 | """ 39 | ... 40 | 41 | -------------------------------------------------------------------------------- /code-completion/umachine.py: -------------------------------------------------------------------------------- 1 | DEEPSLEEP_RESET = 4 2 | HARD_RESET = 2 3 | 4 | 5 | class I2C: 6 | "" 7 | 8 | def init(): 9 | pass 10 | 11 | def readfrom(): 12 | pass 13 | 14 | def readfrom_into(): 15 | pass 16 | 17 | def readfrom_mem(): 18 | pass 19 | 20 | def readfrom_mem_into(): 21 | pass 22 | 23 | def readinto(): 24 | pass 25 | 26 | def scan(): 27 | pass 28 | 29 | def start(): 30 | pass 31 | 32 | def stop(): 33 | pass 34 | 35 | def write(): 36 | pass 37 | 38 | def writeto(): 39 | pass 40 | 41 | def writeto_mem(): 42 | pass 43 | 44 | 45 | PWRON_RESET = 1 46 | 47 | 48 | class Pin: 49 | "" 50 | AF1_TIM1 = 1 51 | AF1_TIM2 = 1 52 | AF2_TIM3 = 2 53 | AF2_TIM4 = 2 54 | AF2_TIM5 = 2 55 | AF3_TIM10 = 3 56 | AF3_TIM11 = 3 57 | AF3_TIM9 = 3 58 | AF4_I2C1 = 4 59 | AF4_I2C3 = 4 60 | AF5_SPI1 = 5 61 | AF5_SPI2 = 5 62 | AF7_USART1 = 7 63 | AF7_USART2 = 7 64 | AF8_USART6 = 8 65 | AF9_I2C3 = 9 66 | AF_OD = 18 67 | AF_PP = 2 68 | ALT = 2 69 | ALT_OPEN_DRAIN = 18 70 | ANALOG = 3 71 | IN = 0 72 | IRQ_FALLING = 270598144 73 | IRQ_RISING = 269549568 74 | OPEN_DRAIN = 17 75 | OUT = 1 76 | OUT_OD = 17 77 | OUT_PP = 1 78 | PULL_DOWN = 2 79 | PULL_NONE = 0 80 | PULL_UP = 1 81 | 82 | def af(): 83 | pass 84 | 85 | def af_list(): 86 | pass 87 | 88 | board = None 89 | cpu = None 90 | 91 | def debug(): 92 | pass 93 | 94 | def dict(): 95 | pass 96 | 97 | def gpio(): 98 | pass 99 | 100 | def high(): 101 | pass 102 | 103 | def init(): 104 | pass 105 | 106 | def irq(): 107 | pass 108 | 109 | def low(): 110 | pass 111 | 112 | def mapper(): 113 | pass 114 | 115 | def mode(): 116 | pass 117 | 118 | def name(): 119 | pass 120 | 121 | def names(): 122 | pass 123 | 124 | def off(): 125 | pass 126 | 127 | def on(): 128 | pass 129 | 130 | def pin(): 131 | pass 132 | 133 | def port(): 134 | pass 135 | 136 | def pull(): 137 | pass 138 | 139 | def value(): 140 | pass 141 | 142 | 143 | SOFT_RESET = 0 144 | 145 | 146 | class SPI: 147 | "" 148 | LSB = 128 149 | MSB = 0 150 | 151 | def deinit(): 152 | pass 153 | 154 | def init(): 155 | pass 156 | 157 | def read(): 158 | pass 159 | 160 | def readinto(): 161 | pass 162 | 163 | def write(): 164 | pass 165 | 166 | def write_readinto(): 167 | pass 168 | 169 | 170 | class Signal: 171 | "" 172 | 173 | def off(): 174 | pass 175 | 176 | def on(): 177 | pass 178 | 179 | def value(): 180 | pass 181 | 182 | 183 | class UART: 184 | "" 185 | CTS = 512 186 | RTS = 256 187 | 188 | def any(): 189 | pass 190 | 191 | def deinit(): 192 | pass 193 | 194 | def init(): 195 | pass 196 | 197 | def read(): 198 | pass 199 | 200 | def readchar(): 201 | pass 202 | 203 | def readinto(): 204 | pass 205 | 206 | def readline(): 207 | pass 208 | 209 | def sendbreak(): 210 | pass 211 | 212 | def write(): 213 | pass 214 | 215 | def writechar(): 216 | pass 217 | 218 | 219 | class WDT: 220 | "" 221 | 222 | def feed(): 223 | pass 224 | 225 | 226 | WDT_RESET = 3 227 | 228 | 229 | def bootloader(): 230 | pass 231 | 232 | 233 | def deepsleep(): 234 | pass 235 | 236 | 237 | def disable_irq(): 238 | pass 239 | 240 | 241 | def enable_irq(): 242 | pass 243 | 244 | 245 | def freq(): 246 | pass 247 | 248 | 249 | def idle(): 250 | pass 251 | 252 | 253 | def info(): 254 | pass 255 | 256 | 257 | mem16 = None 258 | mem32 = None 259 | mem8 = None 260 | 261 | 262 | def reset(): 263 | pass 264 | 265 | 266 | def reset_cause(): 267 | pass 268 | 269 | 270 | def sleep(): 271 | pass 272 | 273 | 274 | def soft_reset(): 275 | pass 276 | 277 | 278 | def time_pulse_us(): 279 | pass 280 | 281 | 282 | def unique_id(): 283 | pass 284 | -------------------------------------------------------------------------------- /code-completion/umqtt/simple.py: -------------------------------------------------------------------------------- 1 | class MQTTException(Exception): 2 | ... 3 | 4 | class MQTTClient: 5 | def __init__(self, client_id, server, port=0, user=None, password=None, keeyalive=0, ssl=False, ssl_params={}): 6 | """ 7 | Create a mqtt client object. 8 | 9 | - client_id 10 | - server 11 | - port 12 | - user 13 | - password 14 | - keeyalive 15 | - ssl 16 | - ssl_params 17 | """ 18 | ... 19 | 20 | def connect(self, clean_session=True): 21 | """ 22 | Connect to mqtt server. 23 | 24 | - clean_session: 25 | """ 26 | ... 27 | 28 | def set_callback(self, f): 29 | """ 30 | set_callback 31 | 32 | - f 33 | """ 34 | ... 35 | 36 | def set_last_will(self, topic, msg, retain=False, qos=0): 37 | """ 38 | set_last_will 39 | 40 | - topic 41 | - msg 42 | - retain 43 | - qos 44 | """ 45 | ... 46 | 47 | def disconnect(self): 48 | """ 49 | Disconnect from mqtt server. 50 | """ 51 | ... 52 | 53 | def ping(self): 54 | """ 55 | Send ping to mqtt server. 56 | """ 57 | ... 58 | 59 | def publish(self, topic, msg, retain=False, qos=0): 60 | """ 61 | publish 62 | 63 | - topic 64 | - msg 65 | - retain 66 | - qos 67 | """ 68 | ... 69 | 70 | def subscribe(self, topic, qos=0): 71 | """ 72 | subscribe 73 | 74 | - topic 75 | - qos 76 | """ 77 | ... 78 | 79 | def wait_msg(self): 80 | """ 81 | Wait for message, socket blocked 82 | """ 83 | ... 84 | 85 | def check_msg(self): 86 | """ 87 | Check message, socket none blocked 88 | """ 89 | ... 90 | -------------------------------------------------------------------------------- /code-completion/uos.py: -------------------------------------------------------------------------------- 1 | """ 2 | uos 模块包含了对文件系统的访问操作,是对应 CPython 模块的一个子集。 3 | """ 4 | 5 | def chdir(path) -> None: 6 | """更改当前目录。""" 7 | ... 8 | 9 | def getcwd() -> None: 10 | """获取当前目录。""" 11 | ... 12 | 13 | def listdir(dir : str = None) -> None: 14 | """没有参数就列出当前目录,否则列出给定目录。""" 15 | ... 16 | 17 | def mkdir(path : str) -> None: 18 | """创建一个目录。""" 19 | ... 20 | 21 | def remove(path : str) -> None: 22 | """删除文件。""" 23 | ... 24 | 25 | def rmdir(path : str) -> None: 26 | """删除目录。""" 27 | ... 28 | 29 | def rename(old_path : str, new_path : str) -> None: 30 | """重命名文件或者文件夹。""" 31 | ... 32 | 33 | def stat(path : str) -> None: 34 | """获取文件或目录的状态。""" 35 | ... 36 | 37 | def sync() -> None: 38 | """同步所有的文件系统。""" 39 | ... 40 | 41 | def mkfs(fs_type : str, dev_name : str) -> None: 42 | """在指定的设备上创建 fs_type 类型的文件系统。example: os.mkfs("elm", "fs")""" 43 | ... 44 | -------------------------------------------------------------------------------- /code-completion/urandom.py: -------------------------------------------------------------------------------- 1 | """ 2 | urandom 模块实现了伪随机数生成器。 3 | """ 4 | 5 | def choice(obj) -> None: 6 | """ 7 | 随机生成对象 obj 中的元数。 8 | 9 | - obj:元数列表 10 | 11 | 示例: 12 | 13 | - print(random.choice("DFRobot")) 14 | - R 15 | - print(random.choice("DFRobot")) 16 | - D 17 | - print(random.choice([0, 2, 4, 3])) 18 | - 3 19 | - print(random.choice([0, 2, 4, 3])) 20 | - 3 21 | - print(random.choice([0, 2, 4, 3])) 22 | - 2 23 | """ 24 | ... 25 | 26 | def getrandbits(size) -> None: 27 | """ 28 | 随机生成 0 到 size 个位二进制数范围内的正整数。 比如 : 29 | 30 | - size = 4,那么便是从 0 到0b1111中随机一个正整数。 31 | - size = 8,那么便是从 0 到 0b11111111中随机一个正整数。 32 | - size:位大小 33 | 34 | 示例: 35 | 36 | - print( random.getrandbits(1)) #1位二进制位,范围为0~1(十进制:0~1) 37 | - 1 38 | - print(random.getrandbits(1)) 39 | - 0 40 | - print(random.getrandbits(8)) #8位二进制位,范围为0000 0000~1111 11111(十进制:0~255) 41 | - 224 42 | - print(random.getrandbits(8)) 43 | - 155 44 | """ 45 | ... 46 | 47 | def randint(start, end) -> None: 48 | """ 49 | 随机生成一个 start 到 end 之间的整数。 50 | 51 | start:指定范围内的开始值,包含在范围内 52 | end:指定范围内的结束值,包含在范围内 53 | 示例: 54 | 55 | - import random 56 | - print(random.randint(1, 4)) 57 | - 4 58 | - print(random.randint(1, 4)) 59 | - 2 60 | """ 61 | ... 62 | 63 | def random() -> None: 64 | """ 65 | 随机生成一个 0 到 1 之间的浮点数。 示例: 66 | 67 | - print(random.random()) 68 | - 0.7111824 69 | - print(random.random()) 70 | - 0.3168149 71 | """ 72 | ... 73 | 74 | 75 | def randrange(start, end, step) -> None: 76 | """ 77 | 随机生成 start 到 end 并且递增为 step 的范围内的正整数。例如,randrange(0, 8, 2)中,随机生成的数为 0、2、4、6 中任一个。 78 | 79 | - start:指定范围内的开始值,包含在范围内 80 | - end:指定范围内的结束值,包含在范围内 81 | - step:递增基数 82 | 83 | 示例: 84 | 85 | - print(random.randrange(2, 8, 2)) 86 | - 4 87 | - print(random.randrange(2, 8, 2)) 88 | - 6 89 | - print(random.randrange(2, 8, 2)) 90 | - 2 91 | """ 92 | ... 93 | 94 | def seed(sed) -> None: 95 | """ 96 | 指定随机数种子,通常和其他随机数生成函数搭配使用。 97 | 注意: MicroPython 中的随机数其实是一个稳定算法得出的稳定结果序列,而不是一个随机序列。 98 | sed 就是这个算法开始计算的第一个值。 99 | 所以就会出现只要 sed 是一样的,那么后续所有“随机”结果和顺序也都完全一致。 100 | """ 101 | ... 102 | 103 | def uniform(start, end) -> None: 104 | """ 105 | 随机生成start到end之间的浮点数。 106 | 107 | - start:指定范围内的开始值,包含在范围内 108 | - stop:指定范围内的结束值,包含在范围内 109 | 110 | 示例: 111 | 112 | - print(random.uniform(2, 4)) 113 | - 2.021441 114 | - print(random.uniform(2, 4)) 115 | - 3.998012 116 | """ 117 | ... 118 | -------------------------------------------------------------------------------- /code-completion/ure.py: -------------------------------------------------------------------------------- 1 | """ 2 | ure 模块用于测试字符串的某个模式,执行正则表达式操作。 3 | """ 4 | 5 | DEBUG = ... # type: int 6 | 7 | class compile(...): 8 | """ 9 | - compile(regex_str[, flags]) 10 | 编译正则表达式,返回 regex 对象。 11 | """ 12 | ... 13 | 14 | def __init__(self) -> None: 15 | ... 16 | 17 | def match(self, string) -> None: 18 | """用 string 匹配 regex,匹配总是从字符串的开始匹配。""" 19 | ... 20 | 21 | def search(self, string) -> None: 22 | """在 string 中搜索 regex。不同于匹配,它搜索第一个匹配位置的正则表达式字符串 (结果可能会是0)。""" 23 | ... 24 | 25 | def sub(self, replace, string, count, flags) -> None: 26 | """Compile regex_str and search for it in string, replacing all matches with replace, and returning the new string.""" 27 | ... 28 | 29 | def split(self) -> None: 30 | """获取缓存区内容。""" 31 | ... 32 | 33 | class match(...): 34 | """ 35 | - Match objects as returned by match() and search() methods。 36 | """ 37 | ... 38 | 39 | def __init__(self) -> None: 40 | ... 41 | 42 | def group(self, index) -> None: 43 | """用 string 匹配 regex,匹配总是从字符串的开始匹配。""" 44 | ... 45 | 46 | def groups(self) -> None: 47 | """在 string 中搜索 regex。不同于匹配,它搜索第一个匹配位置的正则表达式字符串 (结果可能会是0)。""" 48 | ... 49 | 50 | def start(self, index) -> None: 51 | """start([index])""" 52 | ... 53 | 54 | def end(self, index) -> None: 55 | """end([index]) 56 | Return the index in the original string of the start or end of the substring group that was matched. index defaults to the entire group, otherwise it will select a group. 57 | """ 58 | ... 59 | 60 | def span(self) -> None: 61 | """Returns the 2-tuple (match.start(index), match.end(index)).""" 62 | ... 63 | 64 | class search(...): 65 | """ 66 | - Match objects as returned by match() and search() methods。 67 | """ 68 | ... 69 | 70 | def __init__(self) -> None: 71 | ... 72 | 73 | def group(self, index) -> None: 74 | """用 string 匹配 regex,匹配总是从字符串的开始匹配。""" 75 | ... 76 | 77 | def groups(self) -> None: 78 | """在 string 中搜索 regex。不同于匹配,它搜索第一个匹配位置的正则表达式字符串 (结果可能会是0)。""" 79 | ... 80 | 81 | def start(self, index) -> None: 82 | """start([index])""" 83 | ... 84 | 85 | def end(self, index) -> None: 86 | """end([index]) 87 | Return the index in the original string of the start or end of the substring group that was matched. index defaults to the entire group, otherwise it will select a group. 88 | """ 89 | ... 90 | 91 | def span(self) -> None: 92 | """Returns the 2-tuple (match.start(index), match.end(index)).""" 93 | ... 94 | 95 | def match(regex, string) -> None: 96 | """用 string 匹配 regex,匹配总是从字符串的开始匹配。""" 97 | ... 98 | 99 | def search(regex, string) -> None: 100 | """在 string 中搜索 regex。不同于匹配,它搜索第一个匹配位置的正则表达式字符串 (结果可能会是0)。""" 101 | ... 102 | 103 | def sub(regex_str, replace, string, count, flags) -> None: 104 | """Compile regex_str and search for it in string, replacing all matches with replace, and returning the new string.""" 105 | ... 106 | 107 | -------------------------------------------------------------------------------- /code-completion/urequests.py: -------------------------------------------------------------------------------- 1 | class Response: 2 | def __init__(self, raw): 3 | """ 4 | Initialize object 5 | 6 | - None 7 | """ 8 | ... 9 | 10 | def close(self): 11 | """ 12 | Close 13 | 14 | - None 15 | """ 16 | ... 17 | 18 | def content(self): 19 | """ 20 | Content 21 | 22 | - None 23 | """ 24 | ... 25 | 26 | def text(self): 27 | """ 28 | Text 29 | 30 | - None 31 | """ 32 | ... 33 | 34 | def json(self): 35 | """ 36 | Json 37 | 38 | - None 39 | """ 40 | ... 41 | 42 | 43 | def request(method, url, data=None, json=None, headers={}, stream=None, timeout=None): 44 | """ 45 | Request 46 | 47 | - method 48 | - url 49 | - data 50 | - json 51 | - headers 52 | - stream 53 | """ 54 | ... 55 | 56 | 57 | def head(url, **kw): 58 | """ 59 | Head 60 | 61 | - url 62 | - **kw 63 | """ 64 | ... 65 | 66 | def get(url, **kw): 67 | """ 68 | Get 69 | 70 | - url 71 | - **kw 72 | """ 73 | ... 74 | 75 | def post(url, **kw): 76 | """ 77 | Post 78 | 79 | - url 80 | - **kw 81 | """ 82 | ... 83 | 84 | def put(url, **kw): 85 | """ 86 | Put 87 | 88 | - url 89 | - **kw 90 | """ 91 | ... 92 | 93 | def patch(url, **kw): 94 | """ 95 | Patch 96 | 97 | - url 98 | - **kw 99 | """ 100 | ... 101 | 102 | def delete(url, **kw): 103 | """ 104 | Delete 105 | 106 | - url 107 | - **kw 108 | """ 109 | ... 110 | -------------------------------------------------------------------------------- /code-completion/uselect.py: -------------------------------------------------------------------------------- 1 | POLLERR = 8 2 | POLLHUP = 16 3 | POLLIN = 1 4 | POLLOUT = 4 5 | 6 | 7 | def poll(): 8 | pass 9 | 10 | 11 | def select(): 12 | pass 13 | -------------------------------------------------------------------------------- /code-completion/usocket.py: -------------------------------------------------------------------------------- 1 | """ 2 | usocket 模块提供对BSD套接字接口的访问。 3 | """ 4 | 5 | AF_INET = ... # type: int 6 | AF_INET6 = ... # type: int 7 | 8 | SOCK_STREAM = ... # type: int 9 | SOCK_DGRAM = ... # type: int 10 | SOCK_RAW = ... # type: int 11 | SO_REUSEADDR = ... # type: int 12 | 13 | IPPROTO_TCP = ... # type: int 14 | IPPROTO_UDP = ... # type: int 15 | 16 | 17 | class socket(object): 18 | 19 | def __init__(self, family, type, protocol = socket.IPPROTO_TCP) -> None: 20 | """ 21 | 创建新的套接字,使用指定的地址、类型和协议号。 22 | - usocket.socket(usocket.AF_INET,usocket.SOCK_STREAM) 23 | """ 24 | ... 25 | 26 | def getaddrinfo(self, host, port) -> None: 27 | return tuple 28 | """ 29 | 将主机域名(host)和端口(port)转换为用于创建套接字的5元组序列。元组列表的结构如下: 30 | 31 | - (family, type, proto, canonname, sockaddr) 32 | 示例: 33 | 34 | - info = socket.getaddrinfo("rt-thread.org", 10000) 35 | - print(info) 36 | - [(2, 1, 0, '', ('118.31.15.152', 10000))] 37 | """ 38 | ... 39 | 40 | def close(self) -> None: 41 | """关闭套接字。一旦关闭后,套接字所有的功能都将失效。远端将接收不到任何数据 (清理队列数据后)。 虽然在垃圾回收时套接字会自动关闭,但还是推荐在必要时用 close() 去关闭。""" 42 | ... 43 | 44 | def bind(self, address) -> None: 45 | """将套接字绑定到地址,套接字不能是已经绑定的。""" 46 | ... 47 | 48 | def listen(self, backlog) -> None: 49 | """ 50 | listen([backlog]) 51 | 监听套接字,使服务器能够接收连接。 52 | backlog:接受套接字的最大个数,至少为0,如果没有指定,则默认一个合理值。 53 | """ 54 | ... 55 | 56 | def accept(self) -> None: 57 | return conn, address 58 | """ 59 | 接收连接请求。 注意: 只能在绑定地址端口号和监听后调用,返回 conn 和 address。 60 | 61 | - conn:新的套接字对象,可以用来收发消息 62 | - address:连接到服务器的客户端地址 63 | """ 64 | ... 65 | 66 | def connect(self, address : tuple) -> None: 67 | """ 68 | 连接服务器。 69 | 70 | - address:服务器地址和端口号的元组或列表 71 | """ 72 | ... 73 | 74 | def send(self, bytes) -> None: 75 | return size 76 | """ 77 | 发送数据,并返回成功发送的字节数,返回字节数可能比发送的数据长度少。 78 | 79 | - bytes:bytes类型数据 80 | """ 81 | ... 82 | 83 | def recv(self, bufsize) -> None: 84 | return obj 85 | """ 86 | 接收数据,返回接收到的数据对象。 87 | 88 | - bufsize:指定一次接收的最大数据量 89 | 示例: 90 | 91 | - data = conn.recv(1024) 92 | """ 93 | ... 94 | 95 | def sendto(self, bytes, address) -> None: 96 | return size 97 | """ 98 | 送数据,目标由address决定,常用于UDP通信,返回发送的数据大小。 99 | 100 | - bytes:bytes类型数据 101 | - address:目标地址和端口号的元组 102 | 103 | 示例: 104 | 105 | - data = sendto("hello RT-Thread", ("192.168.10.110", 100)) 106 | """ 107 | ... 108 | 109 | def recvfrom(self, bufsize) -> None: 110 | return size 111 | """ 112 | 接收数据,常用于UDP通信,并返回接收到的数据对象和对象的地址。 113 | 114 | - bufsize:指定一次接收的最大数据量 115 | 示例: 116 | 117 | - data,addr=fd.recvfrom(1024) 118 | """ 119 | ... 120 | 121 | def setsockopt(self, level, optname, value) -> None: 122 | return status 123 | """ 124 | 根据选项值设置套接字。 125 | 126 | - level:套接字选项级别 127 | - optname:套接字的选项 128 | - value:可以是一个整数,也可以是一个表示缓冲区的bytes类对象。 129 | 示例: 130 | 131 | - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 132 | """ 133 | ... 134 | 135 | def settimeout(self, value) -> None: 136 | return status 137 | """ 138 | 设置超时时间,单位:秒。 示例: 139 | 140 | s.settimeout(2) 141 | """ 142 | ... 143 | 144 | def setblocking(self, flag) -> None: 145 | return status 146 | """ 147 | 设置阻塞或非阻塞模式: 如果 flag 是 false,设置非阻塞模式。 148 | """ 149 | ... 150 | 151 | def read(self, size) -> None: 152 | return size 153 | """ 154 | - read([size]) 155 | Read up to size bytes from the socket. 156 | Return a bytes object. If size is not given, it reads all data available from the socket until EOF; 157 | as such the method will not return until the socket is closed. This function tries to read as much data as requested (no “short reads”). 158 | This may be not possible with non-blocking socket though, and then less data will be returned. 159 | """ 160 | ... 161 | 162 | def readinto(self, buf) -> None: 163 | return size 164 | """ 165 | readinto(buf[, nbytes]) 166 | Read bytes into the buf. 167 | If nbytes is specified then read at most that many bytes. 168 | Otherwise, read at most len(buf) bytes. 169 | Just as read(), this method follows “no short reads” policy. 170 | Return value: number of bytes read and stored into buf. 171 | """ 172 | ... 173 | 174 | def readline(self) -> None: 175 | return obj 176 | """ 177 | 接收一行数据,遇换行符结束,并返回接收数据的对象 。 178 | """ 179 | ... 180 | 181 | def write(self, buf) -> None: 182 | return size 183 | """ 184 | 将字节类型数据写入套接字,并返回写入成功的数据大小。 185 | """ 186 | ... 187 | 188 | -------------------------------------------------------------------------------- /code-completion/ussl.py: -------------------------------------------------------------------------------- 1 | CERT_NONE = ... 2 | CERT_OPTIONAL = ... 3 | CERT_REQUIRED = ... 4 | 5 | def wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None): 6 | """ 7 | Wrap socket 8 | 9 | - sock 10 | - server_side 11 | - keyfile 12 | - certfile 13 | - cert_reqs 14 | - ca_certs 15 | """ 16 | ... 17 | -------------------------------------------------------------------------------- /code-completion/ustruct.py: -------------------------------------------------------------------------------- 1 | """ 2 | 打包和解包原始数据类型。 3 | ustruct 模块在 Python 值和以 Python 字节对象表示的 C 结构之间执行转换。 4 | 支持 size/byte 的前缀: @, <, >, !. 5 | 支持的格式代码: b, B, h, H, i, I, l, L, q, Q, s, P, f, d (最后2个需要支持浮点数). 6 | """ 7 | 8 | def calcsize(fmt) -> None: 9 | """ 10 | 返回存放某一类型数据 fmt 需要的字节数。 11 | - fmt:数据类型 12 | - b — 字节型 13 | - B — 无符号字节型 14 | - h — 短整型 15 | - H — 无符号短整型 16 | - i — 整型 17 | - I — 无符号整型 18 | - l — 整型 19 | - L — 无符号整型 20 | - q — 长整型 21 | - Q — 无符号长整型 22 | - f — 浮点型 23 | - d — 双精度浮点型 24 | - P — 无符号型 25 | 示例: 26 | 27 | - print(struct.calcsize("i")) 28 | - 4 29 | - print(struct.calcsize("B")) 30 | - 1 31 | """ 32 | ... 33 | 34 | def pack(fmt, v1, v2, ...) -> None: 35 | """ 36 | 按照格式字符串 fmt 打包参数 v1, v2, ... 。返回值是参数打包后的字节对象。 37 | fmt:同 calcsize。 38 | 示例: 39 | 40 | - struct.pack("ii", 3, 2) 41 | - b'\x03\x00\x00\x00\x02\x00\x00\x00' 42 | - ustruct.unpack(fmt, data) 43 | 从 fmt 中解包数据。返回值是解包后参数的元组。 44 | 45 | data:要解压的字节对象。 46 | 示例: 47 | - buf = struct.pack("bb", 1, 2) 48 | - print(buf) 49 | - b'\x01\x02' 50 | - print(struct.unpack("bb", buf)) 51 | - (1, 2) 52 | """ 53 | ... 54 | 55 | def pack_into(fmt, buffer, offset, v1, v2, ...) -> None: 56 | """按照格式字符串 fmt 压缩参数 v1, v2, ... 到缓冲区 buffer,开始位置是 offset。当offset 为负数时,从缓冲区末尾开始计数。""" 57 | ... 58 | 59 | def unpack_from(fmt, data, offset=0) -> None: 60 | """ 61 | 以 fmt 作为规则从 data 的 offset 位置开始解包数据,如果 offset 是负数就是从缓冲区末尾开始计算。 62 | 返回值是解包后的参数元组。 63 | - buf = struct.pack("bb", 1, 2) 64 | - print(struct.unpack("bb", buf)) 65 | - (1, 2) 66 | - print(struct.unpack_from("b", buf, 1)) 67 | - (2,) 68 | """ 69 | ... 70 | -------------------------------------------------------------------------------- /code-completion/utime.py: -------------------------------------------------------------------------------- 1 | """ 2 | utime 模块提供获取当前时间和日期、测量时间间隔和延迟的功能。 3 | """ 4 | 5 | from typing import Any, Dict, List, Optional, Sequence, Tuple, Union 6 | 7 | def localtime(secs : int) -> Tuple: 8 | return Tuple 9 | """ 10 | 从初始时间的秒转换为元组: (年, 月, 日, 时, 分, 秒, 星期, yearday) 。如果 secs 是空或者 None,那么使用当前时间。 11 | year 年份包括世纪(例如2014)。 12 | 13 | - month 范围 1-12 14 | - day 范围 1-31 15 | - hour 范围 0-23 16 | - minute 范围 0-59 17 | - second 范围 0-59 18 | - weekday 范围 0-6 对应周一到周日 19 | - yearday 范围 1-366 20 | """ 21 | ... 22 | 23 | def mktime(time : tuple) -> int: 24 | return time 25 | """时间的反函数,它的参数是完整8参数的元组,返回值一个整数自2000年1月1日以来的秒数。""" 26 | ... 27 | 28 | def sleep(seconds) -> None: 29 | """休眠指定的时间(秒),Seconds 可以是浮点数。注意有些版本的 MicroPython不支持浮点数,为了兼容可以使用 sleep_ms() 和 sleep_us()函数。""" 30 | ... 31 | 32 | def sleep_ms(ms) -> None: 33 | """延时指定毫秒,参数不能小于0。""" 34 | ... 35 | 36 | def sleep_us(us) -> None: 37 | """延时指定微秒,参数不能小于0。""" 38 | ... 39 | 40 | def ticks_ms() -> int: 41 | return time 42 | """ 43 | 返回不断递增的毫秒计数器,在某些值后会重新计数(未指定)。 44 | 计数值本身无特定意义,只适合用在ticks_diff()。 45 | 注: 直接在这些值上执行标准数学运算(+,-)或关系运算符(<,>,>,> =)会导致无效结果。 46 | 执行数学运算然后传递结果作为参数给ticks_diff() 或 ticks_add() 也将导致函数产生无效结果。 47 | """ 48 | ... 49 | 50 | def ticks_us() -> int: 51 | return time 52 | """ 53 | 返回不断递增的微秒计数器,在某些值后会重新计数(未指定)。 54 | 计数值本身无特定意义,只适合用在ticks_diff()。 55 | 注: 直接在这些值上执行标准数学运算(+,-)或关系运算符(<,>,>,> =)会导致无效结果。 56 | 执行数学运算然后传递结果作为参数给ticks_diff() 或 ticks_add() 也将导致函数产生无效结果。 57 | """ 58 | ... 59 | 60 | def ticks_cpu() -> None: 61 | """与 ticks_ms() 和 ticks_us() 类似,具有更高精度 (使用 CPU 时钟),并非每个端口都实现此功能。""" 62 | ... 63 | 64 | def ticks_add(ticks, delta) -> int: 65 | return time 66 | """ 67 | 给定一个数字作为节拍的偏移值 delta,这个数字的值是正数或者负数都可以。 68 | 给定一个 ticks 节拍值,本函数允许根据节拍值的模算数定义来计算给定节拍值之前或者之后 delta 个节拍的节拍值 。 69 | ticks 参数必须是 ticks_ms(), ticks_us(), or ticks_cpu() 函数的直接返回值。 70 | 然而,delta 可以是一个任意整数或者是数字表达式。ticks_add 函数对计算事件/任务的截至时间很有用。 71 | (注意:必须使用 ticksdiff() 函数来处理 最后期限)。 72 | """ 73 | ... 74 | 75 | def ticks_diff(ticks1, ticks2) -> int : 76 | return time 77 | """ 78 | 计算两次调用 ticksms(), ticks_us(), 或 ticks_cpu()之间的时间。 79 | 因为这些函数的计数值可能会回绕,所以不能直接相减,需要使用 ticks_diff() 函数。 80 | “旧” 时间需要在 “新” 时间之前,否则结果无法确定。 81 | 这个函数不要用在计算很长的时间 (因为 ticks*() 函数会回绕,通常周期不是很长)。 82 | 通常用法是在带超时的轮询事件中调用: 83 | 代码示例: 84 | # 等待 GPIO 引脚有效,但是最多等待500微秒 85 | 86 | - start = time.ticks_us() 87 | - while pin.value() == 0: 88 | - if time.ticks_diff(time.ticks_us(), start) > 500: 89 | - raise TimeoutError 90 | """ 91 | ... 92 | 93 | def time() -> int: 94 | return time 95 | """ 96 | 返回从开始时间的秒数(整数),假设 RTC 已经按照前面方法设置好。 97 | 如果 RTC 没有设置,函数将返回参考点开始计算的秒数 (对于 RTC 没有后备电池的板子,上电或复位后的情况)。 98 | 如果你开发便携版的 MicroPython 应用程序,你不要依赖函数来提供超过秒级的精度。 99 | 如果需要高精度,使用 ticks_ms() 和 ticks_us() 函数。 100 | 如果需要日历时间,使用不带参数的 localtime() 是更好选择。""" 101 | ... 102 | -------------------------------------------------------------------------------- /code-completion/utimeq.py: -------------------------------------------------------------------------------- 1 | class utimeq: 2 | "" 3 | 4 | def peektime(): 5 | pass 6 | 7 | def pop(): 8 | pass 9 | 10 | def push(): 11 | pass 12 | -------------------------------------------------------------------------------- /code-completion/uzlib.py: -------------------------------------------------------------------------------- 1 | """ 2 | uzlib 模块实现了使用 DEFLATE 算法解压缩二进制数据 (常用的 zlib 库和 gzip 文档)。目前不支持压缩。 3 | """ 4 | 5 | def decompress(data) -> None: 6 | """打开一个文件,关联到内建函数open()。所有端口 (用于访问文件系统) 需要支持模式参数,但支持其他参数不同的端口。""" 7 | ... 8 | 9 | -------------------------------------------------------------------------------- /code-completion/zlib.py: -------------------------------------------------------------------------------- 1 | class DecompIO: 2 | "" 3 | 4 | def read(): 5 | pass 6 | 7 | def readinto(): 8 | pass 9 | 10 | def readline(): 11 | pass 12 | 13 | 14 | def decompress(): 15 | pass 16 | -------------------------------------------------------------------------------- /demo/weather_show/.mpyproject.json: -------------------------------------------------------------------------------- 1 | //This is an automatically generated configuration file. 2 | //Please do not modify or delete it!!! 3 | { 4 | "projectName":"weather_show" 5 | } -------------------------------------------------------------------------------- /demo/weather_show/main_demo.py: -------------------------------------------------------------------------------- 1 | import time 2 | import network 3 | import ujson as json 4 | from machine import LCD 5 | import urequests as requests 6 | 7 | def lcd_init(): 8 | lcd = LCD() # Create a LCD object 9 | lcd.light(True) # Open the backlight 10 | lcd.set_color(lcd.WHITE, lcd.BLACK) # Set background color and foreground color 11 | lcd.fill(lcd.WHITE) # Fill the entire LCD with white 12 | lcd.text("0000-00-00", 10, 0, 24) 13 | lcd.line(0, 25, 239, 25) 14 | lcd.text("City: N/A", 10, 105, 24) # prints the string at 32 font size at position (0, 48) 15 | lcd.text("Humidity: N/A", 10, 135, 24) 16 | lcd.text("Temp: N/A", 10, 165, 24) 17 | 18 | lcd.show_bmp(45, 87, "pictures/weather.bmp") 19 | lcd.show_bmp(5, 238, "pictures/micropython.bmp") 20 | lcd.show_bmp(210, 20, "pictures/wifi_week.bmp") 21 | return lcd 22 | 23 | def wifi_connect(ssid, password, lcd): 24 | wlan = network.WLAN(network.STA_IF) 25 | 26 | print("Begin to connect wifi...") 27 | wlan.connect(ssid, password) 28 | 29 | if wlan.isconnected(): 30 | print("Wifi connect successful, waitting to get IP...") 31 | else: 32 | print("Wifi connect failed.") 33 | 34 | count = 0 35 | while count < 3: 36 | lcd.show_bmp(210, 20, "pictures/wifi_week.bmp") 37 | time.sleep(0.3) 38 | lcd.show_bmp(210, 20, "pictures/wifi_middle.bmp") 39 | time.sleep(0.3) 40 | lcd.show_bmp(210, 20, "pictures/wifi_strong.bmp") 41 | time.sleep(0.3) 42 | count += 1 43 | 44 | def main(): 45 | ssid = "test" 46 | password = "123456789" 47 | 48 | lcd = lcd_init() 49 | 50 | wifi_connect(ssid, password, lcd) 51 | 52 | # you can find cityid on this page: 53 | # https://gitee.com/wangjins/weather_api/blob/master/city.json 54 | cityid = "101020100" 55 | url = "http://www.tianqiapi.com/api/?version=v6&cityid=" + cityid + "&appid=65251531&appsecret=Yl2bzCYb" 56 | 57 | r = requests.get(url) 58 | data = json.loads(r.content.decode()) 59 | 60 | lcd.text("%s"%data["date"], 10, 0, 24) 61 | lcd.text("City: ShangHai", 10, 105, 24) # prints the string at 32 font size at position (0, 48) 62 | lcd.text("Humidity: %s"%data["humidity"], 10, 135, 24) 63 | lcd.text("Temp: %s - %s"%(data["tem2"], data["tem1"]), 10, 165, 24) 64 | image = "pictures/" + data["wea_img"] + ".bmp" # (xue, lei, shachen, wu, bingbao, yun, yu, yin, qing) 65 | lcd.show_bmp(190, 166, image) 66 | 67 | if __name__ == "__main__": 68 | main() 69 | -------------------------------------------------------------------------------- /demo/weather_show/pictures/bingbao.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/bingbao.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/lei.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/lei.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/micropython.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/micropython.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/qing.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/qing.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/shachen.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/shachen.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/weather.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/weather.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/wifi_middle.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/wifi_middle.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/wifi_strong.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/wifi_strong.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/wifi_week.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/wifi_week.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/wu.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/wu.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/xue.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/xue.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/yin.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/yin.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/yu.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/yu.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/yujiaxue.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/yujiaxue.bmp -------------------------------------------------------------------------------- /demo/weather_show/pictures/yun.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/demo/weather_show/pictures/yun.bmp -------------------------------------------------------------------------------- /demo/weather_show/urequests.py: -------------------------------------------------------------------------------- 1 | import usocket 2 | 3 | class Response: 4 | 5 | def __init__(self, f): 6 | self.raw = f 7 | self.encoding = "utf-8" 8 | self._cached = None 9 | 10 | def close(self): 11 | if self.raw: 12 | self.raw.close() 13 | self.raw = None 14 | self._cached = None 15 | 16 | @property 17 | def content(self): 18 | if self._cached is None: 19 | try: 20 | self._cached = self.raw.read() 21 | finally: 22 | self.raw.close() 23 | self.raw = None 24 | return self._cached 25 | 26 | @property 27 | def text(self): 28 | return str(self.content, self.encoding) 29 | 30 | def json(self): 31 | import ujson 32 | return ujson.loads(self.content) 33 | 34 | 35 | def request(method, url, data=None, json=None, headers={}, stream=None): 36 | try: 37 | proto, dummy, host, path = url.split("/", 3) 38 | except ValueError: 39 | proto, dummy, host = url.split("/", 2) 40 | path = "" 41 | if proto == "http:": 42 | port = 80 43 | elif proto == "https:": 44 | import ussl 45 | port = 443 46 | else: 47 | raise ValueError("Unsupported protocol: " + proto) 48 | 49 | if ":" in host: 50 | host, port = host.split(":", 1) 51 | port = int(port) 52 | 53 | ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM) 54 | ai = ai[0] 55 | 56 | s = usocket.socket(ai[0], ai[1], ai[2]) 57 | try: 58 | s.connect(ai[-1]) 59 | if proto == "https:": 60 | s = ussl.wrap_socket(s, server_hostname=host) 61 | s.write(b"%s /%s HTTP/1.0\r\n" % (method, path)) 62 | if not "Host" in headers: 63 | s.write(b"Host: %s\r\n" % host) 64 | # Iterate over keys to avoid tuple alloc 65 | for k in headers: 66 | s.write(k) 67 | s.write(b": ") 68 | s.write(headers[k]) 69 | s.write(b"\r\n") 70 | if json is not None: 71 | assert data is None 72 | import ujson 73 | data = ujson.dumps(json) 74 | s.write(b"Content-Type: application/json\r\n") 75 | if data: 76 | s.write(b"Content-Length: %d\r\n" % len(data)) 77 | s.write(b"\r\n") 78 | if data: 79 | s.write(data) 80 | 81 | l = s.readline() 82 | #print(l) 83 | l = l.split(None, 2) 84 | status = int(l[1]) 85 | reason = "" 86 | if len(l) > 2: 87 | reason = l[2].rstrip() 88 | while True: 89 | l = s.readline() 90 | if not l or l == b"\r\n": 91 | break 92 | #print(l) 93 | if l.startswith(b"Transfer-Encoding:"): 94 | if b"chunked" in l: 95 | raise ValueError("Unsupported " + l) 96 | elif l.startswith(b"Location:") and not 200 <= status <= 299: 97 | raise NotImplementedError("Redirects not yet supported") 98 | except OSError: 99 | s.close() 100 | raise 101 | 102 | resp = Response(s) 103 | resp.status_code = status 104 | resp.reason = reason 105 | return resp 106 | 107 | 108 | def head(url, **kw): 109 | return request("HEAD", url, **kw) 110 | 111 | def get(url, **kw): 112 | return request("GET", url, **kw) 113 | 114 | def post(url, **kw): 115 | return request("POST", url, **kw) 116 | 117 | def put(url, **kw): 118 | return request("PUT", url, **kw) 119 | 120 | def patch(url, **kw): 121 | return request("PATCH", url, **kw) 122 | 123 | def delete(url, **kw): 124 | return request("DELETE", url, **kw) 125 | -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/check_example_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/check_example_en.png -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/direct_run_files_en.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/direct_run_files_en.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/download_file_floder_en.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/download_file_floder_en.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/en_connect_board.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/en_connect_board.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/en_create_blank_project.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/en_create_blank_project.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/en_run_example_files.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/en_run_example_files.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/en_run_snippets.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/en_run_snippets.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/en_select_powershell.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/en_select_powershell.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/install_python_plug_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/install_python_plug_en.png -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/more_deep_docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/more_deep_docs.png -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/01_select_powershell.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/01_select_powershell.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/02_install_python_plug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/02_install_python_plug.png -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/03_create_blank_prj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/03_create_blank_prj.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/04_create_demo_prj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/04_create_demo_prj.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/05_demo_express.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/05_demo_express.png -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/06_uart_connect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/06_uart_connect.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/07_check_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/07_check_example.png -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/08_direct_run_files.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/08_direct_run_files.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/09_run_code_snippet.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/09_run_code_snippet.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/10_download_file_floder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/10_download_file_floder.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/11_sync_files.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/11_sync_files.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/plug_pic/12_auto_complete.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/plug_pic/12_auto_complete.gif -------------------------------------------------------------------------------- /docs/MicroPythonPlug-in/assets/sync_files_en.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/docs/MicroPythonPlug-in/assets/sync_files_en.gif -------------------------------------------------------------------------------- /examples/00.learning/00.hello_python.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # 第一个 Python 程序,来和 Python 打个招呼吧 12 | print("Hello, Python!") 13 | -------------------------------------------------------------------------------- /examples/00.learning/01.basic_grammar.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # 在 Python 中将需要注释的内容前加上 # 号 12 | # 第一个注释 13 | import sys 14 | print("Hello, Python!") # 第二个注释 15 | 16 | # Python 最具特色的就是使用缩进来表示代码块,不需要使用大括号 {} 17 | # 缩进的空格数是可变的,但是同一个代码块的语句必须包含相同的缩进空格数 18 | if True: 19 | print("True") 20 | else: 21 | print("False") 22 | 23 | # import 与 from...import 24 | # 在 python 用 import 或者 from...import 来导入相应的模块。 25 | # 将整个模块(somemodule)导入,格式为: import somemodule 26 | # 从某个模块中导入某个函数,格式为: from somemodule import somefunction 27 | # 从某个模块中导入多个函数,格式为: from somemodule import firstfunc, secondfunc, thirdfunc 28 | # 将某个模块中的全部函数导入,格式为: from somemodule import * 29 | 30 | import sys 31 | print(sys.version) 32 | 33 | from sys import path 34 | print ('python path %s'%path) 35 | 36 | # Python 中的变量不需要声明。每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。 37 | # 在 Python 中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存中对象的类型。 38 | 39 | counter = 100 # 整型变量 40 | miles = 1000.0 # 浮点型变量 41 | name = "RT-Thread" # 字符串 42 | 43 | print(counter) 44 | print(miles) 45 | print(name) 46 | 47 | # Python3 中有六个标准的数据类型: 48 | 49 | # Number(数字) 50 | # String(字符串) 51 | # List(列表) 52 | # Tuple(元组) 53 | # Set(集合) 54 | # Dictionary(字典) 55 | # Python3 的六个标准数据类型中: 56 | # 不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组) 57 | # 可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合) 58 | -------------------------------------------------------------------------------- /examples/00.learning/02.number.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # 数字 12 | # Python3 支持 int、float、bool、complex(复数) 13 | # 在 Python 3里,只有一种整数类型 int,表示为长整型 14 | # 像大多数语言一样,数值类型的赋值和计算都是很直观的 15 | # 内置的 type() 函数可以用来查询变量所指的对象类型 16 | 17 | a, b, c, d = 20, 5.5, True, 4+3j 18 | print(type(a), type(b), type(c), type(d)) 19 | -------------------------------------------------------------------------------- /examples/00.learning/03.string.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # String(字符串) 12 | # Python中的字符串用单引号 ' 或双引号 " 括起来,同时使用反斜杠 \ 转义特殊字符。 13 | # 字符串的截取的语法格式如下: 14 | # 变量[头下标:尾下标] 15 | # 索引值以 0 为开始值,-1 为从末尾的开始位置。 16 | 17 | str = 'RT-Thread' 18 | print(str) # 输出字符串 19 | print(str[0:-1]) # 输出第一个到倒数第二个的所有字符 20 | print(str[0]) # 输出字符串第一个字符 21 | print(str[2:5]) # 输出从第三个开始到第五个的字符 22 | print(str[2:]) # 输出从第三个开始的后的所有字符 23 | print(str * 2) # 输出字符串两次 24 | print(str + "TEST") # 连接字符串 25 | -------------------------------------------------------------------------------- /examples/00.learning/04.list.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # List(列表) 12 | # List(列表) 是 Python 中使用最频繁的数据类型。 13 | # 列表可以完成大多数集合类的数据结构实现。列表中元素的类型可以不相同,它支持数字,字符串甚至可以包含列表(所谓嵌套)。 14 | # 列表是写在方括号 [] 之间、用逗号分隔开的元素列表。 15 | # 和字符串一样,列表同样可以被索引和截取,列表被截取后返回一个包含所需元素的新列表。 16 | # 列表截取的语法格式如下: 17 | # 变量[头下标:尾下标] 18 | # 索引值以 0 为开始值,-1 为从末尾的开始位置。 19 | 20 | list = ['abcd', 786, 2.23, 'hello', 70.2] 21 | tinylist = [123, 'hello'] 22 | 23 | print(list) # 输出完整列表 24 | print(list[0]) # 输出列表第一个元素 25 | print(list[1:3]) # 从第二个开始输出到第三个元素 26 | print(list[2:]) # 输出从第三个元素开始的所有元素 27 | print(tinylist * 2) # 输出两次列表 28 | print(list + tinylist) # 连接列表 29 | -------------------------------------------------------------------------------- /examples/00.learning/05.tuple.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # 元组(tuple)与列表类似,不同之处在于元组的元素不能修改。元组写在小括号 () 里,元素之间用逗号隔开 12 | # 元组中的元素类型也可以不相同 13 | 14 | tuple = ('abcd', 786, 2.23, 'hello', 70.2) 15 | tinytuple = (123, 'hello') 16 | 17 | print(tuple) # 输出完整元组 18 | print(tuple[0]) # 输出元组的第一个元素 19 | print(tuple[1:3]) # 输出从第二个元素开始到第三个元素 20 | print(tuple[2:]) # 输出从第三个元素开始的所有元素 21 | print(tinytuple * 2) # 输出两次元组 22 | print(tuple + tinytuple) # 连接元组 23 | -------------------------------------------------------------------------------- /examples/00.learning/06.set.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # 集合(set)是由一个或数个形态各异的大小整体组成的,构成集合的事物或对象称作元素或是成员 12 | # 基本功能是进行成员关系测试和删除重复元素 13 | # 可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典 14 | 15 | student = {'Tom', 'Jim', 'Mary', 'Tom', 'Jack', 'Rose'} 16 | print(student) # 输出集合,重复的元素被自动去掉 17 | 18 | # 成员测试 19 | if 'Rose' in student: 20 | print('Rose is in set') 21 | else: 22 | print('Rose is not in set') 23 | 24 | # set可以进行集合运算 25 | a = set('abracadabra') 26 | b = set('alacazam') 27 | 28 | print(a) 29 | print(a - b) # a 和 b 的差集 30 | print(a | b) # a 和 b 的并集 31 | print(a & b) # a 和 b 的交集 32 | print(a ^ b) # a 和 b 中不同时存在的元素 33 | -------------------------------------------------------------------------------- /examples/00.learning/07.dict.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # 字典(dictionary)是Python中另一个非常有用的内置数据类型 12 | # 列表是有序的对象集合,字典是无序的对象集合。两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取 13 | # 字典是一种映射类型,字典用 { } 标识,它是一个无序的 键(key) : 值(value) 的集合 14 | # 键(key)必须使用不可变类型 15 | # 在同一个字典中,键(key)必须是唯一的 16 | 17 | dict = {} 18 | dict['one'] = "RT-THREAD" 19 | dict[2] = "MicroPython" 20 | 21 | tinydict = {'name': 'rt-thread', 'code': 512, 'site': 'www.rt-thread.org'} 22 | 23 | print(dict['one']) # 输出键为 'one' 的值 24 | print(dict[2]) # 输出键为 2 的值 25 | print(tinydict) # 输出完整的字典 26 | print(tinydict.keys()) # 输出所有键 27 | print(tinydict.values()) # 输出所有值 28 | -------------------------------------------------------------------------------- /examples/00.learning/08.condition.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # if 语句 12 | # Python中if语句的一般形式如下所示: 13 | 14 | # if condition_1: 15 | # statement_block_1 16 | # elif condition_2: 17 | # statement_block_2 18 | # else: 19 | # statement_block_3 20 | 21 | # 如果 "condition_1" 为 True 将执行 "statement_block_1" 块语句 22 | # 如果 "condition_1" 为 False,将判断 "condition_2" 23 | # 如果 "condition_2" 为 True 将执行 "statement_block_2" 块语句 24 | # 如果 "condition_2" 为 False,将执行"statement_block_3"块语句 25 | # Python 中用 elif 代替了 else if,所以if语句的关键字为:if – elif – else 26 | 27 | # 注意: 28 | # 1、每个条件后面要使用冒号 :,表示接下来是满足条件后要执行的语句块 29 | # 2、使用缩进来划分语句块,相同缩进数的语句在一起组成一个语句块 30 | # 3、在 Python 中没有 switch – case 语句 31 | 32 | count1 = 100 33 | if count1: 34 | print("1 - if get condition true") 35 | print(count1) 36 | 37 | count2 = 0 38 | if count2: 39 | print("2 - if get condition true") 40 | print(count2) 41 | 42 | print("exit!") 43 | -------------------------------------------------------------------------------- /examples/00.learning/09.loops.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-07-27 SummerGift first version 9 | # 10 | 11 | # Python 中的循环语句有 for 和 while 12 | 13 | # 下列程序使用 while 来计算 1 到 100 的总和: 14 | n = 100 15 | sum = 0 16 | counter = 1 17 | while counter <= n: 18 | sum = sum + counter 19 | counter += 1 20 | 21 | print("The sum from 1 to %d is: %d" % (n, sum)) 22 | 23 | # Python for 循环可以遍历任何序列的项目,如一个列表或者一个字符串 24 | languages = ["C", "C++", "java", "Python"] 25 | for x in languages: 26 | print (x) 27 | 28 | # 如果你需要遍历数字序列,可以使用内置 range() 函数。它会生成数列,例如: 29 | for i in range(5): 30 | print(i) 31 | 32 | # Python pass 是空语句,是为了保持程序结构的完整性 33 | # pass 不做任何事情,一般用做占位语句,如下实例 34 | 35 | # while True: 36 | # pass # 等待键盘中断 (Ctrl+C) 37 | 38 | # 以下实例在字母为 r 时 执行 pass 语句块: 39 | for letter in 'RT-Thread': 40 | if letter == 'T': 41 | pass 42 | print('exec pass code') 43 | else: 44 | print("current letter : %s" % letter) 45 | 46 | print("exit!") 47 | -------------------------------------------------------------------------------- /examples/01.basic/_thread.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import gc 12 | import _thread 13 | 14 | def testThread(): 15 | count = 0 16 | while (count < 9): 17 | print("Hello rt-thread!") 18 | count += 1 19 | 20 | print("Thread exit!") 21 | gc.collect() # Free the memory space requested by the thread 22 | 23 | # TestThread thread is created with an empty argument 24 | _thread.start_new_thread(testThread, ()) 25 | -------------------------------------------------------------------------------- /examples/01.basic/array.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import array 12 | 13 | a = array.array('i', [2, 4, 1, 5]) 14 | b = array.array('f') 15 | print(a) 16 | print(b) 17 | 18 | a = array.array('f', [3, 6]) 19 | print(a) 20 | a.append(7.0) 21 | print(a) 22 | 23 | a = array.array('i', [1, 2, 3]) 24 | b = array.array('i', [4, 5]) 25 | a.extend(b) 26 | print(a) 27 | -------------------------------------------------------------------------------- /examples/01.basic/main.py: -------------------------------------------------------------------------------- 1 | 2 | def main(): 3 | print("Welcome to RT-Thread MicroPython!") 4 | 5 | if __name__ == '__main__': 6 | main() 7 | -------------------------------------------------------------------------------- /examples/01.basic/math.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import math 12 | 13 | print(math.e) 14 | print(math.pi) 15 | print(math.sqrt(9)) 16 | print(math.pow(2, 3)) 17 | print(math.exp(2)) 18 | print(math.log(10)) 19 | print(math.log2(8)) 20 | print(math.log10(10)) 21 | print(math.radians(60)) 22 | print(math.radians(60)) 23 | print(math.sin(math.radians(90))) 24 | print(math.cos(math.radians(60))) 25 | print(math.tan(math.radians(60))) 26 | print(math.asin(0.5)) 27 | print(math.ceil(5.6454)) 28 | print(math.floor(2.99)) 29 | print(math.floor(-2.34)) 30 | print(math.fabs(-5)) 31 | print(math.fabs(5.0)) 32 | print(math.fmod(4, 5)) 33 | print(math.trunc(5.12)) 34 | print(math.trunc(-6.8)) 35 | print(math.gamma(5.21)) 36 | print(math.lgamma(5.21)) 37 | -------------------------------------------------------------------------------- /examples/01.basic/random.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import random 12 | 13 | for j in range(0, 2): 14 | random.seed(13) # Specify random number seed 15 | for i in range(0, 10): # Generate random sequences in the range of 0 to 10 16 | print(random.randint(1, 10)) 17 | print("end") 18 | -------------------------------------------------------------------------------- /examples/01.basic/rmdir.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-10-21 SummerGift first version 9 | # 10 | 11 | # Deletes the entire folder recursively 12 | 13 | def rmdir(directory): 14 | os.chdir(directory) 15 | for f in os.listdir(): 16 | try: 17 | os.remove(f) 18 | except OSError: 19 | pass 20 | for f in os.listdir(): 21 | rmdir(f) 22 | os.chdir('..') 23 | os.rmdir(directory) 24 | -------------------------------------------------------------------------------- /examples/01.basic/sys.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import sys 12 | 13 | print(sys.version) 14 | print(sys.version_info) 15 | print(sys.path) 16 | print(sys.__name__) 17 | print(sys.platform) 18 | print(sys.byteorder) 19 | -------------------------------------------------------------------------------- /examples/01.basic/ucollections.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from ucollections import OrderedDict 12 | from ucollections import namedtuple 13 | 14 | print("namedtuple example:") 15 | MyTuple = namedtuple("MyTuple", ("id", "name")) 16 | t1 = MyTuple(1, "foo") 17 | t2 = MyTuple(2, "bar") 18 | print(t1.name) 19 | print(t2.name) 20 | assert t2.name == t2[1] 21 | 22 | print("\nOrderedDict example:") 23 | # To make benefit of ordered keys, OrderedDict should be initialized 24 | # from sequence of (key, value) pairs. 25 | d = OrderedDict([("z", 1), ("a", 2)]) 26 | # More items can be added as usual 27 | d["w"] = 5 28 | d["b"] = 3 29 | for k, v in d.items(): 30 | print("%s %s"%(k, v)) 31 | -------------------------------------------------------------------------------- /examples/01.basic/uos.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import uos 12 | 13 | print("Get the current directory:") 14 | print(uos.getcwd()) 15 | 16 | print("Create folder: rtthread") 17 | uos.mkdir("rtthread") 18 | 19 | print("List the files in the current directory:") 20 | print(uos.listdir()) 21 | 22 | print("Move the current directory to the rtthread folder:") 23 | uos.chdir("rtthread") 24 | 25 | print("Get the current directory:") 26 | print(uos.getcwd()) 27 | 28 | print("Switch to the previous directory:") 29 | uos.chdir("..") 30 | 31 | print("Get the current directory:") 32 | print(uos.getcwd()) 33 | 34 | print("List the files in the current directory:") 35 | print(uos.listdir()) 36 | 37 | print("Delete the rtthread folder:") 38 | uos.rmdir("rtthread") 39 | 40 | print("List the files in the current directory:") 41 | print(uos.listdir()) 42 | -------------------------------------------------------------------------------- /examples/01.basic/utime.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import utime 12 | 13 | utime.sleep(1) # sleep for 1 second 14 | utime.sleep_ms(500) # sleep for 500 milliseconds 15 | utime.sleep_us(10) # sleep for 10 microseconds 16 | 17 | start = utime.ticks_ms() # get value of millisecond counter 18 | delta = utime.ticks_diff(utime.ticks_ms(), start) # compute time difference 19 | print(utime.ticks_add(utime.ticks_ms(), -100)) 20 | print(utime.ticks_add(0, -1)) 21 | -------------------------------------------------------------------------------- /examples/02.network/tcp_client.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import usocket 12 | 13 | client = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) 14 | client.connect(("192.168.10.110", 6000)) 15 | client.send("rt-thread micropython!") 16 | client.close() 17 | -------------------------------------------------------------------------------- /examples/02.network/tcp_server.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import usocket 12 | 13 | # Create STREAM TCP socket 14 | server = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) 15 | server.bind(('192.168.12.203', 6001)) 16 | server.listen(5) 17 | server.setblocking(True) 18 | 19 | while True: 20 | # Wait for client connection 21 | clientsocket, addr = server.accept() 22 | print("connect address: %s" % str(addr)) 23 | clientsocket.send('welcome to rt-thread micropython!') 24 | clientsocket.close() 25 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/adc.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | # The adc input pin is PC4 on pandora board 12 | 13 | from machine import ADC # Import the ADC class from machine 14 | 15 | adc = ADC(1, 13) # Creates an ADC object that currently uses the 13 channels of an ADC device numbered 1 16 | print(adc.read()) # Gets the ADC object sampling value, value range 0 to 4096 17 | adc.deinit() # Close ADC object 18 | adc.init(13) # Open and reconfigure the ADC object 19 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/beeper.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import utime as time 12 | from machine import Pin 13 | 14 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 15 | def pin_num(pin_index): 16 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 17 | 18 | # create beeper object from pin PIN_BEEPER, Set pin PIN_BEEPER to output mode 19 | beeper = Pin(("beep", pin_num("PB2")), Pin.OUT_PP) 20 | 21 | beeper.value(1) # trun the buzzer on 22 | time.sleep(0.5) 23 | beeper.value(0) # trun the buzzer off 24 | time.sleep(0.5) 25 | beeper.value(1) 26 | time.sleep(0.5) 27 | beeper.value(0) 28 | time.sleep(0.5) 29 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/blink.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import utime as time 12 | from machine import Pin 13 | 14 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 15 | def pin_num(pin_index): 16 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 17 | 18 | # create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode 19 | led = Pin(("led_red", pin_num("PE7")), Pin.OUT_PP) 20 | 21 | while True: 22 | led.value(0) # Set led turn on 23 | time.sleep(0.5) 24 | led.value(1) # Set led turn off 25 | time.sleep(0.5) -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/i2c.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin, I2C 12 | 13 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 14 | def pin_num(pin_index): 15 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 16 | 17 | clk = Pin(("clk", pin_num("PB13")), Pin.OUT_OD) # Select the PIN_CLK pin device as the clock 18 | sda = Pin(("sda", pin_num("PB14")), Pin.OUT_OD) # Select the PIN_SDA pin device as the data line 19 | i2c = I2C(-1, clk, sda, freq=100000) # create I2C peripheral at frequency of 100kHz 20 | i2c.scan() # scan for slaves, returning a list of 7-bit addresses 21 | i2c.writeto(0x51, b'123') # write 3 bytes to slave with 7-bit address 42 22 | i2c.readfrom(0x51, 4) # read 4 bytes from slave with 7-bit address 42 23 | i2c.readfrom_mem(0x51, 0x02, 1) # read 1 bytes from memory of slave 0x51(7-bit) 24 | i2c.writeto_mem(0x51, 2, b'\x10') # write 1 byte to memory of slave 42 25 | 26 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/key.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin 12 | 13 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 14 | def pin_num(pin_index): 15 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 16 | 17 | # create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode 18 | led = Pin(("led_red", pin_num("PE7")), Pin.OUT_PP) 19 | key_0 = Pin(("key_0", pin_num("PD10")), Pin.IN, Pin.PULL_UP) 20 | 21 | while True: 22 | if key_0.value() == 0: 23 | led.value(0) # Set led turn on 24 | else: 25 | led.value(1) 26 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/lcd.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import LCD # Import the LCD class from machine 12 | 13 | lcd = LCD() # Create a LCD object 14 | lcd.light(False) # Close the backlight 15 | lcd.light(True) # Open the backlight 16 | lcd.set_color(lcd.WHITE, lcd.BLACK) # Set background color and foreground color 17 | lcd.fill(lcd.BLACK) # Fill the entire LCD with black 18 | lcd.fill(lcd.RED) # Fill the entire LCD with red 19 | lcd.fill(lcd.GRAY) # Fill the entire LCD with gray 20 | lcd.fill(lcd.WHITE) # Fill the entire LCD with white 21 | lcd.pixel(50, 50, lcd.BLUE) # fills the pixels in the (50,50) position with blue 22 | lcd.text("hello RT-Thread", 0, 0, 16) # prints the string at 16 font size at position (0, 0) 23 | lcd.text("hello RT-Thread", 0, 16, 24) # prints the string at 24 font size at position (0, 16) 24 | lcd.text("hello RT-Thread", 0, 48, 32) # prints the string at 32 font size at position (0, 48) 25 | lcd.line(0, 50, 239, 50) # Draw a line starting at (0,50) and ending at (239,50) 26 | lcd.line(0, 50, 239, 50) # Draw a line starting at (0,50) and ending at (239,50) 27 | lcd.rectangle(100, 100, 200, 200) # Draw a rectangle with the top left corner (100,100) and the bottom right corner (200,200) 28 | lcd.circle(150, 150, 80) # Draw a circle with a radius of 80 at the center (150,150) 29 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/pin.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | # Pins can be used are PA4 PA8, PB8-9 PB10-15, PC2 PC4 PC6-7, PD12-15 12 | 13 | from machine import Pin 14 | 15 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 16 | def pin_num(pin_index): 17 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 18 | 19 | p_out = Pin(("PIN_OUT", pin_num("PB15")), Pin.OUT_PP) 20 | p_out.value(1) # set io high 21 | p_out.value(0) # set io low 22 | 23 | p_in = Pin(("key_0", pin_num("PD10")), Pin.IN, Pin.PULL_UP) 24 | print(p_in.value()) # get value, 0 or 1 25 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/pin_irq.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin 12 | 13 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 14 | 15 | def pin_num(pin_index): 16 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 17 | 18 | key_0 = Pin(("key_0", pin_num("PD10")), Pin.IN, Pin.PULL_UP) 19 | 20 | def func(v): 21 | print("Hello rt-thread!") 22 | 23 | key_0.irq(trigger=Pin.IRQ_RISING, handler=func) 24 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/pin_num.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-28 SummerGift first version 9 | # 10 | 11 | def pin_num(pin_index): 12 | """ 13 | Get the GPIO pin number through the GPIO index, format must be "P + + number", such as PE7 14 | """ 15 | 16 | if pin_index[0] != 'P': 17 | print("ERROR : Please pass in the correct parameters P + + number, such as PE7") 18 | return 19 | 20 | if not pin_index[1].isupper(): 21 | print("ERROR : Please pass in the correct parameters P + + number, such as PE7") 22 | return 23 | 24 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 25 | 26 | print("The pin number of PE7 is %d."%pin_num("PE7")) # Get the pin number for PE7 27 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/pwm.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | # The pwm output pin is PB0 on pandora board 12 | 13 | from machine import PWM # Import PWM class from machine 14 | 15 | pwm = PWM(3, 3, 1000, 100) # Create PWM object. Currently, 3 channels of PWM device numbered 3 are used. 16 | # The initialization frequency is 1000Hz and the duty ratio value is 100 (duty ratio is 100/255 = 39.22%). 17 | pwm.freq(2000) # Set the frequency of PWM object 18 | pwm.freq() # Get the frequency of PWM object 19 | print(pwm) # Show PWM object information 20 | pwm.duty(200) # Sets the duty ratio value of PWM object 21 | pwm.duty() # Get the duty ratio value of PWM object 22 | print(pwm) # Show PWM object information 23 | pwm.deinit() # Close PWM object 24 | pwm.init(3, 1000, 100) # Open and reconfigure the PWM object 25 | print(pwm) # Show PWM object information 26 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/rgb_led.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import utime as time 12 | from machine import Pin 13 | 14 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 15 | def pin_num(pin_index): 16 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 17 | 18 | LED_ON = 0 19 | LED_OFF = 1 20 | 21 | led_r = Pin(("LED RED", pin_num("PE7")), Pin.OUT_PP) 22 | led_g = Pin(("LED GREEN", pin_num("PE8")), Pin.OUT_PP) 23 | led_b = Pin(("LED BLUE", pin_num("PE9")), Pin.OUT_PP) 24 | 25 | blink_tab = [(LED_ON, LED_ON, LED_ON), 26 | (LED_OFF, LED_ON, LED_ON), 27 | (LED_ON, LED_OFF, LED_ON), 28 | (LED_ON, LED_ON, LED_OFF), 29 | (LED_OFF, LED_OFF, LED_ON), 30 | (LED_ON, LED_OFF, LED_OFF), 31 | (LED_OFF, LED_ON, LED_OFF), 32 | (LED_ON, LED_OFF, LED_OFF)] 33 | 34 | count = 0 35 | 36 | while True: 37 | group_num = count % len(blink_tab) 38 | 39 | led_r.value(blink_tab[group_num][0]) # set led status 40 | led_g.value(blink_tab[group_num][1]) 41 | led_b.value(blink_tab[group_num][2]) 42 | 43 | count += 1 44 | time.sleep(0.5) 45 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/rtc.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import RTC 12 | 13 | rtc = RTC() # Create an RTC device object 14 | rtc.init((2019, 6, 5, 2, 10, 22, 30, 0)) # Set initialization time 15 | print(rtc.now()) # Get the current time 16 | rtc.deinit() # Reset time to January 1, 2015 17 | print(rtc.now()) # Get the current time 18 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/rtthread.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import rtthread 12 | 13 | # determine if code is running in a preemptible thread 14 | print(rtthread.is_preempt_thread()) 15 | print(rtthread.current_tid()) # current thread id 16 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/spi.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin, SPI 12 | 13 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 14 | def pin_num(pin_index): 15 | return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:]) 16 | 17 | clk = Pin(("clk", pin_num("PB10")), Pin.OUT_PP) # Select the PIN_CLK pin device as the clock 18 | mosi = Pin(("mosi", pin_num("PB11")), Pin.OUT_PP) # Select the PIN_MOSI pin device as the mosi 19 | miso = Pin(("miso", pin_num("PB12")), Pin.IN) # Select the PIN_MISO pin device as the miso 20 | 21 | spi = SPI(-1, 500000, polarity=0, phase=0, bits=8, firstbit=0, sck=clk, mosi=mosi, miso=miso) 22 | print(spi) 23 | spi.write("hello rt-thread!") 24 | spi.read(10) 25 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/timer.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-29 ChenYong first version 9 | # 10 | 11 | from machine import Timer 12 | import utime as time 13 | 14 | def callback_periodic(obj): # defined preiodic mode timeout callback 15 | print("Timer callback periodic test") 16 | 17 | def callback_oneshot(obj): # defined ont shot mode timeout callback 18 | print("Timer callback oneshot test") 19 | 20 | timer = Timer(15) # Create Timer object. Timer device number 15 are used. 21 | timer.init(timer.PERIODIC, 1000, callback_periodic) # Initialize the Timer device object 22 | # Set Timer mode to preiodic mode, set timeout to 1 seconds and set callback fucntion 23 | time.sleep_ms(5500) # Execute 5 times timeout callback in the delay time 24 | timer.init(timer.ONE_SHOT, 1000, callback_oneshot) # Reset initialize the Timer device object 25 | # Set Timer mode to one shot mode, set timeout to 1 seconds and set callback fucntion 26 | time.sleep_ms(1500) # Execute 1 times timeout callback in the delay time 27 | timer.deinit() # Stop and close Timer device object 28 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/uart.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import UART 12 | 13 | uart = UART(1, 115200) # init with given baudrate 14 | uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters 15 | uart.read(10) # read 10 characters, returns a bytes object 16 | uart.read() # read all available characters 17 | uart.readline() # read a line 18 | uart.write('abc') # write the 3 characters 19 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/wdt.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-29 ChenYong first version 9 | # 10 | 11 | from machine import WDT 12 | 13 | wdt = WDT("wdt", 10) # Create an WDT device object, set the timeout to 10 seconds 14 | wdt.feed() # Perform the "feed dog" operation to clear the watchdog device count during the timout period 15 | # If not executed, the system will restart after the timeout 16 | print("reset system after 10 seconds") 17 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/wifi_ap.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import network 12 | 13 | ap = network.WLAN(network.AP_IF) 14 | ap.config(essid="hello_rt-thread", password="88888888") 15 | ap.active(True) 16 | ap.config("essid") 17 | -------------------------------------------------------------------------------- /examples/03.board/1.stm32l4_pandora/wifi_sta.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import network 12 | 13 | wlan = network.WLAN(network.STA_IF) 14 | print(wlan.scan()) 15 | 16 | wlan.connect("test", "123456789") 17 | 18 | if wlan.isconnected(): 19 | print("wifi connect successful") 20 | else: 21 | print("wifi connect failed") 22 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/adc.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import ADC # Import the ADC class from machine 12 | 13 | # adc channel 5 : PB23 14 | # adc channel 6 : PB24 15 | # adc channel 7 : PB25 16 | # adc channel 8 : PB26 17 | 18 | adc = ADC("adc", 5) # Creates an ADC object that currently uses the 5 channel(PB23) of an ADC device name "adc" 19 | value = (adc.read() - 8192.0) / 8192 * 2.25 / 1.2 + 1.584 # Gets the ADC object sampling value and change to voltage value 20 | print("Voltage Value: %.3f" % value) # print voltage value 21 | adc.deinit() # Close ADC object 22 | adc.init(5) # Open and reconfigure the ADC object 23 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/beeper.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import utime as time 12 | from machine import Pin 13 | 14 | # You can get pin number information from file pin_map.py 15 | PIN_BEEPER = 45 # PB15 16 | 17 | # create beeper object from pin PIN_BEEPER, Set pin PIN_BEEPER to output mode 18 | beeper = Pin(("beep", PIN_BEEPER), Pin.OUT_PP) 19 | 20 | beeper.value(1) # trun the buzzer on 21 | time.sleep(0.5) 22 | beeper.value(0) # trun the buzzer off 23 | time.sleep(0.5) 24 | beeper.value(1) 25 | time.sleep(0.5) 26 | beeper.value(0) 27 | time.sleep(0.5) 28 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/blink.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import utime as time 12 | from machine import Pin 13 | 14 | # You can get pin number information from file pin_map.py 15 | PIN_LED_R = 30 # PA13 16 | 17 | # create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode 18 | led = Pin(("led_red", PIN_LED_R), Pin.OUT_PP) 19 | 20 | while True: 21 | led.value(0) # Set led turn on 22 | time.sleep(0.5) 23 | led.value(1) # Set led turn off 24 | time.sleep(0.5) 25 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/i2c.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin, I2C 12 | 13 | # You can get pin number information from file pin_map.py 14 | PIN_CLK = 23 # PA0 15 | PIN_SDA = 24 # PA1 16 | 17 | clk = Pin(("clk", PIN_CLK), Pin.OUT_OD) # Select the PIN_CLK pin device as the clock 18 | sda = Pin(("sda", PIN_SDA), Pin.OUT_OD) # Select the PIN_SDA pin device as the data line 19 | i2c = I2C(-1, clk, sda, freq=100000) # create I2C peripheral at frequency of 100kHz 20 | i2c.scan() # scan for slaves, returning a list of 7-bit addresses 21 | i2c.writeto(0x51, b'123') # write 3 bytes to slave with 7-bit address 42 22 | i2c.readfrom(0x51, 4) # read 4 bytes from slave with 7-bit address 42 23 | i2c.readfrom_mem(0x51, 0x02, 1) # read 1 bytes from memory of slave 0x51(7-bit) 24 | i2c.writeto_mem(0x51, 2, b'\x10') # write 1 byte to memory of slave 42 25 | 26 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/key.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-08-26 SummerGift first version 9 | # 10 | 11 | from machine import Pin 12 | 13 | # You can get pin number information from file pin_map.py 14 | PIN_LED_R = 30 # PA13 15 | PIN_KEY0 = 35 # PA7 16 | KEY_PRESSED = 0 17 | 18 | # create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode 19 | led = Pin(("led_red", PIN_LED_R), Pin.OUT_PP) 20 | key_0 = Pin(("key_0", PIN_KEY0), Pin.IN, Pin.PULL_UP) 21 | 22 | while True: 23 | if key_0.value() == KEY_PRESSED: 24 | led.value(0) # Set led turn on 25 | else: 26 | led.value(1) 27 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/lcd.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import LCD # Import the LCD class from machine 12 | 13 | lcd = LCD() # Create a LCD object 14 | lcd.light(False) # Close the backlight 15 | lcd.light(True) # Open the backlight 16 | lcd.set_color(lcd.WHITE, lcd.BLACK) # Set background color and foreground color 17 | lcd.fill(lcd.BLACK) # Fill the entire LCD with black 18 | lcd.fill(lcd.RED) # Fill the entire LCD with red 19 | lcd.fill(lcd.GRAY) # Fill the entire LCD with gray 20 | lcd.fill(lcd.WHITE) # Fill the entire LCD with white 21 | lcd.pixel(50, 50, lcd.BLUE) # fills the pixels in the (50,50) position with blue 22 | lcd.text("hello RT-Thread", 0, 0, 16) # prints the string at 16 font size at position (0, 0) 23 | lcd.text("hello RT-Thread", 0, 16, 24) # prints the string at 24 font size at position (0, 16) 24 | lcd.text("hello RT-Thread", 0, 48, 32) # prints the string at 32 font size at position (0, 48) 25 | lcd.line(0, 50, 239, 50) # Draw a line starting at (0,50) and ending at (239,50) 26 | lcd.line(0, 50, 239, 50) # Draw a line starting at (0,50) and ending at (239,50) 27 | lcd.rectangle(100, 100, 200, 200) # Draw a rectangle with the top left corner (100,100) and the bottom right corner (200,200) 28 | lcd.circle(150, 150, 80) # Draw a circle with a radius of 80 at the center (150,150) 29 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/pin.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin 12 | 13 | # You can get pin number information from file pin_map.py 14 | PIN_OUT = 30 # PA13 15 | PIN_IN = 35 # PA7 16 | 17 | p_out = Pin(("PA13", PIN_OUT), Pin.OUT_PP) 18 | p_out.value(1) # set io high 19 | p_out.value(0) # set io low 20 | 21 | p_in = Pin(("key_0", PIN_IN), Pin.IN, Pin.PULL_UP) 22 | print(p_in.value()) # get value, 0 or 1 23 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/pin_irq.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin 12 | 13 | # You can get pin number information from file pin_map.py 14 | PIN_KEY0 = 35 # PA7 15 | 16 | key_0 = Pin(("key_0", PIN_KEY0), Pin.IN, Pin.PULL_UP) 17 | 18 | def func(v): 19 | print("Hello rt-thread!") 20 | 21 | key_0.irq(trigger=Pin.IRQ_RISING, handler=func) 22 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/pin_map.py: -------------------------------------------------------------------------------- 1 | # You can get the corresponding relationship 2 | # between number and pins fow W601 IoT Board by following. 3 | 4 | """ 5 | PIN(PB_19) = 1 6 | PIN(PB_20) = 2 7 | PIN(PB_21) = 3 8 | PIN(PB_22) = 4 9 | PIN(PB_23) = 5 10 | PIN(PB_24) = 6 11 | PIN(PB_25) = 7 12 | PIN(PB_26) = 8 13 | PIN(PA_00) = 23 14 | PIN(PA_01) = 24 15 | PIN(PA_02) = 25 16 | PIN(PA_03) = 26 17 | PIN(PA_04) = 27 18 | PIN(PA_05) = 29 19 | PIN(PA_13) = 30 20 | PIN(PA_14) = 31 21 | PIN(PA_15) = 32 22 | PIN(PA_06) = 33 23 | PIN(PA_07) = 35 24 | PIN(PA_08) = 36 25 | PIN(PA_09) = 37 26 | PIN(PA_10) = 38 27 | PIN(PA_11) = 39 28 | PIN(PA_12) = 40 29 | PIN(PB_28) = 41 30 | PIN(PB_13) = 43 31 | PIN(PB_14) = 44 32 | PIN(PB_15) = 45 33 | PIN(PB_16) = 47 34 | PIN(PB_17) = 48 35 | PIN(PB_18) = 49 36 | PIN(PB_30) = 51 37 | PIN(PB_31) = 52 38 | PIN(PB_27) = 53 39 | PIN(PB_00) = 54 40 | PIN(PB_01) = 55 41 | PIN(PB_02) = 56 42 | PIN(PB_03) = 57 43 | PIN(PB_04) = 59 44 | PIN(PB_05) = 60 45 | PIN(PB_06) = 61 46 | PIN(PB_07) = 62 47 | PIN(PB_08) = 63 48 | PIN(PB_09) = 64 49 | PIN(PB_10) = 65 50 | PIN(PB_11) = 66 51 | PIN(PB_12) = 67 52 | """ 53 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/pwm.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import PWM # Import PWM class from machine 12 | 13 | # pwm channel 1 : PB18 14 | # pwm channel 2 : PB17 15 | 16 | pwm = PWM("pwm", 1, 1000, 100) # Create PWM object. Currently, 1 channel(PB18) of PWM device name "pwm" are used. 17 | # The initialization frequency is 1000Hz and the duty ratio value is 100 (duty ratio is 100/255 = 39.22%). 18 | pwm.freq(2000) # Set the frequency of PWM object 19 | pwm.freq() # Get the frequency of PWM object 20 | print(pwm) # Show PWM object information 21 | pwm.duty(200) # Sets the duty ratio value of PWM object 22 | pwm.duty() # Get the duty ratio value of PWM object 23 | print(pwm) # Show PWM object information 24 | pwm.deinit() # Close PWM object 25 | pwm.init(1, 1000, 100) # Open and reconfigure the PWM object 26 | print(pwm) # Show PWM object information 27 | 28 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/rgb_led.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import utime as time 12 | from machine import Pin 13 | 14 | LED_ON = 0 15 | LED_OFF = 1 16 | 17 | # You can get pin number information from file pin_map.py 18 | PIN_LED_R = 30 # PA13 19 | PIN_LED_G = 31 # PA14 20 | PIN_LED_B = 32 # PA15 21 | 22 | led_r = Pin(("led_red", PIN_LED_R), Pin.OUT_PP) 23 | led_g = Pin(("led_green", PIN_LED_G), Pin.OUT_PP) 24 | led_b = Pin(("led_blue", PIN_LED_B), Pin.OUT_PP) 25 | 26 | blink_tab = [(LED_ON, LED_ON, LED_ON), 27 | (LED_OFF, LED_ON, LED_ON), 28 | (LED_ON, LED_OFF, LED_ON), 29 | (LED_ON, LED_ON, LED_OFF), 30 | (LED_OFF, LED_OFF, LED_ON), 31 | (LED_ON, LED_OFF, LED_OFF), 32 | (LED_OFF, LED_ON, LED_OFF), 33 | (LED_ON, LED_OFF, LED_OFF)] 34 | 35 | count = 0 36 | 37 | while True: 38 | group_num = count % len(blink_tab) 39 | 40 | led_r.value(blink_tab[group_num][0]) # set led status 41 | led_g.value(blink_tab[group_num][1]) 42 | led_b.value(blink_tab[group_num][2]) 43 | 44 | count += 1 45 | time.sleep(0.5) 46 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/rtc.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import RTC 12 | 13 | rtc = RTC() # Create an RTC device object 14 | rtc.init((2019, 6, 5, 2, 10, 22, 30, 0)) # Set initialization time 15 | print(rtc.now()) # Get the current time 16 | rtc.deinit() # Reset time to January 1, 2015 17 | print(rtc.now()) # Get the current time 18 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/rtthread.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import rtthread 12 | 13 | # determine if code is running in a preemptible thread 14 | print(rtthread.is_preempt_thread()) 15 | print(rtthread.current_tid()) # current thread id 16 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/spi.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import Pin, SPI 12 | 13 | # You can get pin number information from file pin_map.py 14 | PIN_CLK = 26 # PA3 15 | PIN_MOSI = 27 # PA4 16 | PIN_MISO = 28 # PA5 17 | 18 | clk = Pin(("clk", PIN_CLK), Pin.OUT_PP) # Select the PIN_CLK pin device as the clock 19 | mosi = Pin(("mosi", PIN_MOSI), Pin.OUT_PP) # Select the PIN_MOSI pin device as the mosi 20 | miso = Pin(("miso", PIN_MISO), Pin.IN) # Select the PIN_MISO pin device as the miso 21 | 22 | spi = SPI(-1, 500000, polarity=0, phase=0, bits=8, firstbit=0, sck=clk, mosi=mosi, miso=miso) 23 | print(spi) 24 | spi.write("hello rt-thread!") 25 | spi.read(10) 26 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/timer.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-29 ChenYong first version 9 | # 10 | 11 | from machine import Timer 12 | import utime as time 13 | 14 | def callback_periodic(obj): # defined preiodic mode timeout callback 15 | print("Timer callback periodic test") 16 | 17 | def callback_oneshot(obj): # defined ont shot mode timeout callback 18 | print("Timer callback oneshot test") 19 | 20 | timer = Timer(1) # Create Timer object, driver support timer1/timer2/timer3 21 | timer.init(timer.PERIODIC, 1000, callback_periodic) # Initialize the Timer device object 22 | # Set Timer mode to preiodic mode, set timeout to 1 seconds and set callback fucntion 23 | time.sleep_ms(5500) # Execute 5 times timeout callback in the delay time 24 | timer.init(timer.ONE_SHOT, 1000, callback_oneshot) # Reset initialize the Timer device object 25 | # Set Timer mode to one shot mode, set timeout to 1 seconds and set callback fucntion 26 | time.sleep_ms(1500) # Execute 1 times timeout callback in the delay time 27 | timer.deinit() # Stop and close Timer device object 28 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/uart.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import UART 12 | 13 | uart = UART(0, 115200) # init with given baudrate PA4/PA5 14 | uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters 15 | uart.read(10) # read 10 characters, returns a bytes object 16 | uart.read() # read all available characters 17 | uart.readline() # read a line 18 | uart.write('abc') # write the 3 characters 19 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/wdt.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-29 ChenYong first version 9 | # 10 | 11 | from machine import WDT 12 | 13 | wdt = WDT("wdg", 10) # Create an WDT device object, set the timeout to 10 seconds 14 | wdt.feed() # Perform the "feed dog" operation to clear the watchdog device count during the timout period 15 | # If not executed, the system will restart after the timeout 16 | print("reset system after 10 seconds") 17 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/wifi_ap.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import network 12 | 13 | ap = network.WLAN(network.AP_IF) 14 | ap.config(essid="hello_rt-thread", password="88888888") 15 | ap.active(True) 16 | ap.config("essid") 17 | -------------------------------------------------------------------------------- /examples/03.board/2.w601_iot_board/wifi_sta.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | import network 12 | 13 | wlan = network.WLAN(network.STA_IF) 14 | print(wlan.scan()) 15 | 16 | wlan.connect("test", "123456789") 17 | 18 | if wlan.isconnected(): 19 | print("wifi connect successful") 20 | else: 21 | print("wifi connect failed") 22 | -------------------------------------------------------------------------------- /examples/03.board/3.esp8266/blink.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-09-27 SummerGift first version 9 | # 10 | 11 | import time 12 | from machine import Pin 13 | led = Pin(2, Pin.OUT) # create LED object from pin2,Set Pin2 to output 14 | 15 | while True: 16 | led.value(1) # turn off 17 | time.sleep(0.5) 18 | led.value(0) # turn on 19 | time.sleep(0.5) 20 | -------------------------------------------------------------------------------- /examples/03.board/4.esp32/blink.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-09-27 SummerGift first version 9 | # 10 | 11 | import time 12 | from machine import Pin 13 | led = Pin(2, Pin.OUT) # create LED object from pin2,Set Pin2 to output 14 | 15 | while True: 16 | led.value(1) # Set led turn on 17 | time.sleep(0.5) 18 | led.value(0) # Set led turn off 19 | time.sleep(0.5) 20 | -------------------------------------------------------------------------------- /examples/03.board/5.pyboard/blink.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-09-27 SummerGift first version 9 | # 10 | 11 | # pyboard V1.1 12 | from pyb import LED 13 | import time 14 | led1 = LED(1) 15 | led1.toggle() # turn on led 16 | led2 = LED(2) 17 | led2.toggle() 18 | led3 = LED(3) 19 | led3.toggle() 20 | led4 = LED(4) 21 | led4.toggle() 22 | 23 | while 1: 24 | time.sleep(0.5) 25 | led1.on() 26 | time.sleep(0.5) 27 | led1.off() 28 | time.sleep(0.5) 29 | led3.on() 30 | time.sleep(0.5) 31 | led3.off() 32 | time.sleep(0.5) 33 | led2.on() 34 | time.sleep(0.5) 35 | led2.off() 36 | time.sleep(0.5) 37 | led4.on() 38 | time.sleep(0.5) 39 | led4.off() 40 | -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/camera_snapshot.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-12-10 SummerGift first version 9 | # 10 | 11 | from camera import camera 12 | 13 | cam = camera() 14 | cam.snapshot("picture.jpg") -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/camera_web.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-11-29 SummerGift first version 9 | # 10 | 11 | from camera import camera 12 | import rtthread 13 | import time 14 | 15 | rtthread.wifi_join("w0", "test", "123456789") 16 | time.sleep(3) 17 | 18 | # start web camera and then you can view the image on the website 19 | cam = camera() 20 | cam.server_start(5009) 21 | # cam.server_stop() -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/lcd.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-06-13 SummerGift first version 9 | # 10 | 11 | from machine import LCD # Import the LCD class from machine 12 | 13 | lcd = LCD() # Create a LCD object 14 | lcd.light(False) # Close the backlight 15 | lcd.light(True) # Open the backlight 16 | lcd.set_color(lcd.WHITE, lcd.BLACK) # Set background color and foreground color 17 | lcd.fill(lcd.BLACK) # Fill the entire LCD with black 18 | lcd.fill(lcd.RED) # Fill the entire LCD with red 19 | lcd.fill(lcd.GRAY) # Fill the entire LCD with gray 20 | lcd.fill(lcd.WHITE) # Fill the entire LCD with white 21 | lcd.pixel(50, 50, lcd.BLUE) # fills the pixels in the (50,50) position with blue 22 | lcd.text("hello RT-Thread", 0, 0, 16) # prints the string at 16 font size at position (0, 0) 23 | lcd.text("hello RT-Thread", 0, 16, 24) # prints the string at 24 font size at position (0, 16) 24 | lcd.text("hello RT-Thread", 0, 48, 32) # prints the string at 32 font size at position (0, 48) 25 | lcd.line(0, 50, 239, 50) # Draw a line starting at (0,50) and ending at (239,50) 26 | lcd.line(0, 50, 239, 50) # Draw a line starting at (0,50) and ending at (239,50) 27 | lcd.rectangle(100, 100, 200, 200) # Draw a rectangle with the top left corner (100,100) and the bottom right corner (200,200) 28 | lcd.circle(150, 150, 80) # Draw a circle with a radius of 80 at the center (150,150) 29 | -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/pin.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-11-29 SummerGift first version 9 | # 10 | 11 | from machine import Pin 12 | 13 | p_in = Pin(("key", 13), Pin.IN, Pin.PULL_UP) 14 | print(p_in.value()) # get value, flase or true 15 | -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/pin_irq.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-11-29 SummerGift first version 9 | # 10 | 11 | from machine import Pin 12 | 13 | def func(v): 14 | print("Hello rt-thread!") 15 | 16 | # Get the GPIO pin number from GPIO index, for details see pin_num example. 17 | key_0 = Pin(("key_0", 13), Pin.IN, Pin.PULL_UP) 18 | key_0.irq(trigger=Pin.IRQ_RISING, handler=func) 19 | key_0 = Pin(("key_0", 13), Pin.IN, Pin.PULL_UP) 20 | -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/player.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-11-29 SummerGift first version 9 | # 10 | 11 | from player import player 12 | import rtthread 13 | 14 | rtthread.wifi_join("w0", "test", "123456789") 15 | 16 | play = player() 17 | play.opensong("http://music.163.com/song/media/outer/url?id=447925558.mp3") 18 | play.play() 19 | 20 | # play.set_volume(60) 21 | # play.pause() 22 | # play.stop() 23 | -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/recorder.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-11-29 SummerGift first version 9 | # 10 | 11 | from recorder import recorder 12 | import utime as time 13 | 14 | record = recorder() 15 | record.start("voice.wav") 16 | time.sleep(5) 17 | record.stop() 18 | -------------------------------------------------------------------------------- /examples/03.board/6.sparrow_one_board/sound_recorder.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2019-12-10 SummerGift first version 9 | # 10 | 11 | from recorder import recorder 12 | from player import player 13 | import utime as time 14 | 15 | record = recorder() 16 | record.start("hello.wav") 17 | time.sleep(5) 18 | record.stop() 19 | 20 | play = player() 21 | play.set_volume(80) 22 | play.opensong("hello.wav") 23 | play.play() 24 | time.sleep(5) 25 | play.stop() -------------------------------------------------------------------------------- /examples/_README.md: -------------------------------------------------------------------------------- 1 | # MicroPython 示例程序 ([English](#micropython-sample-program)) 2 | 3 | 本仓库用来存放在 [RT-Thread MicroPython 开发环境](https://marketplace.visualstudio.com/items?itemName=RT-Thread.rt-thread-micropython) 中所提供的示例程序,如下表所示: 4 | 5 | | 文件夹名称 | 介绍 | 6 | | ----------- | ------------------------------------------------------------ | 7 | | 00.learning | Python 基础语法学习示例 | 8 | | 01.basic | MicroPython 基础模块使用示例 | 9 | | 02.network | 网络连接相关示例 | 10 | | 03.board | 提供专属于特定开发板的示例程序,目前支持的开发板可以通过插件介绍首页查看 | 11 | 12 | ## 贡献您的代码 13 | 14 | 您可以通过向 [RT-Thread mpy-snippets 仓库](https://github.com/RT-Thread/mpy-snippets) 提交 PR 的方式来为开源项目作出贡献,我们非常期待并感谢您的提交。 15 | 16 | # MicroPython sample program 17 | 18 | The repository be used to store micropython sample program in [RT-Thread MicroPython development environment](https://marketplace.visualstudio.com/items?itemName=RT-Thread.rt-thread-micropython), as shown in the following table: 19 | 20 | | folder name | introduction | 21 | | ----------- | ------------------------------------------------------------| 22 | | 00.learning | Learning grammar learning sample Python basis | 23 | | 01.basic | MicroPython basic module using sample | 24 | | 02.network | net work related sample | 25 | | 03.board | provides specific development board specific sample program, currently supported development board can be viewed through the plug-in introduction home page | 26 | 27 | ## Contribution 28 | 29 | You are welcome to make contributions to open source project [RT-Thread mpy-snippets repository](https://github.com/RT-Thread/mpy-snippets) by submitting your PR. We look forward to it and thank you for your submission. -------------------------------------------------------------------------------- /firmware/l475_pandora_iot_board/stm32l475-atk-pandora-mpy-v1.10.2-20190919.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/firmware/l475_pandora_iot_board/stm32l475-atk-pandora-mpy-v1.10.2-20190919.bin -------------------------------------------------------------------------------- /firmware/l475_pandora_iot_board/stm32l475-atk-pandora-mpy-v1.10.2-20190921.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/firmware/l475_pandora_iot_board/stm32l475-atk-pandora-mpy-v1.10.2-20190921.bin -------------------------------------------------------------------------------- /firmware/stm32f407-atk-explorer/stm32f407-atk-explorer-mpy-v1.10.2-20190802.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/firmware/stm32f407-atk-explorer/stm32f407-atk-explorer-mpy-v1.10.2-20190802.bin -------------------------------------------------------------------------------- /firmware/w601_iot_board/w601-atk-board-mpy-v1.10.2-20190919.FLS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/firmware/w601_iot_board/w601-atk-board-mpy-v1.10.2-20190919.FLS -------------------------------------------------------------------------------- /firmware/w601_iot_board/w601-atk-board-mpy-v1.10.2-20190921.FLS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/firmware/w601_iot_board/w601-atk-board-mpy-v1.10.2-20190921.FLS -------------------------------------------------------------------------------- /library/_README.md: -------------------------------------------------------------------------------- 1 | # MicroPython 库 ([English](#micropython-library)) 2 | 3 | 本仓库用来存放在 [RT-Thread MicroPython 开发环境](https://marketplace.visualstudio.com/items?itemName=RT-Thread.rt-thread-micropython) 中所提供的库文件。 4 | 5 | ## 贡献您的代码 6 | 7 | 您可以通过向 [RT-Thread mpy-snippets 仓库](https://github.com/RT-Thread/mpy-snippets) 提交 PR 的方式来为开源项目作出贡献,我们非常期待并感谢您的提交。 8 | 9 | # MicroPython library 10 | 11 | The repository be used to store microPython library in [RT-Thread MicroPython development environment](https://marketplace.visualstudio.com/items?itemName=RT-Thread.rt-thread-micropython). 12 | 13 | ## Contribution 14 | 15 | You are welcome to make contributions to open source project [RT-Thread mpy-snippets repository](https://github.com/RT-Thread/mpy-snippets) by submitting your PR. We look forward to it and thank you for your submission. -------------------------------------------------------------------------------- /library/aht10/aht10.py: -------------------------------------------------------------------------------- 1 | import utime as time 2 | from micropython import const 3 | import ustruct as struct 4 | 5 | AHT10_ADDR = const(0x38) 6 | AHT10_CALIBRATION_CMD = const(0xE1) # calibration cmd for measuring 7 | AHT10_NORMAL_CMD = const(0xA8) # normal cmd 8 | AHT10_GET_DATA = const(0xAC) # get data cmd 9 | 10 | class AHT10: 11 | """Class which provides interface to MPU6500 6-axis motion tracking device.""" 12 | def __init__(self, i2c, address=0x38): 13 | self.i2c = i2c 14 | self.address = address 15 | 16 | def sensor_init(self): 17 | buf=bytearray(2) 18 | buf[0] = 0x00 19 | buf[1] = 0x00 20 | self.i2c.writeto_mem(self.address, AHT10_NORMAL_CMD, buf) 21 | time.sleep_ms(350) 22 | buf[0] = 0x08 23 | buf[1] = 0x00 24 | self.i2c.writeto_mem(self.address, AHT10_CALIBRATION_CMD, buf) 25 | time.sleep_ms(450) 26 | 27 | def is_calibration_enabled(self): 28 | status = self.i2c.readfrom(self.address, 1) 29 | status_hex = struct.unpack_from(">b", status) 30 | if status_hex[0] & int('0x68', 16) == int('0x08', 16): 31 | return True 32 | else: 33 | return False 34 | 35 | def read_temperature(self): 36 | cmd=bytearray(2) 37 | cmd[0] = 0x00 38 | cmd[1] = 0x00 39 | self.i2c.writeto_mem(self.address, AHT10_GET_DATA, cmd) 40 | 41 | if self.is_calibration_enabled(): 42 | temp = self.i2c.readfrom(self.address, 6) 43 | temp_hex = struct.unpack(">BBBBBB", temp) 44 | cur_temp = ((temp_hex[3] & 0xf) << 16 | temp_hex[4] << 8 | temp_hex[5]) * 200.0 / (1 << 20) - 50 45 | return cur_temp 46 | else: 47 | self.sensor_init() 48 | print("The aht10 is under an abnormal status. Please try again") 49 | 50 | def read_humidity(self): 51 | cmd=bytearray(2) 52 | cmd[0] = 0x00 53 | cmd[1] = 0x00 54 | self.i2c.writeto_mem(self.address, AHT10_GET_DATA, cmd) 55 | 56 | if self.is_calibration_enabled(): 57 | temp = self.i2c.readfrom(self.address, 6) 58 | temp_hex = struct.unpack(">BBBBBB", temp) 59 | 60 | while temp_hex[2] == 0: 61 | temp = self.i2c.readfrom(self.address, 6) 62 | temp_hex = struct.unpack(">BBBBBB", temp) 63 | 64 | cur_humi = (temp_hex[1] << 12 | temp_hex[2] << 4 | (temp_hex[3] & 0xf0) >> 4) * 100.0 / (1 << 20) 65 | return cur_humi 66 | else: 67 | self.sensor_init() 68 | print("The aht10 is under an abnormal status. Please try again") -------------------------------------------------------------------------------- /library/aht10/aht10_example.py: -------------------------------------------------------------------------------- 1 | from machine import I2C, Pin 2 | from aht10 import AHT10 3 | 4 | PIN_CLK = 54 # PD6, get the pin number from get_pin_number.py 5 | PIN_SDA = 33 # PC1 6 | 7 | clk = Pin(("clk", PIN_CLK), Pin.OUT_OD) # Select the PIN_CLK as the clock 8 | sda = Pin(("sda", PIN_SDA), Pin.OUT_OD) # Select the PIN_SDA as the data line 9 | 10 | i2c = I2C(-1, clk, sda, freq=100000) 11 | sensor = AHT10(i2c) 12 | sensor.sensor_init() 13 | sensor.is_calibration_enabled() 14 | 15 | print("current temp: %.2f "%sensor.read_temperature()) 16 | print("current humi: %.2f %%"%sensor.read_humidity()) 17 | -------------------------------------------------------------------------------- /library/ap3216c/ap3216c.py: -------------------------------------------------------------------------------- 1 | import utime as time 2 | from micropython import const 3 | import ustruct as struct 4 | 5 | # System Register 6 | AP3216C_SYS_CONFIGURATION_REG = const(0x00) 7 | AP3216C_SYS_INT_STATUS_REG = const(0x01) 8 | AP3216C_SYS_INT_CLEAR_MANNER_REG = const(0x02) 9 | AP3216C_IR_DATA_L_REG = const(0x0A) 10 | AP3216C_IR_DATA_H_REG = const(0x0B) 11 | AP3216C_ALS_DATA_L_REG = const(0x0C) 12 | AP3216C_ALS_DATA_H_REG = const(0x0D) 13 | AP3216C_PS_DATA_L_REG = const(0x0E) 14 | AP3216C_PS_DATA_H_REG = const(0x0F) 15 | 16 | # ALS Register 17 | AP3216C_ALS_CONFIGURATION_REG = const(0x10) # range 5:4,persist 3:0 18 | AP3216C_ALS_CALIBRATION_REG = const(0x19) 19 | AP3216C_ALS_THRESHOLD_LOW_L_REG = const(0x1A) # bit 7:0 20 | AP3216C_ALS_THRESHOLD_LOW_H_REG = const(0x1B) # bit 15:8 21 | AP3216C_ALS_THRESHOLD_HIGH_L_REG = const(0x1C) # bit 7:0 22 | AP3216C_ALS_THRESHOLD_HIGH_H_REG = const(0x1D) # bit 15:8 23 | 24 | # PS Register 25 | AP3216C_PS_CONFIGURATION_REG = const(0x20) 26 | AP3216C_PS_LED_DRIVER_REG = const(0x21) 27 | AP3216C_PS_INT_FORM_REG = const(0x22) 28 | AP3216C_PS_MEAN_TIME_REG = const(0x23) 29 | AP3216C_PS_LED_WAITING_TIME_REG = const(0x24) 30 | AP3216C_PS_CALIBRATION_L_REG = const(0x28) 31 | AP3216C_PS_CALIBRATION_H_REG = const(0x29) 32 | AP3216C_PS_THRESHOLD_LOW_L_REG = const(0x2A) # bit 1:0 33 | AP3216C_PS_THRESHOLD_LOW_H_REG = const(0x2B) # bit 9:2 34 | AP3216C_PS_THRESHOLD_HIGH_L_REG = const(0x2C) # bit 1:0 35 | AP3216C_PS_THRESHOLD_HIGH_H_REG = const(0x2D) # bit 9:2 36 | 37 | # AP3216C ADDR 38 | AP3216C_ADDR = const(0x1e) # 0x3c=0x1e<<1 39 | 40 | # AP3216C_MODE SET 41 | AP3216C_MODE_POWER_DOWN = const(0x00) # Power down (Default) 42 | AP3216C_MODE_ALS = const(0x01) # ALS function active 43 | AP3216C_MODE_PS = const(0x02) # PS+IR function active 44 | AP3216C_MODE_ALS_AND_PS = const(0x03) # ALS and PS+IR functions active 45 | AP3216C_MODE_SW_RESET = const(0x04) # SW reset 46 | AP3216C_MODE_ALS_ONCE = const(0x05) # ALS function once 47 | AP3216C_MODE_PS_ONCE = const(0x06) # PS+IR function once 48 | AP3216C_MODE_ALS_AND_PS_ONCE = const(0x07) # ALS and PS+IR functions once 49 | 50 | AP3216C_ALS_RANGE_20661 = const(0x00) # Resolution = 0.35 lux/count(default). 51 | AP3216C_ALS_RANGE_5162 = const(0x01) # Resolution = 0.0788 lux/count. 52 | AP3216C_ALS_RANGE_1291 = const(0x02) # Resolution = 0.0197 lux/count. 53 | AP3216C_ALS_RANGE_323 = const(0x03) # Resolution = 0.0049 lux/count 54 | 55 | class AP3216C: 56 | """Class which provides interface to apc3216c device.""" 57 | def __init__(self, i2c, address=AP3216C_ADDR): 58 | self.i2c = i2c 59 | self.address = address 60 | 61 | def sensor_init(self): 62 | self.reset_sensor() 63 | 64 | buf=bytearray(1) 65 | buf[0]=AP3216C_MODE_ALS_AND_PS 66 | self.i2c.writeto_mem(self.address, AP3216C_SYS_CONFIGURATION_REG, buf) 67 | time.sleep_ms(100) 68 | 69 | def reset_sensor(self): 70 | buf=bytearray(1) 71 | buf[0]=AP3216C_MODE_SW_RESET 72 | self.i2c.writeto_mem(self.address, AP3216C_SYS_CONFIGURATION_REG, buf) 73 | time.sleep_ms(100) 74 | 75 | def read_ps_data(self): 76 | temp = self.i2c.readfrom_mem(self.address, AP3216C_PS_DATA_L_REG, 1) 77 | temp_hex1 = struct.unpack(">B", temp) 78 | temp = self.i2c.readfrom_mem(self.address, AP3216C_PS_DATA_H_REG, 1) 79 | temp_hex2 = struct.unpack(">B", temp) 80 | read_data = temp_hex1[0] + (temp_hex2[0] << 8) 81 | 82 | if (1 == ((read_data >> 6) & 0x01 or (read_data >> 14) & 0x01)): 83 | print("The data of PS is invalid for high intensive IR light") 84 | 85 | return (read_data & 0x000f) + (((read_data >> 8) & 0x3f) << 4) # sensor proximity converse to reality 86 | 87 | def read_ambient_light(self): 88 | temp = self.i2c.readfrom_mem(self.address, AP3216C_ALS_DATA_L_REG, 1) 89 | temp_hex1 = struct.unpack(">B", temp) 90 | temp = self.i2c.readfrom_mem(self.address, AP3216C_ALS_DATA_H_REG, 1) 91 | temp_hex2 = struct.unpack(">B", temp) 92 | read_data = temp_hex1[0] + (temp_hex2[0] << 8) 93 | 94 | temp = self.get_als_range() 95 | 96 | if (temp == AP3216C_ALS_RANGE_20661): 97 | brightness = 0.35 * read_data; # sensor ambient light converse to reality 98 | elif (temp == AP3216C_ALS_RANGE_5162): 99 | brightness = 0.0788 * read_data; # sensor ambient light converse to reality 100 | elif (temp == AP3216C_ALS_RANGE_1291): 101 | brightness = 0.0197 * read_data; # sensor ambient light converse to reality 102 | elif (temp == AP3216C_ALS_RANGE_323): 103 | brightness = 0.0049 * read_data; # sensor ambient light converse to reality 104 | else: 105 | print("Failed to get range of ap3216c") 106 | 107 | return brightness 108 | 109 | def get_als_range(self): 110 | 111 | temp = self.i2c.readfrom_mem(self.address, AP3216C_ALS_CONFIGURATION_REG, 1) 112 | temp_hex = struct.unpack(">B", temp) 113 | temp = (temp_hex[0] & 0xff) >> 4 114 | 115 | if (temp == AP3216C_ALS_RANGE_20661) or (temp == AP3216C_ALS_RANGE_5162) or (temp == AP3216C_ALS_RANGE_1291) or (temp == AP3216C_ALS_RANGE_323): 116 | return temp 117 | else: 118 | print("Getting als dynamic range is wrong, please refer als_range") 119 | return False 120 | 121 | 122 | -------------------------------------------------------------------------------- /library/ap3216c/ap3216c_example.py: -------------------------------------------------------------------------------- 1 | from machine import I2C, Pin 2 | from ap3216c import AP3216C 3 | import utime as time 4 | 5 | PIN_CLK = 32 # PC0, get the pin number from get_pin_number.py 6 | PIN_SDA = 33 # PC1 7 | 8 | clk = Pin(("clk", PIN_CLK), Pin.OUT_OD) # Select the PIN_CLK as the clock 9 | sda = Pin(("sda", PIN_SDA), Pin.OUT_OD) # Select the PIN_SDA as the data line 10 | 11 | i2c = I2C(-1, clk, sda, freq=100000) 12 | 13 | sensor = AP3216C(i2c) 14 | sensor.sensor_init() 15 | 16 | while True: 17 | print("current ps data : %.2f"%sensor.read_ps_data()) 18 | print("current brightness: %.2f"%sensor.read_ambient_light()) 19 | time.sleep_ms(1000) 20 | 21 | -------------------------------------------------------------------------------- /library/benchmark/benchmark.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2019, RT-Thread Development Team 3 | # 4 | # SPDX-License-Identifier: MIT License 5 | # 6 | # Change Logs: 7 | # Date Author Notes 8 | # 2018-10-25 Shao ziyang first version 9 | # 2019-11-12 SummerGift adapt to RT-Thread MicroPython 10 | # 11 | 12 | import utime as time 13 | import machine 14 | import gc 15 | 16 | 17 | def pi(places=100): 18 | extra = 8 19 | one = 10 ** (places+extra) 20 | t, c, n, na, d, da = 3*one, 3*one, 1, 0, 0, 24 21 | 22 | while t > 1: 23 | n, na, d, da = n+na, na+8, d+da, da+32 24 | t = t * n // d 25 | c += t 26 | return c // (10 ** extra) 27 | 28 | 29 | def pi_test(n=5000): 30 | t1 = time.ticks_ms() 31 | t = pi(n) 32 | t2 = time.ticks_ms() 33 | r = time.ticks_diff(t2, t1)/1000 34 | print(' Pi %d digit calculation: %s' % (n, r)) 35 | return '%.2f' % r 36 | 37 | 38 | def int_add_test(n=1000000, a=12345, b=56789): 39 | t1 = time.ticks_ms() 40 | sum = 0 41 | for i in range(n): 42 | sum = a + b 43 | t2 = time.ticks_ms() 44 | r = time.ticks_diff(t2, t1)/1000 45 | print(' Integer Add test %d times: %s s' % (n, r)) 46 | return '%.2f' % r 47 | 48 | 49 | def float_add_test(n=1000000, a=1234.5678, b=5678.1234): 50 | t1 = time.ticks_ms() 51 | sum = 0 52 | for i in range(n): 53 | sum = a + b 54 | t2 = time.ticks_ms() 55 | r = time.ticks_diff(t2, t1)/1000 56 | print(' Float Add test %d times: %s s' % (n, r)) 57 | return '%.2f' % r 58 | 59 | 60 | def int_mul_test(n=1000000, a=12345, b=56789): 61 | t1 = time.ticks_ms() 62 | sum = 0 63 | for i in range(n): 64 | sum = a * b 65 | t2 = time.ticks_ms() 66 | r = time.ticks_diff(t2, t1)/1000 67 | print(' Integer Mul test %d times: %s s' % (n, r)) 68 | return '%.2f' % r 69 | 70 | 71 | def float_mul_test(n=1000000, a=1234.5678, b=5678.1234): 72 | t1 = time.ticks_ms() 73 | sum = 0 74 | for i in range(n): 75 | sum = a * b 76 | t2 = time.ticks_ms() 77 | r = time.ticks_diff(t2, t1)/1000 78 | print(' Float Mul test %d times: %s s' % (n, r)) 79 | return '%.2f' % r 80 | 81 | 82 | def int_div_test(n=1000000, a=123456, b=567): 83 | t1 = time.ticks_ms() 84 | sum = 0 85 | for i in range(n): 86 | sum = a // b 87 | t2 = time.ticks_ms() 88 | r = time.ticks_diff(t2, t1)/1000 89 | print(' Integer Div test %d times: %s s' % (n, r)) 90 | return '%.2f' % r 91 | 92 | 93 | def float_div_test(n=1000000, a=12345.678, b=56.789): 94 | t1 = time.ticks_ms() 95 | sum = 0 96 | for i in range(n): 97 | sum = a / b 98 | t2 = time.ticks_ms() 99 | r = time.ticks_diff(t2, t1)/1000 100 | print(' Float Div test %d times: %s s' % (n, r)) 101 | return '%.2f' % r 102 | 103 | 104 | def mem_free(): 105 | r = gc.mem_free() 106 | print('free memory: %d' % r) 107 | 108 | 109 | print('\nLaunch the speed test') 110 | 111 | print('\nCalcaulate integer addition') 112 | gc.collect() 113 | mem_free() 114 | d1 = int_add_test() 115 | d2 = int_add_test() 116 | d3 = int_add_test() 117 | r_int_add = min(d1, d2, d3) 118 | print('Integer addition test result: %s s' % r_int_add) 119 | mem_free() 120 | 121 | print('\nCalcaulate float addition') 122 | gc.collect() 123 | mem_free() 124 | d1 = float_add_test() 125 | d2 = float_add_test() 126 | d3 = float_add_test() 127 | r_float_add = min(d1, d2, d3) 128 | print('Float addition test result: %s s' % r_float_add) 129 | mem_free() 130 | 131 | print('\nCalcaulate integer multiplication') 132 | gc.collect() 133 | mem_free() 134 | d1 = int_mul_test() 135 | d2 = int_mul_test() 136 | d3 = int_mul_test() 137 | r_int_mul = min(d1, d2, d3) 138 | print('Integer multiplication test result: %s s' % r_int_mul) 139 | mem_free() 140 | 141 | print('\nCalcaulate float multiplication') 142 | gc.collect() 143 | mem_free() 144 | d1 = float_mul_test() 145 | d2 = float_mul_test() 146 | d3 = float_mul_test() 147 | r_float_mul = min(d1, d2, d3) 148 | print('Float multiplication test result: %s s' % r_float_mul) 149 | mem_free() 150 | 151 | print('\nCalcaulate integer division') 152 | gc.collect() 153 | mem_free() 154 | d1 = int_div_test() 155 | d2 = int_div_test() 156 | d3 = int_div_test() 157 | r_int_div = min(d1, d2, d3) 158 | print('Integer division test result: %s s' % r_int_div) 159 | mem_free() 160 | 161 | print('\nCalcaulate float division') 162 | gc.collect() 163 | mem_free() 164 | d1 = float_div_test() 165 | d2 = float_div_test() 166 | d3 = float_div_test() 167 | r_float_div = min(d1, d2, d3) 168 | print('Float division test result: %s s' % r_float_div) 169 | mem_free() 170 | 171 | print('\nCalcaulate Pi 1000 digit') 172 | gc.collect() 173 | mem_free() 174 | try: 175 | d1 = pi_test(1000) 176 | d2 = pi_test(1000) 177 | d3 = pi_test(1000) 178 | r_pi_1000 = min(d1, d2, d3) 179 | print('1000 digit Pi calculation result: %s s' % r_pi_1000) 180 | mem_free() 181 | except: 182 | r_pi_1000 = None 183 | print(' calculation error') 184 | 185 | print('/nTest result:') 186 | print(' Integer addition test result: %s s' % r_int_add) 187 | print(' Float addition test result: %s s' % r_float_add) 188 | print(' Integer multiplication test result: %s s' % r_int_mul) 189 | print(' Float multiplication test result: %s s' % r_float_mul) 190 | print(' Integer division test result: %s s' % r_int_div) 191 | print(' Float division test result: %s s' % r_float_div) 192 | print(' 1000 digit Pi calculation result: %s s' % r_pi_1000) 193 | -------------------------------------------------------------------------------- /library/benchmark/factorial.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def fact(n): 4 | r=1 5 | t1=time.ticks_us() 6 | while n>1: 7 | r=r*n 8 | n=n-1 9 | t2=time.ticks_us() 10 | print('elapsed: ', time.ticks_diff(t1,t2), 'us') 11 | return r 12 | -------------------------------------------------------------------------------- /library/benchmark/pi_test.py: -------------------------------------------------------------------------------- 1 | import time 2 | import machine 3 | import gc 4 | 5 | 6 | def pi(places=100): 7 | extra = 8 8 | one = 10 ** (places + extra) 9 | t, c, n, na, d, da = 3 * one, 3 * one, 1, 0, 0, 24 10 | 11 | while t > 1: 12 | n, na, d, da = n + na, na + 8, d + da, da + 32 13 | t = t * n // d 14 | c += t 15 | return c // (10 ** extra) 16 | 17 | 18 | def pi_test(n=5000): 19 | t1 = time.ticks_ms() 20 | pi(n) 21 | t2 = time.ticks_ms() 22 | r = time.ticks_diff(t2, t1) / 1000 23 | print(' Pi', n, 'digit calculation: ', r, 's') 24 | return '%.2f' % r 25 | 26 | 27 | gc.collect() 28 | 29 | try: 30 | d1 = pi_test(1000) 31 | d2 = pi_test(1000) 32 | d3 = pi_test(1000) 33 | r_pi_1000 = min(d1, d2, d3) 34 | print('1000 digit Pi calculation result: ', r_pi_1000, 's') 35 | except: 36 | r_pi_1000 = None 37 | print(' calculation error') 38 | 39 | print('\nCalcaulate Pi 5000 digit') 40 | gc.collect() 41 | 42 | try: 43 | d1 = pi_test(5000) 44 | d2 = pi_test(5000) 45 | d3 = pi_test(5000) 46 | r_pi_5000 = min(d1, d2, d3) 47 | print('5000 digit Pi calculation result: ', r_pi_5000, 's') 48 | except: 49 | r_pi_5000 = None 50 | print(' calculation error') 51 | 52 | print('\nCalcaulate Pi 100,000 digit') 53 | 54 | gc.collect() 55 | try: 56 | d1 = pi_test(100000) 57 | d2 = pi_test(100000) 58 | d3 = pi_test(100000) 59 | r_pi_100000 = min(d1, d2, d3) 60 | print('100000 digit Pi calculation result: ', r_pi_100000, 's') 61 | except: 62 | r_pi_100000 = None 63 | print(' calculation error') 64 | 65 | if r_pi_1000: 66 | print(' 1000 digit Pi calculation result: ', r_pi_1000, 's') 67 | if r_pi_5000: 68 | print(' 5000 digit Pi calculation result: ', r_pi_5000, 's') 69 | if r_pi_100000: 70 | print(' 100000 digit Pi calculation result: ', r_pi_100000, 's') 71 | -------------------------------------------------------------------------------- /library/filetree/tree.py: -------------------------------------------------------------------------------- 1 | import os 2 | class TREE: 3 | 4 | def __repr__(self): 5 | self.__call__() 6 | return "" 7 | 8 | def __call__(self, path=".", level=0, is_last=False, is_root=True, 9 | carrier=" "): 10 | l = os.listdir(path) 11 | nf = len([file for file in os.listdir(path) if not os.stat(file)[0] & 0x4000]) 12 | nd = len(l) - nf 13 | ns_f, ns_d = 0, 0 14 | l.sort() 15 | if len(l) > 0: 16 | last_file = l[-1] 17 | else: 18 | last_file = '' 19 | for f in l: 20 | st = os.stat("%s/%s" % (path, f)) 21 | if st[0] & 0x4000: # stat.S_IFDIR 22 | print(self._treeindent(level, f, last_file, is_last=is_last, carrier=carrier) + " %s " % f) 23 | os.chdir(f) 24 | level += 1 25 | lf = last_file == f 26 | if level > 1: 27 | if lf: 28 | carrier += " " 29 | else: 30 | carrier += " │" 31 | ns_f, ns_d = self.__call__(level=level, is_last=lf, 32 | is_root=False, carrier=carrier) 33 | if level > 1: 34 | carrier = carrier[:-5] 35 | os.chdir('..') 36 | level += (-1) 37 | nf += ns_f 38 | nd += ns_d 39 | else: 40 | print(self._treeindent(level, f, last_file, is_last=is_last, carrier=carrier) + " %s" % (f)) 41 | if is_root: 42 | print('{} directories, {} files'.format(nd, nf)) 43 | else: 44 | return (nf, nd) 45 | 46 | def _treeindent(self, lev, f, lastfile, is_last=False, carrier=None): 47 | if lev == 0: 48 | return "" 49 | else: 50 | if f != lastfile: 51 | return carrier + " ├────" 52 | else: 53 | return carrier + " └────" 54 | 55 | 56 | tree = TREE() 57 | -------------------------------------------------------------------------------- /library/filetree/tree_example.py: -------------------------------------------------------------------------------- 1 | from tree import * 2 | 3 | print("This demo lists the content of your directory\n") 4 | tree = TREE() 5 | print(tree) 6 | -------------------------------------------------------------------------------- /library/icm20608/icm20608_example.py: -------------------------------------------------------------------------------- 1 | from machine import I2C, Pin 2 | from icm20608 import ICM20608 3 | import utime as time 4 | 5 | PIN_CLK = 32 # PC0, get the pin number from get_pin_number.py 6 | PIN_SDA = 33 # PC1 7 | 8 | clk = Pin(("clk", PIN_CLK), Pin.OUT_OD) # Select the PIN_CLK as the clock 9 | sda = Pin(("sda", PIN_SDA), Pin.OUT_OD) # Select the PIN_SDA as the data line 10 | 11 | i2c = I2C(-1, clk, sda, freq=100000) 12 | sensor = ICM20608(i2c) 13 | sensor.sensor_init() 14 | sensor.calib_level(10) 15 | 16 | count = 100 17 | while count > 0: 18 | print("accel : [ x : %10.2f y : %10.2f z : %10.2f] gyro : [ x : %10.2f y : %10.2f z : %10.2f]"%(sensor.get_accel()[0],sensor.get_accel()[1],sensor.get_accel()[2],sensor.get_gyro()[0],sensor.get_gyro()[1],sensor.get_gyro()[2])) 19 | count -= 1 20 | time.sleep_ms(100) 21 | -------------------------------------------------------------------------------- /library/lcd_image/ball.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/library/lcd_image/ball.img -------------------------------------------------------------------------------- /library/lcd_image/show_bmp_example.py: -------------------------------------------------------------------------------- 1 | from machine import LCD 2 | 3 | # Currently only supports 32-bit BMP true color image display 4 | 5 | def main(): 6 | lcd = LCD() 7 | lcd.light(True) 8 | lcd.set_color(lcd.WHITE, lcd.BLACK) 9 | lcd.show_bmp(180, 50, "sun.bmp") 10 | 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /library/lcd_image/sun.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/library/lcd_image/sun.bmp -------------------------------------------------------------------------------- /library/mpu9250/mpu9250.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018-2019 Mika Tuupola 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copied of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | # https://github.com/tuupola/micropython-mpu9250 22 | 23 | """ 24 | MicroPython I2C driver for MPU9250 9-axis motion tracking device 25 | """ 26 | 27 | # pylint: disable=import-error 28 | from micropython import const 29 | from mpu6500 import MPU6500 30 | from ak8963 import AK8963 31 | # pylint: enable=import-error 32 | 33 | __version__ = "0.2.1" 34 | 35 | class MPU9250: 36 | """Class which provides interface to MPU9250 9-axis motion tracking device.""" 37 | def __init__(self, i2c, mpu6500 = None, ak8963 = None): 38 | if mpu6500 is None: 39 | self.mpu6500 = MPU6500(i2c) 40 | else: 41 | self.mpu6500 = mpu6500 42 | 43 | # if ak8963 is None: 44 | # self.ak8963 = AK8963(i2c) 45 | # else: 46 | # self.ak8963 = ak8963 47 | 48 | @property 49 | def acceleration(self): 50 | """ 51 | Acceleration measured by the sensor. By default will return a 52 | 3-tuple of X, Y, Z axis values in m/s^2 as floats. To get values in g 53 | pass `accel_fs=SF_G` parameter to the MPU6500 constructor. 54 | """ 55 | return self.mpu6500.acceleration 56 | 57 | @property 58 | def gyro(self): 59 | """ 60 | Gyro measured by the sensor. By default will return a 3-tuple of 61 | X, Y, Z axis values in rad/s as floats. To get values in deg/s pass 62 | `gyro_sf=SF_DEG_S` parameter to the MPU6500 constructor. 63 | """ 64 | return self.mpu6500.gyro 65 | 66 | @property 67 | def magnetic(self): 68 | """ 69 | X, Y, Z axis micro-Tesla (uT) as floats. 70 | """ 71 | return self.ak8963.magnetic 72 | 73 | @property 74 | def whoami(self): 75 | return self.mpu6500.whoami 76 | 77 | def __enter__(self): 78 | return self 79 | 80 | def __exit__(self, exception_type, exception_value, traceback): 81 | pass 82 | -------------------------------------------------------------------------------- /library/mpu9250/mpu9250_example.py: -------------------------------------------------------------------------------- 1 | import utime 2 | from machine import I2C, Pin 3 | from mpu9250 import MPU9250 4 | 5 | PIN_CLK = 29 # PB13, get the pin number from get_pin_number.py 6 | PIN_SDA = 30 # PB14 7 | 8 | clk = Pin(("clk", PIN_CLK), Pin.OUT_OD) # Select the PIN_CLK as the clock 9 | sda = Pin(("sda", PIN_SDA), Pin.OUT_OD) # Select the PIN_SDA as the data line 10 | 11 | i2c = I2C(-1, clk, sda, freq=100000) 12 | sensor = MPU9250(i2c) 13 | 14 | print("MPU9250 id: " + hex(sensor.whoami)) 15 | 16 | while True: 17 | print(sensor.acceleration) 18 | print(sensor.gyro) 19 | # print(sensor.magnetic) # not support yet 20 | utime.sleep_ms(1000) 21 | -------------------------------------------------------------------------------- /library/ssd1306/ssd1306_example.py: -------------------------------------------------------------------------------- 1 | from ssd1306 import SSD1306_I2C 2 | from machine import Pin, I2C 3 | # w601 iot board test 4 | PIN_CLK = 66 # PB10 5 | PIN_SDA = 65 # PB11 6 | clk = Pin(("clk", PIN_CLK), Pin.OUT_OD) # Select the PIN_CLK pin device as the clock 7 | sda = Pin(("sda", PIN_SDA), Pin.OUT_OD) # Select the PIN_SDA pin device as the data line 8 | i2c = I2C(-1, clk, sda, freq=100000) 9 | oled = SSD1306_I2C(128, 64, i2c) 10 | 11 | 12 | oled.draw_line(0,0,128,64) 13 | oled.draw_line(128,0,0,64) 14 | oled.show_text(0,0, "RTT test!",12) 15 | oled.show_text(0,10, "RTT TEST!") 16 | oled.show_text(0,24, "RTT test!", 24) 17 | oled.show_text(0,48, "MicroPython") 18 | oled.show() 19 | -------------------------------------------------------------------------------- /library/umqtt/example_pub.py: -------------------------------------------------------------------------------- 1 | from umqtt.simple import MQTTClient 2 | 3 | # Test reception e.g. with: 4 | # mosquitto_sub -t foo_topic 5 | 6 | def main(server="iot.eclipse.org"): 7 | c = MQTTClient("SummerGift", server) 8 | c.connect() 9 | c.publish(b"foo_topic", b"Hello RT-Thread !!!") 10 | c.disconnect() 11 | 12 | if __name__ == "__main__": 13 | main() -------------------------------------------------------------------------------- /library/umqtt/example_sub.py: -------------------------------------------------------------------------------- 1 | import time 2 | from umqtt.simple import MQTTClient 3 | 4 | # Publish test messages e.g. with: 5 | # mosquitto_pub -t foo_topic -m hello 6 | 7 | # Received messages from subscriptions will be delivered to this callback 8 | def sub_cb(topic, msg): 9 | print((topic, msg)) 10 | 11 | def main(server="iot.eclipse.org"): # test server : iot.eclipse.org 12 | c = MQTTClient("RT-Thread", server) 13 | c.set_callback(sub_cb) 14 | c.connect() 15 | c.subscribe(b"foo_topic") # subscribe foo_topic tipic 16 | while True: 17 | if True: 18 | # Blocking wait for message 19 | c.wait_msg() 20 | else: 21 | # Non-blocking wait for message 22 | c.check_msg() 23 | # Then need to sleep to avoid 100% CPU usage (in a real 24 | # app other useful actions would be performed instead) 25 | time.sleep(1) 26 | 27 | c.disconnect() 28 | 29 | if __name__ == "__main__": 30 | main() -------------------------------------------------------------------------------- /library/urequests/urequests.py: -------------------------------------------------------------------------------- 1 | import usocket 2 | 3 | class Response: 4 | 5 | def __init__(self, f): 6 | self.raw = f 7 | self.encoding = "utf-8" 8 | self._cached = None 9 | 10 | def close(self): 11 | if self.raw: 12 | self.raw.close() 13 | self.raw = None 14 | self._cached = None 15 | 16 | @property 17 | def content(self): 18 | if self._cached is None: 19 | try: 20 | self._cached = self.raw.read() 21 | finally: 22 | self.raw.close() 23 | self.raw = None 24 | return self._cached 25 | 26 | @property 27 | def text(self): 28 | return str(self.content, self.encoding) 29 | 30 | def json(self): 31 | import ujson 32 | return ujson.loads(self.content) 33 | 34 | 35 | def request(method, url, data=None, json=None, headers={}, stream=None): 36 | try: 37 | proto, dummy, host, path = url.split("/", 3) 38 | except ValueError: 39 | proto, dummy, host = url.split("/", 2) 40 | path = "" 41 | if proto == "http:": 42 | port = 80 43 | elif proto == "https:": 44 | import ussl 45 | port = 443 46 | else: 47 | raise ValueError("Unsupported protocol: " + proto) 48 | 49 | if ":" in host: 50 | host, port = host.split(":", 1) 51 | port = int(port) 52 | 53 | ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM) 54 | ai = ai[0] 55 | 56 | s = usocket.socket(ai[0], ai[1], ai[2]) 57 | try: 58 | s.connect(ai[-1]) 59 | if proto == "https:": 60 | s = ussl.wrap_socket(s, server_hostname=host) 61 | s.write(b"%s /%s HTTP/1.0\r\n" % (method, path)) 62 | if not "Host" in headers: 63 | s.write(b"Host: %s\r\n" % host) 64 | # Iterate over keys to avoid tuple alloc 65 | for k in headers: 66 | s.write(k) 67 | s.write(b": ") 68 | s.write(headers[k]) 69 | s.write(b"\r\n") 70 | if json is not None: 71 | assert data is None 72 | import ujson 73 | data = ujson.dumps(json) 74 | s.write(b"Content-Type: application/json\r\n") 75 | if data: 76 | s.write(b"Content-Length: %d\r\n" % len(data)) 77 | s.write(b"\r\n") 78 | if data: 79 | s.write(data) 80 | 81 | l = s.readline() 82 | #print(l) 83 | l = l.split(None, 2) 84 | status = int(l[1]) 85 | reason = "" 86 | if len(l) > 2: 87 | reason = l[2].rstrip() 88 | while True: 89 | l = s.readline() 90 | if not l or l == b"\r\n": 91 | break 92 | #print(l) 93 | if l.startswith(b"Transfer-Encoding:"): 94 | if b"chunked" in l: 95 | raise ValueError("Unsupported " + l) 96 | elif l.startswith(b"Location:") and not 200 <= status <= 299: 97 | raise NotImplementedError("Redirects not yet supported") 98 | except OSError: 99 | s.close() 100 | raise 101 | 102 | resp = Response(s) 103 | resp.status_code = status 104 | resp.reason = reason 105 | return resp 106 | 107 | 108 | def head(url, **kw): 109 | return request("HEAD", url, **kw) 110 | 111 | def get(url, **kw): 112 | return request("GET", url, **kw) 113 | 114 | def post(url, **kw): 115 | return request("POST", url, **kw) 116 | 117 | def put(url, **kw): 118 | return request("PUT", url, **kw) 119 | 120 | def patch(url, **kw): 121 | return request("PATCH", url, **kw) 122 | 123 | def delete(url, **kw): 124 | return request("DELETE", url, **kw) 125 | -------------------------------------------------------------------------------- /library/urequests/urequests_example.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import urequests as requests 4 | except ImportError: 5 | import requests 6 | 7 | r = requests.get("http://www.rt-thread.com/service/rt-thread.txt") 8 | print(r.content) 9 | r.close() 10 | -------------------------------------------------------------------------------- /library/webserver/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-midnight -------------------------------------------------------------------------------- /library/webserver/hc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RT-Thread/mpy-snippets/9296d559da275f51845cb9c2f8e2010f66f72cc1/library/webserver/hc2.png --------------------------------------------------------------------------------