بدون توضیح

redoc a0814dd9fb 调整state_previous赋值的地方,应在entry_action执行之前; 4 سال پیش
examples 033fb59d9d Update post_state.c 4 سال پیش
inc d1361cdad3 1、【更改】反馈参数; 5 سال پیش
src a0814dd9fb 调整state_previous赋值的地方,应在entry_action执行之前; 4 سال پیش
.gitignore 7f6b467c52 1、【增加】初版文件。 5 سال پیش
LICENSE a06d7e41da 1、【修正】license 5 سال پیش
README.md 4f5c1e0697 1、【增加】修改说明。 5 سال پیش
SConscript 7f6b467c52 1、【增加】初版文件。 5 سال پیش

README.md

state_machine

1、介绍

state_machine是基于RT-Thread格式移植的状态机软件包。 state_machine的作者是misje, github地址: https://github.com/misje/stateMachine 对该软件包进行了如下修改: 1.修复部分函数反馈,由void改为int,如果异常反馈负数; 2.修改状态儿子数的判断,如果这个状态没有儿子,还需要判断它的父亲(原作者不判断父亲,该状态会停掉);

使用方法

1.先申请一个状态结构,定义事件

enum event_type {
    EVENT_KEYBOARD,
};
struct state_machine m;

2.初始化状态对象

static struct state state_idle = {
    .state_parent = NULL,
    .state_entry = NULL,
    .transitions = (struct transition[]){
        { EVENT_KEYBOARD, (void *)(intptr_t)'t', &keyboard_char_compare, NULL, &state_next },// turn next state
		{ EVENT_KEYBOARD, (void *)(intptr_t)'d', &keyboard_char_compare, &action_fun, &state_idle },// do action
    },
    .transition_nums = 1,
    .data = "idle",
    .action_entry = &print_msg_enter,
    .action_exti = &print_msg_exit,
};

static struct state state_error = { 
    .data = "Error",
    .action_entry = &print_msg_err
};

3.初始化状态机

statem_init( &m, &state_idle, &state_error );
...

4.执行事件

statem_handle_event( &m, &(struct event){ EVENT_KEYBOARD, (void *)(intptr_t)ch } );

特性

state_machine 使用C语言实现,基于面向对象方式设计思路,每个状态对象单独用一份数据结构管理:

Examples

使用示例在 examples 下。