Talk:Event-driven finite-state machine: Difference between revisions

Content deleted Content added
SineBot (talk | contribs)
m Signing comment by Davep88 - "Bug in program: "
syntaxhighlight & fix lint
 
(7 intermediate revisions by 6 users not shown)
Line 1:
{{WikiProject banner shell|class=Start|1=
{{WikiProject Computing |importance=Low}}
}}
 
==Removed text==
I removed the following from the article, as it appears to be unencyclopeadic, and/or confusing or strange:
Line 29 ⟶ 33:
 
Why does this example do onnly halve of it (and other parts somewhere else? <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/62.177.151.49|62.177.151.49]] ([[User talk:62.177.151.49|talk]]) 11:36, 1 October 2008 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
 
==Hard to understand==
The text gives little information besides what one could figure out just from the term "event-driven finite-state machine" yeah, it's a machine that's event driven, big deal! What's are the benefits of event-driven, why should one use that? What's the caveats? What are events at all in programming context? The program listing itself is also hard to understand if you don't know C. What's switch(state)m where does "state" come from, its a variable, right? You define STATES state = ST_RADIO; and then suddenly state is switched. Where does it get it's value? switch(event) is at least filled by the function readEventFromMessageQueue(), but what is EVENTS readEventFromMessageQueue(void); doing? Comment says: "Usually this is a blocking function." what is a ''blocking'' function? I know only little programming someone with less or none experience only sees gibberish. Wouldn't it be better, to have it in ''readable'' pseudocode? Also the text describes "often used in telecommunication protocols" and then gives an example of a - car radio? --[[Special:Contributions/95.91.240.250|95.91.240.250]] ([[User talk:95.91.240.250|talk]]) 20:56, 21 October 2013 (UTC)
 
==Code is not event-driven==
The code shown is not event-driven. Event-driven involves two things: the client 1) registers its interest in certain or all events and 2) implements a method or handler where information about events is received. The Arduino IDE reference has quite a good example of this: the client declares its interest in events received via pin 13 and supplies the method blink() which should be called each time an event occurs. Note that the loop() function does nothing but log the current state.
<syntaxhighlight lang="text">
int pin = 13;
volatile int state = LOW;
 
void setup() {
pinMode(pin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(pin), blink, CHANGE);
}
 
void loop() {
digitalWrite(pin, state);
}
 
void blink() {
state = !state;
}
</syntaxhighlight>
<ref>https://www.arduino.cc/en/Reference/AttachInterrupt</ref>
 
{{reflist-talk}}