mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-13 05:19:50 +04:00
Documentation: new doc on Storage module and JS cleanup (#4161)
- Add new doc on Storage module - Improve formatting in the JS section for better readability
This commit is contained in:
@@ -5,78 +5,99 @@ let serial = require("serial");
|
||||
```
|
||||
# Methods
|
||||
|
||||
## setup
|
||||
## setup()
|
||||
Configure serial port. Should be called before all other methods.
|
||||
|
||||
### Parameters
|
||||
**Parameters**
|
||||
|
||||
- Serial port name (usart, lpuart)
|
||||
- Baudrate
|
||||
|
||||
### Examples:
|
||||
**Example**
|
||||
|
||||
```js
|
||||
// Configure LPUART port with baudrate = 115200
|
||||
serial.setup("lpuart", 115200);
|
||||
```
|
||||
|
||||
## write
|
||||
<br>
|
||||
|
||||
## write()
|
||||
Write data to serial port.
|
||||
|
||||
### Parameters
|
||||
**Parameters**
|
||||
|
||||
One or more arguments of the following types:
|
||||
- A string
|
||||
- Single number, each number is interpreted as a byte
|
||||
- Array of numbers, each number is interpreted as a byte
|
||||
- ArrayBuffer or DataView
|
||||
|
||||
### Examples:
|
||||
**Example**
|
||||
|
||||
```js
|
||||
serial.write(0x0a); // Write a single byte 0x0A
|
||||
serial.write("Hello, world!"); // Write a string
|
||||
serial.write("Hello, world!", [0x0d, 0x0a]); // Write a string followed by two bytes
|
||||
```
|
||||
|
||||
## read
|
||||
<br>
|
||||
|
||||
## read()
|
||||
Read a fixed number of characters from serial port.
|
||||
|
||||
### Parameters
|
||||
**Parameters**
|
||||
|
||||
- Number of bytes to read
|
||||
- *(optional)* Timeout value in ms
|
||||
|
||||
### Returns
|
||||
**Returns**
|
||||
|
||||
A sting of received characters or undefined if nothing was received before timeout.
|
||||
|
||||
### Examples:
|
||||
**Example**
|
||||
|
||||
```js
|
||||
serial.read(1); // Read a single byte, without timeout
|
||||
serial.read(10, 5000); // Read 10 bytes, with 5s timeout
|
||||
```
|
||||
|
||||
## readln
|
||||
<br>
|
||||
|
||||
## readln()
|
||||
Read from serial port until line break character.
|
||||
|
||||
### Parameters
|
||||
**Parameters**
|
||||
|
||||
*(optional)* Timeout value in ms.
|
||||
|
||||
### Returns
|
||||
**Returns**
|
||||
|
||||
A sting of received characters or undefined if nothing was received before timeout.
|
||||
|
||||
### Examples:
|
||||
**Example**
|
||||
|
||||
```js
|
||||
serial.readln(); // Read without timeout
|
||||
serial.readln(5000); // Read with 5s timeout
|
||||
```
|
||||
|
||||
## readBytes
|
||||
<br>
|
||||
|
||||
## readBytes()
|
||||
Read from serial port until line break character.
|
||||
|
||||
### Parameters
|
||||
**Parameters**
|
||||
|
||||
- Number of bytes to read
|
||||
- *(optional)* Timeout value in ms
|
||||
|
||||
### Returns
|
||||
**Returns**
|
||||
|
||||
ArrayBuffer with received data or undefined if nothing was received before timeout.
|
||||
|
||||
### Examples:
|
||||
**Example**
|
||||
|
||||
```js
|
||||
serial.readBytes(4); // Read 4 bytes, without timeout
|
||||
|
||||
@@ -84,19 +105,24 @@ serial.readBytes(4); // Read 4 bytes, without timeout
|
||||
serial.readBytes(1, 0);
|
||||
```
|
||||
|
||||
## expect
|
||||
<br>
|
||||
|
||||
## expect()
|
||||
Search for a string pattern in received data stream.
|
||||
|
||||
### Parameters
|
||||
**Parameters**
|
||||
|
||||
- Single argument or array of the following types:
|
||||
- A string
|
||||
- Array of numbers, each number is interpreted as a byte
|
||||
- *(optional)* Timeout value in ms
|
||||
|
||||
### Returns
|
||||
**Returns**
|
||||
|
||||
Index of matched pattern in input patterns list, undefined if nothing was found.
|
||||
|
||||
### Examples:
|
||||
**Example**
|
||||
|
||||
```js
|
||||
// Wait for root shell prompt with 1s timeout, returns 0 if it was received before timeout, undefined if not
|
||||
serial.expect("# ", 1000);
|
||||
|
||||
Reference in New Issue
Block a user