Comments (12)
Hi Amir,
Thanks for your help. I must admit that I had some difficulty to understand this part of the README. An example is therefore of great help. I slightly adapted your code to my needs and things work perfectly fine.
from lv_demos.
When I run lv_demo_stress, I get a segmentation violation:
eading symbols from demo...
(gdb) r
Starting program: /opt/ucc/micros/esp32/lvgl/simulator/demo
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffefe73700 (LWP 49652)]
[New Thread 0x7fffef672700 (LWP 49653)]
[New Thread 0x7fffeee71700 (LWP 49654)]
[New Thread 0x7fffee670700 (LWP 49655)]
[New Thread 0x7fffedd1a700 (LWP 49657)]
User: mem leak since start: 0, frag: 1 % (lv_demo_stress.c #79 obj_test_task_cb())
Thread 1 "demo" received signal SIGSEGV, Segmentation fault.
_vsnprintf (buffer=buffer@entry=0x5555558eedf8 <work_mem_int+11672> "Formatted:\n100 \377\377\377",
maxlen=maxlen@entry=19, format=, format@entry=0x5555556dd40e "Formatted:\n%d %s",
va=va@entry=0x7fffffffd630, out=0x5555555be0c0 <_out_buffer>)
at /opt/ucc/micros/esp32/lvgl/simulator/lvgl/src/lv_misc/lv_printf.c:814
814 unsigned int l = _strnlen_s(p, precision ? precision : (size_t) -1);
(gdb)
When I compile the program with cmake, I get no compilation error but the program seg-faults the same way
from lv_demos.
Do you use the latest version of lvgl and lv_examples?
It complies and works well for me.
from lv_demos.
Hmmm, I downloaded lv_sim_eclipse_sdl:
git clone https://github.com/lvgl/lv_sim_eclipse_sdl.git --recursive
then I tried to compile with "make"
This produces the compilation error on my Ubuntu 20.04 system. When creating the Makefile with cmake I don't have the problem.
Then I replaced lv_demo_widgets() by lv_demo_stress() and re-compiled.
This works ok now. It seems I did not have the very latest lv_examples and/or lvgl
Another question: Do you have an example how to use lv_task_create in MicroPython? I get seg-faults when setting values from within the task:
https://github.com/uraich/lv_mpy_examples/blob/main/widgets/arc/ex2_arc.py
You may see immediately what I am doing wrong?
from lv_demos.
I've just tried a fresh clone and still works. Anyway, the warnings seem correct because really there is a "function type cast" but I don't how to do it correctly then.
Another question: Do you have an example how to use lv_task_create in MicroPython? I get seg-faults when setting values from within the task:
@amirgon could you help with this?
from lv_demos.
It seems that the warning has been added with gcc version 8. If you run an older version you will not get the warning. As far as I understand it is the first parameter, which is an lv_obj_type * in case of lv_arc_set_end_angle but a void * in case of lv_anim_exec_xcb_t which causes the warning.
Unfortunately I also don't know how to get rid if the problem except of disabling the warning.
from lv_demos.
Another question: Do you have an example how to use lv_task_create in MicroPython? I get seg-faults when setting values from within the task:
@amirgon could you help with this?
@uraich The point is that you are not supposed to use the user_data
, as explained in the README.
user_data
is used internally by the Micropython bindings to keep a reference to a Python callable object and invoke it in the callback.
You don't need user_data
for passing data into a Micropython callback. There are multiple ways you can pass data into a callback. lambda
is one example. Another example is calling an object method, and using other object attributes to pass data to the callback.
So you can rewrite your code like this:
def arc_loader(task, arc):
angle = arc.get_value()
print("angle: ",angle)
angle += 5
if angle >= 100:
task._del()
else:
arc.set_value(angle)
# create an arc which acts as a loader
arc = lv.arc(lv.scr_act(),None)
arc.set_bg_angles(0,360)
arc.set_rotation(270)
arc.align(None,lv.ALIGN.CENTER,0,0)
arc.set_value(10)
lv.task_create(lambda task: arc_loader(task, arc), 20, lv.TASK_PRIO.LOWEST, {})
In Micropython it is recommended to use task_create_basic
like this:
task = lv.task_create_basic()
task.set_cb(lambda task: arc_loader(task, arc))
task.set_period(20)
task.set_prio(lv.TASK_PRIO.LOWEST)
While both task_create
and task_create_basic
are supported today, the task_create_basic
hides the user_data
.
In task_create
you need to pass it as an empty dict for the binding internal usage.
from lv_demos.
Hi Amir,
I read the README very carefully and still have some problems to understand how to use callbacks:
First some typos:
The callback convetion assumes the following: ("n" missing)
Then you should be consistent:
lvgl.anim_set_custom_exec_cb(anim, lambda anim, val, obj=obj: obj.set_y(val))
lv.anim_set_exec_cb(anim, obj, obj.set_y)
Either lvgl... or lv.... in both cases.
From the user perspective, any python callable object (such as python regular function, class function, lambda etc.) can be user as an lvgl callbacks. (should read callback without s)
Then my programming problem:
When calling
create an animation
a=lv.anim_t()
a.init()
print("set custom exec ")
lv.anim_set_exec_cb(a, arc, arc.set_value)
I get AttributeError: 'module' object has no attribute 'anim_set_exec_cb'
When calling:
a.set_exec_cb(a,arc,arc.set_value)
I get TypeError: function takes 2 positional arguments but 4 were given
How do I do this correctly?
Thanks Uli
from lv_demos.
First some typos:
The callback convetion assumes the following: ("n" missing)
Then you should be consistent:
lvgl.anim_set_custom_exec_cb(anim, lambda anim, val, obj=obj: obj.set_y(val))
lv.anim_set_exec_cb(anim, obj, obj.set_y)
Either lvgl... or lv.... in both cases.
From the user perspective, any python callable object (such as python regular function, class function, lambda etc.) can be user as an lvgl callbacks. (should read callback without s)
Please send me a pull request with these fixes.
English is not my native language so I appreciate any corrections.
When calling:
a.set_exec_cb(a,arc,arc.set_value)
I get TypeError: function takes 2 positional arguments but 4 were given
You should use
a.set_exec_cb(lv.arc.set_value)
- You don't need to pass
a
again toset_exec_cb
. - You don't need to pass
arc
here. You should calla.set_var(arc)
- You need to pass
lv.arc.set_value
(and notarc.set_value
) because you are passing a function pointer toset_value
.
Here is a complete example:
arc = lv.arc(scr)
a=lv.anim_t()
a.init()
a.set_exec_cb(lv.arc.set_value)
a.set_var(arc)
a.set_time(1000)
a.set_values(0, 100)
lv.anim_t.start(a)
The reason we call lv.anim_t.start(a)
and not a.start()
is because of ambiguity.
The struct lv_anim_t
already contains an integer member called start
, which shadows the member function lv_anim_start
.
from lv_demos.
I did a copy / paste of the code above and tried it.
I get:
SyntaxError: Cannot convert 'function' to pointer!
when trying to call
a.set_exec_cb(lv.arc.set_value)
from lv_demos.
SyntaxError: Cannot convert 'function' to pointer!
when trying to call
a.set_exec_cb(lv.arc.set_value)
You are right. In recent versions member functions in all forms can no longer be converted to pointers.
I would need to look into it.
To overcome this, you can use set_custom_exec_cb
instead and delegate the call to arc.set_value
.
For example:
arc = lv.arc(scr)
a=lv.anim_t()
a.init()
a.set_custom_exec_cb(lambda a, val: arc.set_value(val))
a.set_time(1000)
a.set_values(0, 100)
lv.anim_t.start(a)
Do not call set_var
when using set_custom_exec_cb
.
from lv_demos.
This issue or pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from lv_demos.
Related Issues (20)
- please fix lv_demo_music_main.c HOT 1
- error with lv_examples.h in arduino HOT 1
- Using LV_ demo_ benchmark(); During template compilation, the following contents will appear, as if img is not defined? HOT 4
- For which version of LVGL are these demos? HOT 2
- lv_demo_widgets problem - no buffer size info HOT 3
- Add /* clang-format off */ HOT 2
- lv_demo_benchmark causes floating point exception HOT 2
- lv_demo_music_list.c “font_small” and “font_medium” Pointer on const HOT 1
- This [lv_demo_widgets] may not be used strictly. Why const? HOT 1
- time variable naming conflict HOT 1
- we need create this chart, what should i do? HOT 1
- lv_demo_music_main.c implicit declaration of function HOT 2
- #132 breaks build HOT 4
- We try to use shadows to achieve this effect, but how to remove this line HOT 4
- lv_demo_widgets, no member "text_length" HOT 6
- lv_demo_widgets, no display HOT 14
- demo, wrong pixel / lines ( glitched rendering ) HOT 9
- lv_demo_benchmark, Arithmetic exception, in lv_sim_vscode_sdl
- Could you offer a simplest demo? HOT 4
- Would a PR to update to v8.3.1 of lvgl be considered? HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lv_demos.