mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
Berry 'serial.read()' read only 'n' bytes (#22835)
This commit is contained in:
parent
a49e924b53
commit
a7ee6054b5
@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Command `FileLog 10..14` to enable logging to filesystem using up to 16 log files of 100kB (`#define FILE_LOG_SIZE 100`)
|
- Command `FileLog 10..14` to enable logging to filesystem using up to 16 log files of 100kB (`#define FILE_LOG_SIZE 100`)
|
||||||
- I2S Opus stream and file support for opus/aac (#22795)
|
- I2S Opus stream and file support for opus/aac (#22795)
|
||||||
- I2S command I2sLoop (#22807)
|
- I2S command I2sLoop (#22807)
|
||||||
|
- Berry `serial.read()` read only `n` bytes
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
|
||||||
|
@ -143,10 +143,18 @@ extern "C" {
|
|||||||
int32_t b_serial_read(struct bvm *vm) {
|
int32_t b_serial_read(struct bvm *vm) {
|
||||||
be_getmember(vm, 1, ".p");
|
be_getmember(vm, 1, ".p");
|
||||||
TasmotaSerial * ser = (TasmotaSerial *) be_tocomptr(vm, -1);
|
TasmotaSerial * ser = (TasmotaSerial *) be_tocomptr(vm, -1);
|
||||||
|
int32_t max_lex = -1; // -1 means unlimited
|
||||||
|
int32_t argc = be_top(vm); // Get the number of arguments
|
||||||
|
if (argc >= 2 && be_isint(vm, 2)) {
|
||||||
|
max_lex = be_toint(vm, 2);
|
||||||
|
}
|
||||||
if (ser) {
|
if (ser) {
|
||||||
int32_t len = ser->available();
|
int32_t len = ser->available();
|
||||||
if (len < 0) { len = 0; }
|
if (len < 0) { len = 0; }
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
|
if (max_lex >= 0 && len > max_lex) {
|
||||||
|
len = max_lex;
|
||||||
|
}
|
||||||
// read bytes on stack
|
// read bytes on stack
|
||||||
char * rx_buf = new char[len];
|
char * rx_buf = new char[len];
|
||||||
len = ser->read(rx_buf, len);
|
len = ser->read(rx_buf, len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user