mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
Berry bytes add 3 (#23200)
* Berry bytes add with 3 bytes * add changelog
This commit is contained in:
parent
a47e6f1496
commit
b77b622fbe
@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
## [14.5.0.3]
|
## [14.5.0.3]
|
||||||
### Added
|
### Added
|
||||||
- Extend command `GPIO` with different display options and allowing updating of module GPIO's in one go
|
- Extend command `GPIO` with different display options and allowing updating of module GPIO's in one go
|
||||||
|
- Berry `bytes.add()` now accepts 3-bytes values
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
|
||||||
|
@ -258,6 +258,26 @@ static size_t buf_add2_be(buf_impl* attr, const uint16_t data) // append 16 bits
|
|||||||
return attr->len;
|
return attr->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t buf_add3_le(buf_impl* attr, const uint32_t data) // append 32 bits value
|
||||||
|
{
|
||||||
|
if (attr->len < attr->size - 2) { // do we have room for 4 bytes
|
||||||
|
attr->bufptr[attr->len++] = data;
|
||||||
|
attr->bufptr[attr->len++] = data >> 8;
|
||||||
|
attr->bufptr[attr->len++] = data >> 16;
|
||||||
|
}
|
||||||
|
return attr->len;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t buf_add3_be(buf_impl* attr, const uint32_t data) // append 32 bits value
|
||||||
|
{
|
||||||
|
if (attr->len < attr->size - 2) { // do we have room for 4 bytes
|
||||||
|
attr->bufptr[attr->len++] = data >> 16;
|
||||||
|
attr->bufptr[attr->len++] = data >> 8;
|
||||||
|
attr->bufptr[attr->len++] = data;
|
||||||
|
}
|
||||||
|
return attr->len;
|
||||||
|
}
|
||||||
|
|
||||||
static size_t buf_add4_le(buf_impl* attr, const uint32_t data) // append 32 bits value
|
static size_t buf_add4_le(buf_impl* attr, const uint32_t data) // append 32 bits value
|
||||||
{
|
{
|
||||||
if (attr->len < attr->size - 3) { // do we have room for 4 bytes
|
if (attr->len < attr->size - 3) { // do we have room for 4 bytes
|
||||||
@ -838,10 +858,12 @@ static int m_add(bvm *vm)
|
|||||||
case -1: /* fallback below */
|
case -1: /* fallback below */
|
||||||
case 1: buf_add1(&attr, v); break;
|
case 1: buf_add1(&attr, v); break;
|
||||||
case 2: buf_add2_le(&attr, v); break;
|
case 2: buf_add2_le(&attr, v); break;
|
||||||
|
case 3: buf_add3_le(&attr, v); break;
|
||||||
case 4: buf_add4_le(&attr, v); break;
|
case 4: buf_add4_le(&attr, v); break;
|
||||||
case -2: buf_add2_be(&attr, v); break;
|
case -2: buf_add2_be(&attr, v); break;
|
||||||
|
case -3: buf_add3_be(&attr, v); break;
|
||||||
case -4: buf_add4_be(&attr, v); break;
|
case -4: buf_add4_be(&attr, v); break;
|
||||||
default: be_raise(vm, "type_error", "size must be -4, -2, -1, 0, 1, 2 or 4.");
|
default: be_raise(vm, "type_error", "size must be between -4 and 4.");
|
||||||
}
|
}
|
||||||
be_pop(vm, argc - 1);
|
be_pop(vm, argc - 1);
|
||||||
m_write_attributes(vm, 1, &attr); /* update attributes */
|
m_write_attributes(vm, 1, &attr); /* update attributes */
|
||||||
|
@ -53,6 +53,11 @@ b.add(0x12345678, -2)
|
|||||||
assert(str(b) == "bytes('2278785678563412785678')")
|
assert(str(b) == "bytes('2278785678563412785678')")
|
||||||
b.add(0x12345678, -4)
|
b.add(0x12345678, -4)
|
||||||
assert(str(b) == "bytes('227878567856341278567812345678')")
|
assert(str(b) == "bytes('227878567856341278567812345678')")
|
||||||
|
b.add(0xAABBCC, 3)
|
||||||
|
assert(str(b) == "bytes('227878567856341278567812345678CCBBAA')")
|
||||||
|
b.add(0x998877, -3)
|
||||||
|
assert(str(b) == "bytes('227878567856341278567812345678CCBBAA998877')")
|
||||||
|
|
||||||
|
|
||||||
#- get -#
|
#- get -#
|
||||||
b=bytes("000102030405")
|
b=bytes("000102030405")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user