Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the MicroPython simulator #1320

Closed
5 of 6 tasks
embeddedt opened this issue Dec 22, 2019 · 240 comments
Closed
5 of 6 tasks

Improve the MicroPython simulator #1320

embeddedt opened this issue Dec 22, 2019 · 240 comments
Labels
pinned Not closed automatically

Comments

@embeddedt
Copy link
Member

embeddedt commented Dec 22, 2019

The MicroPython simulator is online and ready to use, but needs to be polished further.

Here is a list of improvements compiled by @amirgon:

  • Monaco Editor
  • Allow changing the various pane sizes
  • Try to improve Frame-Rate
  • Host SnippetBin backend on LittlevGL server instead of Heroku
  • Improve styling of the html, Bootstrap
  • Support loading fonts on runtime on lvgl. This would allow sharing snippets with custom fonts
@embeddedt

This comment has been minimized.

@amirgon
Copy link
Contributor

amirgon commented Dec 22, 2019

it's actually no better than our existing editor on its own, because it requires a language server running for anything beyond basic syntax coloring.

@embeddedt have a look at this example from here:
image

the same code on Ace editor:
image

What I like about Monaco is

  • It looks cleaner, nicer color and fonts, feels more modern
  • There is a "document map" on the right that can help scrolling

So it's not a big difference, but even without a language server I think Monaco is nicer.

@puzrin
Copy link
Contributor

puzrin commented Dec 26, 2019

Host SnippetBin backend on LittlevGL server instead of Heroku

There are other alternatives:

  • gists
  • URL-encoded content, in anchor (up to 2K should work everywhere, don't remember upper limit)

@embeddedt
Copy link
Member Author

embeddedt commented Dec 26, 2019

We already discussed those other alternatives, but they had a number of downsides (mainly spam concerns and size limitations). We concluded that SnippetBin was the best choice.

@stale stale bot added the stale label Jan 17, 2020
@embeddedt embeddedt added pinned Not closed automatically and removed stale labels Jan 17, 2020
@lvgl lvgl deleted a comment from stale bot Jan 17, 2020
@amirgon
Copy link
Contributor

amirgon commented Jan 17, 2020

Allow changing the lvgl screen size

Micropython SDL driver now accepts parameters for screen width and height.
So only need to dynamically set canvas size in order to implement this in the simulator.

See:

@embeddedt
Copy link
Member Author

I think we need a hook for adjusting the window size after initialization as well.

@amirgon
Copy link
Contributor

amirgon commented Jan 17, 2020

I think we need a hook for adjusting the window size after initialization as well.

To simplify things, what if you let the user adjust it by interactively dragging the window edges?
If it's too small, then only part of the viewport would be visible.

@kisvegabor
Copy link
Member

To simplify things, what if you let the user adjust it by interactively dragging the window edges?

It'd be great, but I don't know if @embeddedt has time and interest to do it.

@embeddedt
Copy link
Member Author

I'm definitely interested in making it work, but finding the time is an issue. I definitely won't be able to start on this before February.

@kisvegabor
Copy link
Member

No problem. We can add @amirgon's updates and improve it further when you can find time for it.

@embeddedt
Copy link
Member Author

I've started working on replacing the existing editor with Monaco. Hopefully I can get it done this weekend.

@embeddedt
Copy link
Member Author

Here's a teaser. 😉

Screenshot_2020-02-09 LittlevGL MicroPython Simulator

I'm working on ironing out the last few issues, then I'll push this to the lvgl_javascript branch.

@embeddedt
Copy link
Member Author

The changes are pushed and live on https://sim.littlevgl.com. Let me know if you think anything needs adjusting.

@kisvegabor
Copy link
Member

Look nice!
What were the "Á" characters in the screenshot?

@amirgon
Copy link
Contributor

amirgon commented Feb 10, 2020 via email

@embeddedt
Copy link
Member Author

@kisvegabor

What were the "Á" characters in the screenshot?

At the time, the page was set to use ISO-8859-1 for the character encoding (not UTF-8), so I think it was interpreting   as Á, or something like that.

@amirgon

I'm currently traveling, I'll have a look after I'm back next week.

No rush; have a safe trip!

@amirgon
Copy link
Contributor

amirgon commented Feb 14, 2020

The changes are pushed and live on https://sim.littlevgl.com. Let me know if you think anything needs adjusting.

@embeddedt it's not working for me.
I'm getting:

main.65321e8f.js:1097 Uncaught ReferenceError: mp_js_stdout is not defined
    at main.65321e8f.js:1097
    at dispatch (jquery-1.12.4.js:5226)
    at elemData.handle (jquery-1.12.4.js:4878)

fit.min.js:1 Uncaught TypeError: Cannot read property 'parentElement' of undefined
    at o (fit.min.js:1)
    at n (fit.min.js:1)
    at a.e.fit (fit.min.js:1)
    at main.65321e8f.js:1097
    at dispatch (jquery-1.12.4.js:5226)
    at elemData.handle (jquery-1.12.4.js:4878)

I'm using latest Chrome (Version 78.0.3904.70 (Official Build) (64-bit)) on Linux.

@embeddedt
Copy link
Member Author

Hmm. It seemed to be working for me on Firefox when I wrote that message, but I've just tried it now in Chrome and it is in fact not working.

I'll take a look when I get a chance. In the meantime, my latest commit to https://github.com/littlevgl/sim should be reverted (I'll try and do that today).

