zia
Full Member level 5
- Joined
- Sep 24, 2010
- Messages
- 284
- Helped
- 27
- Reputation
- 54
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Islamabad Pakistan
- Activity points
- 2,746
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 //State Machine //state_machine.c //Test state machine framework #include<stdio.h> typedef enum {ST_1=0 , ST_2=1, ST_3=3, ST_4=4} State_Type; //## Prototypes ##// void Init_StateTBL(void); void st_1(void); void st_2(void); void st_3(void); void st_4(void); void (*state_table[])(void) = {st_1, st_2, st_3, st_4}; State_Type curr_state; void main(void){ printf("Start /n"); Init_StateTBL(); while(1){ state_table[curr_state](); } return; } //#### Functions ####// void Init_StateTBL(void){ curr_state = ST_1; printf("Init_StateTBL /n"); return; } void st_1(){ curr_state = ST_2; printf("ST_1 /n"); return; } void st_2(){ curr_state = ST_3; printf("ST_2 /n"); return; } void st_3(){ curr_state = ST_4; printf("ST_3 /n"); return; } void st_4(){ curr_state = ST_1; printf("ST_4 /n"); return; }
"Does nothing" isn't the point, it's apparently meaned as a template.you wrote a case/ switch statement which does nothing at all. And does it badly too !!
"Does nothing" isn't the point, it's apparently meaned as a template.
But I'm missing a substantiation. Why is it "beautiful"?
And what's bad? Wasting code and data space? Wearing the computer keyboard? Or even worse?
Its bad because it wasted all of our time. And its hardly a template. It's a nothing.
Whats the matter with you guys ?
Now I think you are overreacting.
Sharing an opinion for the posted code is one thing but we are not going to contempt zia for making that post!
zia has just shared what he considered as useful, I don't see why you have to spend time with this post and then hold it against the OP, you can just bypass it.
Yes Sir !!
(hangs head in shame)
I apologise.....
It IS a beautifully written template which can be immediately applied to many state-machine applications with suitable modifications & expansions. The mods would be very easy to do using this template and of course changing the state transitions depending on whatever inputs are relevant, and not necessarily limited to Kbd+LCD menu's
In the form shown, it simply steps through the 4 states sequentially, displaying the state as it goes.
cheers!
Its bad because it wasted all of our time. And its hardly a template. It's a nothing.
Whats the matter with you guys ?
I don't find your irony funny, as a matter of fact is pisses me off and I don't appreciate people who make fun of others.
But i meant it sincerely ... really !! :sad:
thats amazing. you wrote a case/ switch statement which does nothing at all. And does it badly too !!
Wow
Its bad because it wasted all of our time. And its hardly a template. It's a nothing.
Whats the matter with you guys ?
Yes Sir !!
(hangs head in shame)
I apologise.....
It IS a beautifully written template which can be immediately applied to many state-machine applications with suitable modifications & expansions. The mods would be very easy to do using this template and of course changing the state transitions depending on whatever inputs are relevant, and not necessarily limited to Kbd+LCD menu's
In the form shown, it simply steps through the 4 states sequentially, displaying the state as it goes.
hi i posted it just for optimizationof code and making code a professional touch which is highly used in lcd gui with buttons.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?