Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Support for ESP32-P4 rev.3 (#24146)
- Support for Analog Gauges (#24153)
- Support for MakeSkyBlue Solar Charger Energy Monitor (#24151)
- Berry `tasmota.micros()` to get time in microseconds

### Breaking Changed

Expand Down
4 changes: 3 additions & 1 deletion lib/libesp32/berry_tasmota/src/be_tasmota_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern int l_publish_rule(bvm *vm);
extern int l_cmd(bvm *vm);
extern int l_getoption(bvm *vm);
extern int l_millis(bvm *vm);
extern int l_micros(bvm *vm);
extern int l_timereached(bvm *vm);
extern int l_rtc(bvm *vm);
extern int l_rtc_utc(bvm *vm);
Expand Down Expand Up @@ -114,7 +115,8 @@ class be_class_tasmota (scope: global, name: Tasmota) {
publish_rule, func(l_publish_rule)
_cmd, func(l_cmd)
get_option, func(l_getoption)
millis, func(l_millis)
millis, static_func(l_millis)
micros, static_func(l_micros)
time_reached, func(l_timereached)
rtc, static_func(l_rtc)
rtc_utc, func(l_rtc_utc)
Expand Down
12 changes: 10 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ extern "C" {
int32_t l_millis(struct bvm *vm);
int32_t l_millis(struct bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top == 1 || (top == 2 && be_isint(vm, 2))) { // only 1 argument of type string accepted
if (top == 0 || (top == 1 && be_isint(vm, 1))) { // only 1 argument of type string accepted
uint32_t delay = 0;
if (top == 2) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this needs be if (top == 1) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally no, because it is now a static method, so it does not have the default self first argument.

Let's revert this PR so we can identify the breaking change. I suppose that there is some code that expects 'tasmota.millis()' to being not static

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a miscommunication coming.

The change from line 122 is in your failing PR. My suggestion is in line 124 which will never execute when line 122 is changed that way.

In the meantime @Jason2866 tested my change with success so....

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

micros is really short. Makes this sense in general in Berry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. I’m doing profiling for leds animation on a very slow esp32s2 so it magnifies performance issues. In such cases, milliseconds is too coarse

delay = be_toint(vm, 2);
delay = be_toint(vm, 1);
}
uint32_t ret_millis = millis() + delay;
be_pushint(vm, ret_millis);
Expand All @@ -131,6 +131,14 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}

// Berry: tasmota.micros() -> int
//
int32_t l_micros(struct bvm *vm);
int32_t l_micros(struct bvm *vm) {
be_pushint(vm, micros());
be_return(vm); // Return
}

// Berry: tasmota.get_option(index:int) -> int
//
int32_t l_getoption(struct bvm *vm);
Expand Down