3 ms·
I posted a gist [0] sorry it's not really made for public scrutiny, it's an old pet project clock, a video of most of that code is still there: https://plus.goo
by buserror 10y ago
I posted a gist [0] sorry it's not really made for public scrutiny, it's an old pet project clock, a video of most of that code is still there: https://plus.google.com/+MichelPollet/posts/ARDMrY4jSxp https://plus.google.com/+MichelPollet/posts/ARDMrY4jSxp
That code does timer, radio clock decoding, scrolling, blinking and all that using multiple 'protothreads'. As you can see the main loop sleep() and wait for a timer interrupt (or anything) to fire to wake up, so it's not even running most of the time; only when the 'tick' timer fires.
[0] https://gist.github.com/buserror/9407adb6d52153e16caad5e8a0844023 https://gist.github.com/buserror/9407adb6d52153e16caad5e8a08...
- pcmonk 10y agoCan you point to the usage of Duff's device there? I'm not really seeing it.
- iainmerrick 10y agoFollowing footnotes on Wikipedia led me to this nice clear explanation: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
- mzs 10y agoThank you, when I saw this blog post it reminded me that years ago I had seen something similar but even more brain melting - it was PuTTY!
- buserror 10y agoThe trick is on the PT_ macros really, they hide the switch, case and gotos. I'll post the header later, but you probably can find it by googling for protothreads
- pcmonk 10y agoAh, I see it now. Thanks!
- josephg 10y agoWhoa, PT is fantastic. A full explanation of how it works is here: http://dunkels.com/adam/pt/expansion.html http://dunkels.com/adam/pt/expansion.html Its actually a really simple and beautiful. I worry that we give up a lot of this sort of flow expressiveness in more modern languages like Rust.
- i336_ 10y agoThe one thing I really really like: you can see the hour/minute colon separate flashing as it scrolls. This is really cool.