Explanation required for Code

Status
Not open for further replies.

adnan012

Advanced Member level 1
Joined
Oct 6, 2006
Messages
468
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Visit site
Activity points
4,923
What this piece of code is doing?


Code:
typedef enum {
 st_idle = 0,
 st_init = 1,
 st_run  = 2,
 st_rst  = 3,           
}state_t;

typedef enum {   
 ev_none        = 0,
 ev_any         = 1,
 ev_key_pressed = 2,
 ev_cmd         = 3,       
 ev_time_out    = 4,
}event_t;

typedef struct {
  
 state_t current_event;
 event_t event;
 state_t next_state; 
        
}stateTranMatrix;

static stateTranMatrix st_Matrix[] = {
  
    {st_idle , ev_none , st_init},
    {st_init , ev_none , st_idle},     
};

Regards!

[moderator action: added CODE tags]
 
Last edited by a moderator:

Hello!

This piece of code is not doing much. It just defines enumerations (typedef enum),
defines a structure and a matrix. That's about it. Without seeing the rest of the code,
it's hard to predict what it will actually do.

Dora.
 

According to blog the author provides a working example at github. Why don't you simply run it?

Blog chapter 10 discusses how to call the state machine.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…