Skip to content

Commit 7d0f351

Browse files
authored
Berry tasmota.micros() to get time in microseconds (#24192)
* Remove tab from json * Berry `tasmota.micros()` to get time in microseconds
1 parent 58e608b commit 7d0f351

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- Support for ESP32-P4 rev.3 (#24146)
99
- Support for Analog Gauges (#24153)
1010
- Support for MakeSkyBlue Solar Charger Energy Monitor (#24151)
11+
- Berry `tasmota.micros()` to get time in microseconds
1112

1213
### Breaking Changed
1314

lib/libesp32/berry_tasmota/src/be_tasmota_lib.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern int l_publish_rule(bvm *vm);
2121
extern int l_cmd(bvm *vm);
2222
extern int l_getoption(bvm *vm);
2323
extern int l_millis(bvm *vm);
24+
extern int l_micros(bvm *vm);
2425
extern int l_timereached(bvm *vm);
2526
extern int l_rtc(bvm *vm);
2627
extern int l_rtc_utc(bvm *vm);
@@ -114,7 +115,8 @@ class be_class_tasmota (scope: global, name: Tasmota) {
114115
publish_rule, func(l_publish_rule)
115116
_cmd, func(l_cmd)
116117
get_option, func(l_getoption)
117-
millis, func(l_millis)
118+
millis, static_func(l_millis)
119+
micros, static_func(l_micros)
118120
time_reached, func(l_timereached)
119121
rtc, static_func(l_rtc)
120122
rtc_utc, func(l_rtc_utc)

tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ extern "C" {
119119
int32_t l_millis(struct bvm *vm);
120120
int32_t l_millis(struct bvm *vm) {
121121
int32_t top = be_top(vm); // Get the number of arguments
122-
if (top == 1 || (top == 2 && be_isint(vm, 2))) { // only 1 argument of type string accepted
122+
if (top == 0 || (top == 1 && be_isint(vm, 1))) { // only 1 argument of type string accepted
123123
uint32_t delay = 0;
124124
if (top == 2) {
125-
delay = be_toint(vm, 2);
125+
delay = be_toint(vm, 1);
126126
}
127127
uint32_t ret_millis = millis() + delay;
128128
be_pushint(vm, ret_millis);
@@ -131,6 +131,14 @@ extern "C" {
131131
be_raise(vm, kTypeError, nullptr);
132132
}
133133

134+
// Berry: tasmota.micros() -> int
135+
//
136+
int32_t l_micros(struct bvm *vm);
137+
int32_t l_micros(struct bvm *vm) {
138+
be_pushint(vm, micros());
139+
be_return(vm); // Return
140+
}
141+
134142
// Berry: tasmota.get_option(index:int) -> int
135143
//
136144
int32_t l_getoption(struct bvm *vm);

0 commit comments

Comments
 (0)