@embeddedt
Copy link
Member Author

Fixed... it should start working once GitHub Pages deploys my latest commit.

@kisvegabor
Copy link
Member

kisvegabor commented Feb 15, 2020

I've just tried the new version and it works well in Firefox but the "Restart" button remains inactive in Chrome.

@embeddedt
Copy link
Member Author

@kisvegabor GitHub had issues with the new version for some reason (I got an error about one of the symlinks in the repository), so I think you're still seeing the old version. I'll fix it today.

@embeddedt
Copy link
Member Author

The new version is pushed and appears to work fine in Chrome now.

Note that you may need to press Ctrl+F5 if it doesn't work the first time, as Chrome may still be caching the old, broken version.

@amirgon
Copy link
Contributor

amirgon commented Feb 15, 2020

The new version is pushed and appears to work fine in Chrome now.

It does not work when passing script parameter:

https://sim.littlevgl.com/micropython/ports/javascript/bundle_out/index.html?script=https://raw.githubusercontent.com/littlevgl/lv_binding_micropython/master/examples/advanced_demo.py&cache_buster=7

main.cb19d18d.js:formatted:119808 Uncaught ReferenceError: total is not defined
    at XMLHttpRequest.o.onreadystatechange (main.cb19d18d.js:formatted:119808)

Also, could you list the parameters that the simulator accepts? (script, init_script, cache_buster etc.)


EDIT

One more thing I noticed - it seems like you are using an older micropython version:

MicroPython v1.11-904-g32e3cc4d5 on 2020-02-08; JS with Emscripten
Type "help()" for more information.
>>> import sys
>>> sys.implementation
(name='micropython', version=(1, 11, 0))
>>> 

Recent lv_micropython version is 1.12.

@kisvegabor
Copy link
Member

kisvegabor commented Jan 8, 2022

I also got a question: In the latest master the API of lv_draw_rect has changed so e.g. line 50 of this example shouldn't work.

It seems the simulator based on the last release and not master. Is that correct?

embeddedt added a commit to lvgl/lv_micropython that referenced this issue Jan 8, 2022
@embeddedt
Copy link
Member Author

Any idea why f-strings are not working on the online simulator?

Apparently, they were disabled in the JavaScript port's mpconfigport.h. This should be fixed now. Unfortunately I can't test it yet as GitHub has cached the older simulator version for the next few hours, apparently.

It seems the simulator based on the last release and not master. Is that correct?

The simulator is based on master, because that's what lv_micropython is based on. However, lv_micropython doesn't get updated automatically at the moment. @amirgon periodically bumps the submodule.

The logic for the JavaScript simulator uses the version number in lvgl.h to decide what URL to push to. So, once @amirgon bumps the LVGL submodule on lv_micropython, this example will break, as master still has 8.1 as its version number.

I suppose, once there are breaking changes, lvgl.h probably needs to be updated to at least the next minor version to ensure this doesn't happen.

@kisvegabor
Copy link
Member

The logic for the JavaScript simulator uses the version number in lvgl.h to decide what URL to push to. So, once @amirgon bumps the LVGL submodule on lv_micropython, this example will break, as master still has 8.1 as its version number.

