Create simple a project¶
Open the compose editor by running ‘ufsm-compose’.
A good start is to open the project settings menu and set a project name and maybe adjust the canvas size. The project settings menu is opened by pressing ‘p’
Create a model by adding normal states ‘a-s’ (Add state). Set the state names by pressing ‘e-n’ (Edit - name).
See Editor commands for a more comprehensive list of commands.
Translate model to code:
$ ufsm-generate c led.ufsm .
This command generates led.c and led.h which contains the state machine.
Example code:
#include <stdio.h>
#include "led.h"
void led_on(void *context)
{
printf("LED ON\n");
}
void led_off(void *context)
{
printf("LED OFF\n");
}
int main(int argc, char **argv)
{
struct led_machine m;
led_init(&m, NULL);
led_process(&m, eToggle);
led_process(&m, eToggle);
led_process(&m, eToggle);
led_process(&m, eToggle);
led_process(&m, eToggle);
return 0;
}
Build the example:
gcc simple.c led.c -o led
Source code: examples/simple