guild icon
Toit
#action repeater (solved)
Thread channel in help
kaxori
kaxori 06/27/2023 09:17 AM
I use this code section to wait for timeout or button action:

exception := catch --unwind=(: it != DEADLINE_EXCEEDED_ERROR):
with_timeout --ms=SensorInterval:

// wait for button press&release
pushButton.wait_for 0
sleep --ms=10 // Debounce.
pushButton.wait_for 1
sleep --ms=10 // Debounce.

Is it possible to add a 3rd way to terminate the wait, (i.e. programatically by external mqtt event ) ?
floitsch
floitsch 06/27/2023 04:17 PM
I think the "easiest" is to wait in two different tasks and to kill the other one when one finishes.
floitsch
floitsch 06/27/2023 04:17 PM
Could be that Task.group --required=1 would do the trick, but I need to check the source for that. https://libs.toit.io/core/task/class-Task#group(2%2C0%2C0%2Crequired)
floitsch
floitsch 06/27/2023 04:19 PM
Looking at the code (https://github.com/toitlang/toit/blob/master/lib/core/task.toit#L146) it looks like Task.group with --required=1 should work.
@bitphlipphar am I missing anything, or do you agree?
Program your microcontrollers in a fast and robust high-level language. - toit/lib/core/task.toit at master ยท toitlang/toit
bitphlipphar
bitphlipphar 06/27/2023 04:21 PM
Yeah, that should work. You want one task that waits for a latch set by some mqtt event and one that waits for a timeout or button push.
kaxori
kaxori 06/29/2023 02:54 PM
Thanks for your help.
It works :๐Ÿคฉ:
floitsch
floitsch 06/29/2023 03:03 PM
looks good.
Naming convention isn't really Toit, but that's minor.
I would put the led := ? into the main function, since it's only used there anyway.
Otherwise should work as expected. :๐Ÿ‘:
kaxori
kaxori 06/29/2023 03:33 PM
already done
i need a linter/formatter/beautyfier to generate beautyful code
floitsch
floitsch 06/29/2023 03:34 PM
On my TODO list. Unfortunately requires a few compiler refactorings...
kaxori
kaxori 06/29/2023 03:36 PM
the code exchange between different coders would be so much easier.
I am quiet happy if functionalty works and dont't like to tidy up think..
floitsch
floitsch 06/29/2023 03:37 PM
Fully agree.
kaxori
kaxori 06/29/2023 03:40 PM
have you ever thought to use something like: AsciiDoc or Doxygen ... ?
floitsch
floitsch 06/29/2023 04:07 PM
Yes. We looked into it, but it didn't fullfill the needs we had.
floitsch
floitsch 06/29/2023 04:10 PM
Also looked into whether we can use readthedocs.io but it didn't really fit.
floitsch
floitsch 06/29/2023 04:10 PM
Tbh, has been a while since I looked into it, so I don't remember all the reasons.
floitsch
floitsch 06/29/2023 04:11 PM
And are you asking for toitdocs or the "normal" documentation?
kaxori
kaxori 06/29/2023 10:08 PM
I asked for documenting the code, I like the concept of having documentation together with code.
I you are forgetful (I am !), you have to keep your ideas, concepts, ... . I tried some tools: Mindmap, doxygen (static code analysis), asciidoc (graphics in code), Obsidian (markdown network), Goodnotes (handwriting) ... but nothing is perfect.

So sharing ideas between different brains on a higher abstraction level than code would be more efficient.
floitsch
floitsch 06/29/2023 10:08 PM
In that case we have toitdoc.
floitsch
floitsch 06/29/2023 10:10 PM
It's very similar to markdown. Main difference is that you can reference Toit language elements (with $) and that we don't require an empty line for new paragraphs. Instead we indent continuations of a previous paragraph.
floitsch
floitsch 06/29/2023 10:11 PM
floitsch
floitsch 06/29/2023 10:13 PM
I just noticed that the document isn't fully up to date (the links section). I will fix that tomorrow if I don't forget.
floitsch
floitsch 06/29/2023 10:13 PM
The special sections haven't been implemented yet either.(edited)
kaxori
kaxori 06/29/2023 10:21 PM
But these info is provided by the "toit/jaguar- language/system-developers".
I meant the developers/programmers of "shared"- examples(snippets, modules), libs, applications. Most toit I have seen up to now, hadn't a common sense of docs.
floitsch
floitsch 06/29/2023 10:24 PM
Libraries and modules should use toitdocs (see for example the ds18b20 driver: https://pkg.toit.io/github.com/toitware/[email protected]/docs/ds18b20/class-Ds18b20).

For additional information GitHub's READMEs should work fine.
floitsch
floitsch 06/29/2023 10:26 PM
Eventually we would like to have a similar amount of documentation as flutter has in their dartdocs, but that takes time and effort.
kaxori
kaxori 06/30/2023 05:51 AM
DS1820-doc :๐Ÿ‘๐Ÿป:
but, if i search for ds1820 in https://libs.toit.io/ there is no result/link to above named page :๐Ÿค”:
(edited)
kaxori
kaxori 06/30/2023 05:55 AM
The search engine should find everything and link to the right docs.
kaxori
kaxori 06/30/2023 06:26 AM
OK, I found it: https://pkg.toit.io/search?query=ds18b20
but only with the precise description, should also work with fuzzy search
kaxori
kaxori 06/30/2023 06:26 AM
I like the graphics
floitsch
floitsch 06/30/2023 06:42 AM
libs.toit.io only covers the core libraries. The packages all have their own toitdoc pages.
It would probably make sense to combine them, but we tried to make packages independent. Anybody should be able to run their own registry.
The search on pkg.toit.io doesn't index the toitdocs (yet?). In fact it only generates the documentation lazily at first access.
kaxori
kaxori 06/30/2023 10:40 AM
Discovering more and more docs :๐Ÿ˜:
kaxori
kaxori 06/30/2023 10:43 AM
:๐Ÿ‘ฎ๐Ÿปโ€โ™‚๏ธ: Is there a toit policemen ?
Found // and /// rule for single line comments, which is now valid ?
bitphlipphar
bitphlipphar 06/30/2023 11:37 AM
Both are valid comments, but /// introduces a toitdoc comment; see https://docs.toit.io/language/sdk/toitdoc/#syntax.
floitsch
floitsch 06/30/2023 11:39 AM
Note that I have plans to make /// and /** .. */ inside code to get some of the toitdoc features.
Specifically $foo being a reference to a Toit entity.
This way you could write:
main: x := 499 y := x + 1 /// Takes $x and increments it.
Would allow to ctrl-click and give warnings if the reference goes stale. (Just like in toitdocs).
35 messages in total