Thanks for the explanation.
v8.2 released soon so we can fix the MP examples for it.

@amirgon
Copy link
Contributor

amirgon commented Jan 10, 2022

Apparently, they were disabled in the JavaScript port's mpconfigport.h. This should be fixed now. Unfortunately I can't test it yet as GitHub has cached the older simulator version for the next few hours, apparently.

Strange, I still get this problem even after "Clear Site Data" which clears the cache.
@embeddedt are you sure this is fixed?

However, lv_micropython doesn't get updated automatically at the moment. @amirgon periodically bumps the submodule.

That's right.
The reason I don't do that automatically is because every such "bump" requires merging the binding's lv_conf.h.
Sometimes this merge is not trivial and requires some thought, not something that can be done automatically.

v8.2 released soon so we can fix the MP examples for it.

I'm tracking LVGL releases so I'll get notified when v8.2 is released and will bump the Micropython bindings shortly afterwards.

@embeddedt
Copy link
Member Author

embeddedt commented Jan 10, 2022

Strange, I still get this problem even after "Clear Site Data" which clears the cache.

I know. Something went wrong this time, as the build date is still December 10th. It's not serving what I built on Saturday for some reason. I just haven't had a chance to fix it yet.

I tried pushing a non-code-related change; maybe it'll work this time.

@amirgon
Copy link
Contributor

amirgon commented Jan 28, 2022

@embeddedt I've update lv_micropython, fixed conflicts on the javascript branch, all GitHub action completed, cleared browser's cache... but I still see the older version of the simulator (v1.17 instead of v1.18).
What am I missing?

@embeddedt
Copy link
Member Author

I've finally discovered that GitHub Pages has been failing to rebuild the sim repository since mid-December due to some submodule-related issue with the v6 version of MicroPython. I should have it working again in a couple of minutes.

@amirgon
Copy link
Contributor

amirgon commented Jan 29, 2022

I should have it working again in a couple of minutes.

Simulator shows v1.18 now! Thanks.

@amirgon
Copy link
Contributor

amirgon commented Jan 29, 2022

@embeddedt I suspect there is still some deployment problem.
I made a fix to frozen modules and there are some problems with the online simulator.
For example, this hangs on the simulator, but works on the unix port (on latest lv_micropython).

I'm seeing some errors on Chrome Devtools, I'm not sure if they are related:
Aborted(Assertion failed: The call to mp_js_do_str is running asynchronously. If this was intended, add the async option to the ccall/cwrap call.)
Module.printErr @ lvgl_mp.js:38
abort @ lvgl_mp.js:1591
assert @ lvgl_mp.js:788
ccall @ lvgl_mp.js:858
(anonymous) @ lvgl_mp.js:873
decompressScript @ lvgl.html:67
window.startRunning @ lvgl.html:100
(anonymous) @ lvgl_mp.js:48
setTimeout (async)
mainProgram @ lvgl_mp.js:48
doRun @ lvgl_mp.js:9913
run @ lvgl_mp.js:9930
runCaller @ lvgl_mp.js:9872
removeRunDependency @ lvgl_mp.js:1572
receiveInstance @ lvgl_mp.js:1734
receiveInstantiationResult @ lvgl_mp.js:1751
Promise.then (async)
(anonymous) @ lvgl_mp.js:1780
Promise.then (async)
instantiateAsync @ lvgl_mp.js:1777
createWasm @ lvgl_mp.js:1809
(anonymous) @ lvgl_mp.js:9302
lvgl_mp.js:1599 Uncaught RuntimeError: Aborted(Assertion failed: The call to mp_js_do_str is running asynchronously. If this was intended, add the async option to the ccall/cwrap call.)
    at abort (lvgl_mp.js:1599:11)
    at assert (lvgl_mp.js:788:5)
    at ccall (lvgl_mp.js:858:5)
    at lvgl_mp.js:873:12
    at decompressScript (lvgl.html:67:4)
    at window.startRunning (lvgl.html:100:5)
    at lvgl_mp.js:48:27
