Content deleted Content added
No edit summary |
syntaxhighlight & fix lint |
||
(14 intermediate revisions by 11 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 14 ⟶ 18:
==Bug in program==
There's a bug in this program as state_init == state_red, but there's separate STATE_INIT and STATE_RED states, so red will initially be on for 60 secs, not 30. [[User:Genjix|Genjix]] ([[User talk:Genjix|talk]]) 03:24, 17 March 2008 (UTC)
==Possible bug in program==
The variable 'operation' is set to 1 at the beginning of the program, and never changed afterwards. Hard to see what the point is. <small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Davep88|Davep88]] ([[User talk:Davep88|talk]] • [[Special:Contributions/Davep88|contribs]]) 05:42, 24 June 2011 (UTC)</span></small><!-- Template:Unsigned --> <!--Autosigned by SineBot-->
==Controversiality==
Why isn't there any discussion of why state machines could be a bad idea? This code could be a million times clearer if it was allowed to explicitly pend on events. <span class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/216.31.211.11|216.31.211.11]] ([[User talk:216.31.211.11|talk]]) 00:03, 11 September 2008 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
: Because in places they're used, at any particular time the object must be able to respond to any one of several possible events which could happen. For instance, a traffic light that normally switches based on a timer could have an input that's switched by an emergency vehicle. This would alter the pattern to give the vehicle right of way when it is detected. The code can't be looping just looking at the timer when it needs to also respond to the emergency vehicle switch.--[[Special:Contributions/71.214.211.129|71.214.211.129]] ([[User talk:71.214.211.129|talk]]) 17:02, 18 September 2010 (UTC)
The example code is a FSM, but the style is very bad.
Any FSM (so the fucntion with that name) shoud do 2 things:<br />
* Set/compute (or at least return) the next state
* Execute a (list of) actions.
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}}
|