Espruino interrupts #4224
Replies: 1 comment
-
Posted at 2014-11-08 by thomc @manxome in a similar way you can attach an Interrupt to a pin on, say, an Arduino, you can set a watch on a pin in Espruino. When the pin changes (rises, falls, or both) it will call your function: http://www.espruino.com/Reference#l__global_setWatch Posted at 2014-11-08 by @allObjects @manxome, it does... and very cool, jus as @ThomC explains. Did JS a while a go for a lot... in 97, but got laughed at a lot by the .jsp 'fans' - even by my own kin - ... guess what: it's back bit time, for a while now and is THE client platform (with SimglePageApps instead of .jsp Web pages etc.). The mid 80' through mid 90' regarding client-server enjoying renaissance riding the easy to use Web http(s) protocol wave. Espruino uses interrupts for the setTimeot() and setIntervall(), Espruino is THE thing for exactly just one (1) battery for a life time due to the interrupt drivenness of the whole infrastructure. Put setBusyIndicator(LED1) and *setSleepIndicator(LED2) into your code and then you see how Espruino goes from activity to no activity to absolute silent Zzzzzzzzzz... until the next event wakes it up... totally different to the do loop in arduino's main. Arduino uses its speed to make you believe it is 'on interrupt'... and burns just (m)Amps... doing nothing but checking if it should do something or doing what you unconditionally tell to do. Yes, you can used interrupts too. Espruino does use interrupts for all it does. Espruino even provides commands to go to sleep and deep sleep... almost deep freeze... and comes back pretty quickly without frost bites... ;-) Your app knows when to enter what state and can use these commands. See examples used in reference. What programming languages did you use in the past? Posted at 2014-11-08 by Manxome OK, I found it in the FAQ page: http://www.espruino.com/FAQ
Thanks for the replies @ThomC and @allObjects, but I'm afraid I don't understand enough yet to reconcile your comments with the FAQ. Pretty sure I read that the Arduino can sleep and wake up on an interrupt and I was hoping to have that functionality on my Espruino Picos. From what you are saying, I am guessing it can, but I'm wondering what the limitations are. @allObjects, I used to write a lot of ASP web pages with JavaScript back in the late 90s. Also wrote a lot of C/C++/C#, as well as a bunch of APL a long time ago :) Posted at 2014-11-08 by @allObjects I'm sure you might miss some of APL's terseness in todays again verbose, COBOL like languages, such as Java. I miss some of Smalltalk's concise and consistent application of oo thinking combined with minimal syntax noise. From the constructs I like JavaScript a lot - just miss classes being 1st class objects... (which practically no other commonly used languages support either). Posted at 2014-11-09 by MrTimcakes Allow me to clear some things up with some examples.
This watch executes the ToggleLED function every time button 1 is pressed, this watch also induces a debounce for the button. Some more advanced information: Posted at 2014-11-09 by Manxome Thanks @ducky! It sounds like Espruino is handling interrupts internally, but I am still confused by the FAQ:
Posted at 2014-11-09 by DrAzzy I think the intent of that is to indicate that you can't manipulate hardware interrupt setup via peek/poke, based on it's location in the FAQ? I think that might be in reference to interrupts generated by the on-chip peripherals (i think digitalPulse uses one of the timers to tigger an interrupt), which aren't exposed via setWatch() Re sleep: You can also use setDeepSleep() to get power usage down even further. Posted at 2014-11-09 by Manxome Thanks @drazzy! That makes sense :) Posted at 2014-11-09 by @allObjects ...may be you could... and if poking does not get you there, poked assembler/machine code get's you there... but you should not... otherwise why Espruino/JavaScript in the first place (with which you then would mess). I like Espruino's implementation very much: it translates / maps the internal/low level things into the JavaScript application language layer. It even has the support for managing bursts of interrupts: they are queued in order to not get lost... and it convey as much 'realtime' feeling as possible: with the interrupt, additional context information - most importantly the time of the interrupt *including the time of the previous one - is provided and makes it available to the application. When the JavaScript engine finally catches up - the (next) interrupt is picked up from the queue and handled on the JavaScript level. So you could say: hardware events are mapped to software event, like you are used to Web-program on a button onclick="someJavaScript...;". Clicking with the mouse is a very hardware event, but it is finally handled in the application layer through a software event. Posted at 2014-11-10 by @gfwilliams Hi, Sorry I'm a bit late replying here - was away all weekend. I think it's all been explained, but hopefully this is more of a summary: Espruino uses interrupts internally, for quite a lot of things - setWatch, digitalPulse, serial, timers, waveforms, and so on. However that's only native code - JavaScript itself doesn't execute in an interrupt. If an interrupt needs JavaScript to be run then it puts a message in a queue (often with an accurate timestamp), and the JavaScript is run when the interpreter is next ready to do it. If Espruino is idle it'll basically have exactly the same effect as if you had an interrupt - but if it's busy then you'll have to wait a small time until the code is executed. The decision not to allow JS in interrupts is actually for a few reasons:
Having said all that, you can use In the mean time, it's actually pretty easy to compile Espruino yourself, and you can then add your own bits of C code (which can run on interrupts). Posted at 2014-11-10 by Manxome Thanks @gfwilliams and everyone! What an awesome, helpful, responsive and informative forum! My questions have been thoroughly answered :) Posted at 2014-11-10 by @allObjects Great overview! Thanks, @gfwilliams. #interrupts |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-11-08 by Manxome
Hello! I haven't programmed in JavaScript for at least a dozen years and I'm sure it has changed a bit over the years. I am also fairly new to the Arduiono/electronics/microcontroller/IOT/maker scene, but I am learning and enjoying it! I am an Espruino Pico backer and am really looking forward to playing with it and re-learning JS.
I noticed somewhere that Espruino JS doesn't support hardware interrupts. Is this true? If so, what would be the explanation? It seems like that could be a severe limitation. Please understand that I'm not at all trying to be negative against Espruino, I am just wondering what the reasons and ramifications are.
Thanks so much!
Manxome
Beta Was this translation helpful? Give feedback.
All reactions