abort @ lvgl_mp.js:1599
assert @ lvgl_mp.js:788
ccall @ lvgl_mp.js:858
(anonymous) @ lvgl_mp.js:873
decompressScript @ lvgl.html:67
window.startRunning @ lvgl.html:100
(anonymous) @ lvgl_mp.js:48
setTimeout (async)
mainProgram @ lvgl_mp.js:48
doRun @ lvgl_mp.js:9913
run @ lvgl_mp.js:9930
runCaller @ lvgl_mp.js:9872
removeRunDependency @ lvgl_mp.js:1572
receiveInstance @ lvgl_mp.js:1734
receiveInstantiationResult @ lvgl_mp.js:1751
Promise.then (async)
(anonymous) @ lvgl_mp.js:1780
Promise.then (async)
instantiateAsync @ lvgl_mp.js:1777
createWasm @ lvgl_mp.js:1809
(anonymous) @ lvgl_mp.js:9302
lvgl_mp.js:38 user callback triggered after application aborted.  Ignoring.
Module.printErr @ lvgl_mp.js:38
callUserCallback @ lvgl_mp.js:4621
(anonymous) @ lvgl_mp.js:4644
setTimeout (async)
safeSetTimeout @ lvgl_mp.js:4642
(anonymous) @ lvgl_mp.js:7817
handleSleep @ lvgl_mp.js:8744
_emscripten_scan_registers @ lvgl_mp.js:7812
imports.<computed> @ lvgl_mp.js:8630
$gc_collect @ firmware.wasm:0x100809
$py_gc_collect @ firmware.wasm:0xbae7f
$fun_builtin_0_call @ firmware.wasm:0x75104
$mp_call_method_n_kw @ firmware.wasm:0x534ee
$dynCall_iiii @ firmware.wasm:0x57ee80
ret.<computed> @ lvgl_mp.js:8666
(anonymous) @ lvgl_mp.js:1643
invoke_iiii @ lvgl_mp.js:9578
imports.<computed> @ lvgl_mp.js:8630
$mp_execute_bytecode @ firmware.wasm:0xcda40
$fun_bc_call @ firmware.wasm:0x76083
$mp_call_function_0 @ firmware.wasm:0x52f0d
$dynCall_ii @ firmware.wasm:0x57eb6e
ret.<computed> @ lvgl_mp.js:8666
(anonymous) @ lvgl_mp.js:1643
invoke_ii @ lvgl_mp.js:9512
imports.<computed> @ lvgl_mp.js:8630
$do_str @ firmware.wasm:0xffae9
$mp_js_do_str @ firmware.wasm:0x100509
ret.<computed> @ lvgl_mp.js:8666
(anonymous) @ lvgl_mp.js:1643
ccall @ lvgl_mp.js:845
(anonymous) @ lvgl_mp.js:873
decompressScript @ lvgl.html:67
window.startRunning @ lvgl.html:100
(anonymous) @ lvgl_mp.js:48
setTimeout (async)
mainProgram @ lvgl_mp.js:48
doRun @ lvgl_mp.js:9913
run @ lvgl_mp.js:9930
runCaller @ lvgl_mp.js:9872
removeRunDependency @ lvgl_mp.js:1572
receiveInstance @ lvgl_mp.js:1734
receiveInstantiationResult @ lvgl_mp.js:1751
Promise.then (async)
(anonymous) @ lvgl_mp.js:1780
Promise.then (async)
instantiateAsync @ lvgl_mp.js:1777
createWasm @ lvgl_mp.js:1809
(anonymous) @ lvgl_mp.js:9302
lvgl.html:29 Uncaught TypeError: Illegal invocation
    at HTMLDocument.document.querySelector (lvgl.html:29:12)
    at <anonymous>:3:32
    at <anonymous>:53:7

embeddedt added a commit to lvgl/lv_micropython that referenced this issue Jan 29, 2022
@embeddedt
Copy link
Member Author

embeddedt commented Jan 29, 2022

It was a simulator-specific issue (not related to the 1.18 update). I've fixed it now.

@amirgon
Copy link
Contributor

amirgon commented Jan 29, 2022

I've fixed it now

It works now! Thanks.

@kisvegabor
Copy link
Member

I'm cleaning up the old pinned issues.

This one is already quite long so I suggest opening a new more targeted issue for the remaining ideas.

@amirgon
Copy link
Contributor

amirgon commented May 28, 2022

