action repeater (solved)
# help
k
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 ) ?
f
I think the "easiest" is to wait in two different tasks and to kill the other one when one finishes.
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)
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. @kasperl am I missing anything, or do you agree?
k
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.
k
f
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. 👍
k
already done i need a linter/formatter/beautyfier to generate beautyful code
f
On my TODO list. Unfortunately requires a few compiler refactorings...
k
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..
f
Fully agree.
k
have you ever thought to use something like: AsciiDoc or Doxygen ... ?
f
Yes. We looked into it, but it didn't fullfill the needs we had.
Also looked into whether we can use
readthedocs.io
but it didn't really fit.
Tbh, has been a while since I looked into it, so I don't remember all the reasons.
And are you asking for toitdocs or the "normal" documentation?
k
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.
f
In that case we have toitdoc.
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.
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.
The special sections haven't been implemented yet either.
k
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.
f
Libraries and modules should use toitdocs (see for example the ds18b20 driver: https://pkg.toit.io/github.com/toitware/toit-ds18b20@2.0.0/docs/ds18b20/class-Ds18b20). For additional information GitHub's READMEs should work fine.
Eventually we would like to have a similar amount of documentation as flutter has in their dartdocs, but that takes time and effort.
k
DS1820-doc 👍🏻 but, if i search for ds1820 in https://libs.toit.io/ there is no result/link to above named page 🤔
The search engine should find everything and link to the right docs.
OK, I found it: https://pkg.toit.io/search?query=ds18b20 but only with the precise description, should also work with fuzzy search
I like the graphics

https://cdn.discordapp.com/attachments/1123180346096234516/1124224508463681546/image.png

f
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.
k
Discovering more and more docs 😁
👮🏻‍♂️ Is there a toit policemen ? Found // and /// rule for single line comments, which is now valid ?
k
Both are valid comments, but
///
introduces a toitdoc comment; see https://docs.toit.io/language/sdk/toitdoc/#syntax.
f
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:
Copy code
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).