I still think it's best to host SnippetBin backend on LVGL server instead of Heroku (although this wasn't a blocker so far).
I'm Ok with closing this issue.

@kisvegabor
Copy link
Member

kisvegabor commented May 30, 2022

As I mentioned earlier, it'd be possible to build a service around the "online editor" concept but our (business) focus is now on SquareLine.

Ok, so I close it now. Please open a new issue(s), if something related comes up.

@embeddedt
Copy link
Member Author

@amirgon I am doing some refactoring/rewriting of the simulator frontend to make it cleaner and easier to maintain. Currently I have all features implemented again except the revision history slider, since the logic for it is a bit complicated. Do you use it often/do you think it's necessary? If you think it's worth keeping, I will add it back.

@amirgon
Copy link
Contributor

amirgon commented Jun 7, 2022

Do you use it often/do you think it's necessary? If you think it's worth keeping, I will add it back.

I'm using it from time to time. I'm not sure if others do.

The snippetbin backend supports it by maintaining everything in a git repository.
In my opinion it's a nice feature and too bad to throw it away just because of some frontend improvements.

Can't you simply keep the slider we have today? It doesn't have to look pretty as long as it's functional.

@amirgon
Copy link
Contributor

amirgon commented Jul 9, 2022

@embeddedt The javascript merge workflow fails, but I'm not sure why.
I tried checking out lvgl_javascript_v8 locally and merging master to it, but git doesn't report any merge conflicts. Why did the workflow fail if there are no merge conflicts? Am I doing something wrong?

@embeddedt
Copy link
Member Author

I'm not sure. I know there were recently efforts to change the merge algorithm in Git, so it's possible that your local version does merges slightly differently. I'd just push a manual merge this time. I can do it if you'd prefer.

@amirgon
Copy link
Contributor

amirgon commented Aug 29, 2022

@embeddedt Could you add a link to v9 in https://sim.lvgl.io/ ?
btw, where is this index file stored? Is it in GitHub or on some web server?

@embeddedt
Copy link
Member Author

Updated.

https://github.com/lvgl/sim/blob/master/index.html

@embeddedt
Copy link
Member Author

FYI, GitHub announced that they also updated their merge algorithm, so the inconsistency between a local machine and GitHub when merging is hopefully a thing of the past.

@amirgon
Copy link
Contributor

amirgon commented Sep 16, 2022

FYI, GitHub announced that they also updated their merge algorithm, so the inconsistency between a local machine and GitHub when merging is hopefully a thing of the past.

Interesting!
Thanks for the update.

@amirgon
Copy link
Contributor

amirgon commented Nov 4, 2022

@embeddedt any idea why the javascript port build failed here?

Run benc-uk/workflow-dispatch@v1
🏃 Workflow Dispatch Action v1.2.1
🔎 Found workflow, id: 31073294, name: Build Javascript v9 port, path: .github/workflows/js-port-v9.yml
🚀 Calling GitHub API to dispatch workflow...
Error: No ref found for: 

@embeddedt
Copy link
Member Author

embeddedt commented Nov 5, 2022

I have no idea; that is a new error. I have just committed a typo fix to make the CI run; let's see if it occurs again.

EDIT: Seems to be benc-uk/workflow-dispatch#50; I've applied the workaround described in that issue.

EDIT 2: The error this time was a permission error because the bot is not allowed to modify workflow files (which it would do by merging the commit which added the workaround 😆). That error should not occur again.

@amirgon
Copy link
Contributor

amirgon commented Nov 5, 2022

EDIT: Seems to be benc-uk/workflow-dispatch#50; I've applied the workaround described in that issue.

EDIT 2: The error this time was a permission error because the bot is not allowed to modify workflow files (which it would do by merging the commit which added the workaround laughing). That error should not occur again.

Looks ok now. Thanks!

@amirgon
Copy link
Contributor

amirgon commented Dec 19, 2022

@embeddedt Another problem, looks like some permissions issue?

https://github.com/lvgl/lv_micropython/actions/runs/3734837215/jobs/6337366663

@embeddedt
Copy link
Member Author

Like last time it's because commits that touch the workflow files need to be merged by one of us. I have just done the merge manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned Not closed automatically
Projects
None yet
Development

No branches or pull requests

10 participants