diff --git a/.vscode/settings.json b/.vscode/settings.json index e5d36d8..77b6ec4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,8 @@ "dead_mario.h": "c", "unity.h": "c", "string.h": "c" - } + }, + "cSpell.words": [ + "CFSM" + ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 81f7dd4..74f0671 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # # Implementing State pattern in C # -# Copyright (C) 2024 Haju Schulz +# Copyright (C) 2024-2025 Haju Schulz # cmake_minimum_required(VERSION 3.11) set (CMAKE_C_STANDARD 99) @@ -15,9 +15,9 @@ project(CFSM ) # ****************************************************************************** -# Enable strict compiler warnings +# Enable strict compiler warnings # ****************************************************************************** - + if (MSVC) # warning level 4 add_compile_options(/W4) @@ -28,7 +28,7 @@ endif() add_subdirectory(src) -set (CFSM_EXAMPLE_MARIO_SRC +set (CFSM_EXAMPLE_MARIO_SRC "examples/mario/main.c" "examples/mario/mario.c" "examples/mario/states/small_mario.c" diff --git a/LICENSE b/LICENSE index bbd9840..c2c3ac7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License - Copyright (C) 2024 Haju Schulz +Copyright (C) 2024-205 Haju Schulz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a1163b9..80180c8 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ constructs. ![State Pattern](http://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/nhjschulz/cfsm/master/doc/cfsm_statepattern.puml) The state pattern builds on + * A context that delegates operations to one of various state objects, which is currently the active state. * A number of state objects that implement context operations to provide @@ -52,6 +53,7 @@ use cases: ![State Diagram](http://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/nhjschulz/cfsm/master/doc/cfsm_context.puml) There are operations to execute + 1. When the FSM "enters" a state, meaning it becomes the current active one. 2. When the FSM "leaves" a state, meaning some other state becomes active 3. When a cyclic processing in the active state shall take place @@ -88,12 +90,13 @@ typedef struct cfsm_Ctx { ``` Notes: - * All operations in a state are optional, with the exception of the enter - operation. A state that cannot be entered is pointless. - * Operations that are not defined in a state are ignored by CFSM. - * Supporting "other" operations can be done by adding new, or - changing existing functions pointers in the context. CFSM - is primarily an implementation pattern, not a fixed function library. + +* All operations in a state are optional, with the exception of the enter + operation. A state that cannot be entered is pointless. +* Operations that are not defined in a state are ignored by CFSM. +* Supporting "other" operations can be done by adding new, or + changing existing functions pointers in the context. CFSM + is primarily an implementation pattern, not a fixed function library. ### CFSM States @@ -128,8 +131,8 @@ void SuperMario_onEnter(cfsm_Ctx * fsm) State transitions are triggered by calling the ```cfsm_transition()``` API function. The call can originate -1. from the CFSM using application to enter a specific state -2. from inside the state operation handlers +1. From the CFSM using application to enter a specific state. +2. From inside the state operation handlers. The following interaction diagram shows what happens during a state transition from state "Mario" to "SuperMario": @@ -191,10 +194,10 @@ Here are the transitions shown as a table: The example uses CFSM to implement the Mario state machine in the following way: - * Each Mario character is a state implemented in an own C-File. - * The collection of items or the monster hits are modelled as events. - * The process operation prints a character specific message. - * The enter/leave operations print a message to visualize these transitions. +* Each Mario character is a state implemented in an own C-File. +* The collection of items or the monster hits are modelled as events. +* The process operation prints a character specific message. +* The enter/leave operations print a message to visualize these transitions. The main loop of the example implements a small menu where events get fired based on user input to simulate the game. @@ -285,7 +288,7 @@ different state implementing modules. Here is a transcript of first game simulation steps: - ``` + ```txt $ cfsm_mario.exe (1) SmallMario_onEnter()... (2) SmallMario_onProces(): It's me, Mario! @@ -350,17 +353,16 @@ other modules to transition into it. The first two lines are the actions that the enter handler performs. In this example it - * prints a message to show the user it got called. In real code such - a call would not be there or would be using some debug logging api. - * updates our Mario to become a small one. +* prints a message to show the user it got called. In real code such + a call would not be there or would be using some debug logging pi. +* updates our Mario to become a small one. The final 3 lines update the CFSM context to delegate operations to the SmallMario state. Note that unused handlers don't need to be set to NULL. The -``cfsm_transition()`` API has done this before calling the -enter operation. Only the needed handlers must be set here -(if any). +```cfsm_transition()``` API has done this before calling the enter +operation. Only needed handlers must be set here (if any). #### The Small Mario Leave Operation @@ -402,7 +404,7 @@ event signal operation is implemented as a switch over the event ids. The call to ``mario_updateCoins()`` extracts the coin awards into a helper function. The amount of coins depend on the event, not on the state. Directly implementing it inside the states would cause -code dublication. +code duplication. The individual event cases trigger a transition from small to another Mario dependent on the event. Noteworthy is the slightly more complex @@ -450,7 +452,7 @@ not needed and therefore also not present at all. The CFSM pattern is surprisingly simple. There are no complex logic sequences or loops in CFSM. Processing boils down to a NULL checked function pointer call to delegate operation requests to state -dependend handlers. This simplicity makes the pattern also usable +dependent handlers. This simplicity makes the pattern also usable for functional safety applications. The functionality is easy to test and review. @@ -476,4 +478,3 @@ CFSM achieves the following benefits code duplication. This is usually addressed in OO Languages by introducing base classes for states. C-Language doesn't offer such concepts and CFSM does not try to mimic such OO behavior in C-language. - diff --git a/examples/UnoBlink/README.md b/examples/UnoBlink/README.md index 03ad0d2..767bcb0 100644 --- a/examples/UnoBlink/README.md +++ b/examples/UnoBlink/README.md @@ -1,17 +1,17 @@ # Arduino Blink with CFSM This is a boilerplate code example for -[CFSM](https://github.com/nhjschulz/cfsm) based applications. -It is build on top of Arduino and implements a CFSM version of +[CFSM](https://github.com/nhjschulz/cfsm) based applications. +It is build on top of Arduino and implements the CFSM version of the "led-blink" sketch, the embedded system version of -"hello world". It gets build using +"hello world". It gets build using [PlatformIO](https://platformio.org/) and is configured for Arduino UNO. But it will run on any Arduino supported platform -with an onboard led by updating ```platform.ini```. +with an onboard LED by updating ```platform.ini```. ## Blinking with a State Machine -The blink sketch toggles a led on or off, resulting in +The blink sketch toggles a LED on or off, resulting in two distinct states that can be mapped to FSM states. The first is representing "On", the second "Off". The transitions between the states happen after fixed time intervals. In @@ -31,14 +31,14 @@ different transition methods for going to on or off. ## CFSM Blink Example -The example is based on PlatformIO 's Arduino template with a main module -implementing the ```setup()``` and ```loop()``` methods. +The example is based on PlatformIO 's Arduino template with a main module +implementing the ```setup()``` and ```loop()``` methods. It includes CFSM as an external library using the ```lib_deps``` variable in ```platformio.ini```. ~~~{.ini} lib_deps = - nhjschulz/CFSM@^0.2.0 + nhjschulz/CFSM@^1.0.0 ~~~ The example is following this SW architecture: @@ -51,31 +51,32 @@ The example is following this SW architecture: ![Setup Sequence Diagram](http://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/nhjschulz/cfsm/master/examples/UnoBlink/doc/BlinkSetup.puml) -### Arduino Loop Transition into OffState +### Arduino Loop Transition into OffState The sequence starts while CFSM is in OnState: ![Setup Sequence Diagram](http://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/nhjschulz/cfsm/master/examples/UnoBlink/doc/BlinkOnToOff.puml) -## Arduino Loop Transition into OnState +## Arduino Loop Transition into OnState The sequence starts while CFSM is in OffState: ![Setup Sequence Diagram](http://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/nhjschulz/cfsm/master/examples/UnoBlink/doc/BlinkOffToOn.puml) -Note that there is a little difference between the transitions: -* "On" state processes the transition inside the process operation. -* "Off" state does not use the process operation. The state works event based. That's why - CFSM instantly returns on the process() request in this state. +Note the little difference between the transitions: + +* "On" state processes the transition inside the process operation. +* "Off" state does not use the process operation. The state works event based. That's why + CFSM instantly returns on the process() request in this state. ## Running the Example The onboard led will toggle on and off after every second when the example got flashed. Serial monitor prints -will print the progress also to a serial port. The +will print the progress also to a serial port. The output looks like this: -~~~ +~~~txt OnState: enter() OnState: LED On time has expired ! OnState: leave() @@ -86,4 +87,3 @@ OffState: leave() OnState: enter() ... ~~~ - diff --git a/examples/UnoBlink/doc/BlinkClass.puml b/examples/UnoBlink/doc/BlinkClass.puml index ade4d08..52d4104 100644 --- a/examples/UnoBlink/doc/BlinkClass.puml +++ b/examples/UnoBlink/doc/BlinkClass.puml @@ -6,7 +6,7 @@ - blinkFsm : cfsm_Ctx +setup() +loop() - + } @@ -25,8 +25,8 @@ class BlinkData <> { - - ledPin : int - - turnOnTimeMillis : uint64_t + + ledPin : int + + turnOnTimeMillis : uint64_t } @@ -44,7 +44,7 @@ package "CFSM" { +onProcess() +onEvent() } - +} cfsm_Ctx - Operations OnState .u-|> Operations @@ -53,6 +53,9 @@ OffState .u-|> Operations Main .l.> cfsm_Ctx : \n\nSignal LED_ON\n every 2 seconds Main .> OnState : transition to\nin setup() -states .> BlinkData: <> +OffState .> BlinkData: <> +OnState .> BlinkData: <> + Main .d..> BlinkData: <> + @enduml \ No newline at end of file diff --git a/examples/UnoBlink/doc/BlinkOffToOn.puml b/examples/UnoBlink/doc/BlinkOffToOn.puml index 9d3fa4b..01f6ed4 100644 --- a/examples/UnoBlink/doc/BlinkOffToOn.puml +++ b/examples/UnoBlink/doc/BlinkOffToOn.puml @@ -1,4 +1,5 @@ -@startuml CFSM stateAlias1 --> stateAlias2 : messageOrCond2 <> +@startuml CFSM state LED on + autoactivate on participant Arduino @@ -25,11 +26,12 @@ Cfsm <- OffState : transition(OnState) Cfsm -> OffState : onLeave() Cfsm <-- OffState Cfsm -> OnState: OnEnter() -OnState -> Led #LightGray: turned on +OnState -> Led #LightGray: turn on Cfsm <-- OnState Cfsm --> OffState Cfsm <-- OffState Main <-- Cfsm Arduino <-- Main end + @enduml \ No newline at end of file diff --git a/examples/UnoBlink/doc/BlinkOnToOff.puml b/examples/UnoBlink/doc/BlinkOnToOff.puml index e42e238..62baa9b 100644 --- a/examples/UnoBlink/doc/BlinkOnToOff.puml +++ b/examples/UnoBlink/doc/BlinkOnToOff.puml @@ -1,5 +1,5 @@ -@startuml CFSM stateAlias1 --> stateAlias2 : messageOrCond2 <> -autoactivate on +@startuml CFSM state LED off + participant Arduino participant Main @@ -7,20 +7,35 @@ participant Cfsm participant OnState participant OffState Actor Led + activate Led #LightGray Arduino -> Main : loop() +activate Main Main -> Cfsm : process() +activate Cfsm Cfsm -> OnState : onProcess() +activate OnState alt 1 second since enter of OnState OnState -> Cfsm: transition(OffState) + activate Cfsm Cfsm -> OnState: onLeave() + activate OnState Cfsm <-- OnState + deactivate OnState Cfsm -> OffState : onEnter() - OffState <-- Led : turned off + activate OffState + OffState -> Led : turn off + deactivate Led Cfsm <-- OffState + deactivate OffState Cfsm --> OnState + deactivate Cfsm Cfsm <-- OnState + deactivate OnState Main <-- Cfsm + deactivate Cfsm Arduino <-- Main + deactivate Main end + @enduml \ No newline at end of file diff --git a/examples/UnoBlink/doc/BlinkSetup.puml b/examples/UnoBlink/doc/BlinkSetup.puml index 0c3e08a..77f1e46 100644 --- a/examples/UnoBlink/doc/BlinkSetup.puml +++ b/examples/UnoBlink/doc/BlinkSetup.puml @@ -1,4 +1,5 @@ -@startuml CFSM stateAlias1 --> stateAlias2 : messageOrCond2 <> +@startuml CFSM state + autoactivate on participant Arduino @@ -13,7 +14,7 @@ Main -> Cfsm : init fsm context Main <-- Cfsm Main -> Cfsm : transition(OnState) Cfsm -> OnState : onEnter() -OnState -> Led #LightGray : turned on +OnState -> Led #LightGray : turn on Cfsm <-- OnState Main <-- Cfsm Arduino <-- Main diff --git a/examples/UnoBlink/doc/BlinkState.puml b/examples/UnoBlink/doc/BlinkState.puml index 781cdcb..4069e92 100644 --- a/examples/UnoBlink/doc/BlinkState.puml +++ b/examples/UnoBlink/doc/BlinkState.puml @@ -1,10 +1,11 @@ @startuml Blink State Machine -state OnState -state OffState -OnState -l-> OffState: one Second\npassed -OffState --> OnState: Event\nLED_ON +state OnState: /enter turn on LED +state OffState: /leave turn off LED + +OnState --> OffState: one Second\npassed +OffState --> OnState: Event(LED_ON) [*] -> OnState diff --git a/examples/UnoBlink/platformio.ini b/examples/UnoBlink/platformio.ini index db574b8..49bce1f 100644 --- a/examples/UnoBlink/platformio.ini +++ b/examples/UnoBlink/platformio.ini @@ -12,6 +12,6 @@ platform = atmelavr board = uno framework = arduino - + lib_deps = nhjschulz/CFSM@^0.2.0 \ No newline at end of file diff --git a/examples/UnoBlink/src/blinkdata.h b/examples/UnoBlink/src/blinkdata.h index 03c4187..dee26ef 100644 --- a/examples/UnoBlink/src/blinkdata.h +++ b/examples/UnoBlink/src/blinkdata.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -36,7 +36,7 @@ /** * @brief Blink FSM application instance data - * + * */ typedef struct BlinkCtx { int ledPin; /**< Arduino Led pin number */ @@ -45,7 +45,7 @@ typedef struct BlinkCtx { /** * @brief Events understood by the FSM - * + * */ enum BlinkEvents { BLINK_EVENT_ON = 42 /**< Led turn on event ID*/ diff --git a/examples/UnoBlink/src/main.cpp b/examples/UnoBlink/src/main.cpp index eee07a0..dbc27e0 100644 --- a/examples/UnoBlink/src/main.cpp +++ b/examples/UnoBlink/src/main.cpp @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** - * @brief Blink CFSM based Application Example for Arduino + * @brief Blink CFSM based Application Example for Arduino * * Repository: https://github.com/nhjschulz/cfsm/tree/master/examples/UnoBlink */ @@ -44,14 +44,14 @@ static cfsm_Ctx blinkFsm; /** * @brief Blink application data used by the blink FSM. - * + * * Contains the PIN id used for led toggling. */ static struct BlinkCtx blinkData = { LED_BUILTIN, 0ull }; /** * @brief Arduino setup function - * + * */ void setup() { @@ -64,9 +64,9 @@ void setup() /** * @brief Arduino loop function - * + * */ -void loop() +void loop() { cfsm_process(&blinkFsm); /* Do work in current CFSM state. */ diff --git a/examples/UnoBlink/src/states/OffState.cpp b/examples/UnoBlink/src/states/OffState.cpp index 54c76aa..aa10123 100644 --- a/examples/UnoBlink/src/states/OffState.cpp +++ b/examples/UnoBlink/src/states/OffState.cpp @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,9 +38,9 @@ /** * @brief CFSM event operation for OFF state - * + * * React on led ON event to transition to ON state. - * + * * @param fsm CFSM state machine context * @param eventId event ID */ @@ -58,9 +58,9 @@ static void OffState_onEvent(cfsm_Ctx * fsm, int eventId) /** * @brief CFSM state leave operation for Off state - * + * * Only used to print leave operation to serial log in this example. - * + * * @param fsm CFSM state machine context */ static void OffState_Leave(struct cfsm_Ctx * fsm) @@ -70,9 +70,9 @@ static void OffState_Leave(struct cfsm_Ctx * fsm) /** * @brief CFSM enter operation for OFF state - * + * * Turn LED off. - * + * * @param fsm CFSM state machine context */ void OffState_enter(cfsm_Ctx * fsm) diff --git a/examples/UnoBlink/src/states/OffState.h b/examples/UnoBlink/src/states/OffState.h index 6963c7e..e6b8c23 100644 --- a/examples/UnoBlink/src/states/OffState.h +++ b/examples/UnoBlink/src/states/OffState.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,7 @@ DESCRIPTION *******************************************************************************/ /** - * @brief Blink CFSM example: OFF State Definitons + * @brief Blink CFSM example: OFF State Definitions * */ @@ -34,7 +34,7 @@ /** * @brief Operation for entering LED off state - * + * * @param fsm FSM data structure */ extern void OffState_enter(struct cfsm_Ctx * fsm); diff --git a/examples/UnoBlink/src/states/OnState.cpp b/examples/UnoBlink/src/states/OnState.cpp index f85f071..a2b6a94 100644 --- a/examples/UnoBlink/src/states/OnState.cpp +++ b/examples/UnoBlink/src/states/OnState.cpp @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,10 +37,10 @@ #include "OffState.h" /** - * @brief Cyclic processing CFSM operaion for ON state - * - * Transition to Off state if time in state is larger/equal 1 second. - * + * @brief Cyclic processing CFSM operation for ON state + * + * Transition to Off state if time in state is larger/equal 1 second. + * * @param fsm CFSM state machine context */ static void OnState_process(cfsm_Ctx * fsm) @@ -56,9 +56,9 @@ static void OnState_process(cfsm_Ctx * fsm) /** * @brief CFSM state leave operation for ON state - * + * * Only used to print leave operation to serial log in this example. - * + * * @param fsm CFSM state machine context */ static void OnState_leave( cfsm_Ctx * fsm) @@ -68,9 +68,9 @@ static void OnState_leave( cfsm_Ctx * fsm) /** * @brief CFSM enter operation for ON state - * + * * Record time and turn LED on. - * + * * @param fsm CFSM state machine context */ void OnState_enter(cfsm_Ctx * fsm) @@ -82,7 +82,7 @@ void OnState_enter(cfsm_Ctx * fsm) digitalWrite(ctx->ledPin, HIGH); /* turn LED on */ ctx->turnOnTimeMillis = millis(); /* record time in context */ - /* register ON state hanlders with CFSM */ + /* register ON state handlers with CFSM */ fsm->onProcess = OnState_process; fsm->onLeave = OnState_leave; } diff --git a/examples/UnoBlink/src/states/OnState.h b/examples/UnoBlink/src/states/OnState.h index 8d221e2..668a0ef 100644 --- a/examples/UnoBlink/src/states/OnState.h +++ b/examples/UnoBlink/src/states/OnState.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,7 @@ DESCRIPTION *******************************************************************************/ /** - * @brief Blink CFSM example: ON State Definitons + * @brief Blink CFSM example: ON State Definitions * */ @@ -34,7 +34,7 @@ /** * @brief Operation for entering LED On state - * + * * @param fsm FSM data structure */ extern void OnState_enter(struct cfsm_Ctx * fsm); diff --git a/examples/mario/main.c b/examples/mario/main.c index d61ef0d..80b42a9 100644 --- a/examples/mario/main.c +++ b/examples/mario/main.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief CFSM Mario state handling example - * + * * @addtogroup MarioExample * * @{ @@ -67,7 +67,7 @@ int main(int argc, char **argv) { (void)argc; (void)argv; - + cfsm_Ctx marioFsm; puts ("Mario cfsm example: \n"); @@ -75,7 +75,7 @@ int main(int argc, char **argv) cfsm_init(&marioFsm, NULL); cfsm_transition(&marioFsm, SmallMario_onEnter); - for(;;) + for(;;) { int option; @@ -96,7 +96,7 @@ int main(int argc, char **argv) } /* process signal in current CFSM state */ - if (NOP != option) + if (NOP != option) { cfsm_event(&marioFsm, option); } diff --git a/examples/mario/mario.c b/examples/mario/mario.c index 39280bd..2819e85 100644 --- a/examples/mario/mario.c +++ b/examples/mario/mario.c @@ -1,7 +1,7 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,7 +27,7 @@ *******************************************************************************/ /** * @brief CFSM Mario state handling example - * + * * @addtogroup MarioExample * * @{ @@ -50,11 +50,11 @@ *****************************************************************************/ /** - * @brief Mario data - * + * @brief Mario data + * * Start with small mario, 3 lifes and no coins */ -static MarioData mario = +static MarioData mario = { SMALL_MARIO, 3, @@ -115,7 +115,7 @@ void mario_updateCoins(MarioEvent e) case MONSTER: break; - + case QUIT: case NOP: break; @@ -132,7 +132,7 @@ void mario_updateCoins(MarioEvent e) extern void mario_print(void) { printf( - "Mario: Variant: %s Lifes: %d Coins: %d\n", + "Mario: Variant: %s Lifes: %d Coins: %d\n", variantNames[mario.variant], mario.lifes, mario.coins); diff --git a/examples/mario/mario.h b/examples/mario/mario.h index a0561b1..113ff7c 100644 --- a/examples/mario/mario.h +++ b/examples/mario/mario.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,10 +25,10 @@ DESCRIPTION *******************************************************************************/ /** - * @brief Mario CFSM example - * + * @brief Mario CFSM example + * * Repository: https://github.com/nhjschulz/cfsm - * + * * @addtogroup MarioExample * * @{ @@ -85,14 +85,14 @@ typedef struct MarioData { /** * @brief Changes the variant of Mario - * + * * @param v the new variant */ extern void mario_setVariant(MarioVariant v); /** * @brief Update Marios coins based on the event - * + * * @param e the event to get payed for */ extern void mario_updateCoins(MarioEvent e); @@ -104,7 +104,7 @@ extern void mario_print(void); /** * @brief Take a life from Mario - * + * * @return int number of remaining lifes */ extern int mario_takeLife(void); diff --git a/examples/mario/states/cape_mario.c b/examples/mario/states/cape_mario.c index 650770a..436bbc4 100644 --- a/examples/mario/states/cape_mario.c +++ b/examples/mario/states/cape_mario.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/examples/mario/states/cape_mario.h b/examples/mario/states/cape_mario.h index 8eda47c..1c6721d 100644 --- a/examples/mario/states/cape_mario.h +++ b/examples/mario/states/cape_mario.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/examples/mario/states/dead_mario.c b/examples/mario/states/dead_mario.c index 5c2706c..8d67408 100644 --- a/examples/mario/states/dead_mario.c +++ b/examples/mario/states/dead_mario.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Super Mario State Handling - * + * * @addtogroup MarioExample * * @{ diff --git a/examples/mario/states/dead_mario.h b/examples/mario/states/dead_mario.h index 7ed7456..5281dc4 100644 --- a/examples/mario/states/dead_mario.h +++ b/examples/mario/states/dead_mario.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Dead Mario State Handling - * + * * @addtogroup MarioExample * * @{ diff --git a/examples/mario/states/fire_mario.c b/examples/mario/states/fire_mario.c index b444ff8..5859c86 100644 --- a/examples/mario/states/fire_mario.c +++ b/examples/mario/states/fire_mario.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Fire Mario State Handling - * + * * @addtogroup MarioExample * * @{ @@ -121,7 +121,7 @@ void FireMario_onProcess(cfsm_Ctx * fsm) void FireMario_onLeave(cfsm_Ctx * fsm) { (void)fsm; - + puts("FireMario_onLeave() ..."); } diff --git a/examples/mario/states/fire_mario.h b/examples/mario/states/fire_mario.h index a4b6302..02a236c 100644 --- a/examples/mario/states/fire_mario.h +++ b/examples/mario/states/fire_mario.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Fire Mario State Handling - * + * * @addtogroup MarioExample * * @{ diff --git a/examples/mario/states/small_mario.c b/examples/mario/states/small_mario.c index 0a0fae3..75d81c7 100644 --- a/examples/mario/states/small_mario.c +++ b/examples/mario/states/small_mario.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Small Mario State Handling - * + * * * @{ */ @@ -88,7 +88,7 @@ void SmallMario_onEnter(cfsm_Ctx * fsm) static void SmallMario_onEvent(cfsm_Ctx * fsm, int eventId) { (void)fsm; - + mario_updateCoins(eventId); switch(eventId) diff --git a/examples/mario/states/small_mario.h b/examples/mario/states/small_mario.h index bbc982e..32e4941 100644 --- a/examples/mario/states/small_mario.h +++ b/examples/mario/states/small_mario.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Small Mario State Handling - * + * * @addtogroup MarioExample * * @{ diff --git a/examples/mario/states/super_mario.c b/examples/mario/states/super_mario.c index 47f295f..5d8f05a 100644 --- a/examples/mario/states/super_mario.c +++ b/examples/mario/states/super_mario.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Super Mario State Handling - * + * * @addtogroup MarioExample * * @{ @@ -119,7 +119,7 @@ static void SuperMario_onProcess(cfsm_Ctx * fsm) static void SuperMario_onLeave(cfsm_Ctx * fsm) { (void)fsm; - + puts("SuperMario_onLeave() ..."); } diff --git a/examples/mario/states/super_mario.h b/examples/mario/states/super_mario.h index c08d58d..a884fb6 100644 --- a/examples/mario/states/super_mario.h +++ b/examples/mario/states/super_mario.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ *******************************************************************************/ /** * @brief Super Mario State Handling - * + * * @addtogroup MarioExample * * @{ diff --git a/library.json b/library.json index ff9bdd2..97c9942 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "name": "CFSM", - "version": "0.3.0", + "version": "1.0.0", "description": "A State Design Pattern for State Machines in C-Language", "keywords": "state design pattern, FSM, C-Language", "repository": { diff --git a/library.properties b/library.properties index 786f76a..be9fc01 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=CFSM -version=0.3.0 +version=1.0.0 author=Haju Schulz maintainer=Haju Schulz sentence=A State Design Pattern for State Machines in C-Language. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 947f04a..588c7ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ # Build CFSM as a static link library which is used by example code. # ****************************************************************************** -add_library(cfsm +add_library(cfsm c_fsm.c ) diff --git a/src/c_fsm.c b/src/c_fsm.c index edf7052..ecdfe76 100644 --- a/src/c_fsm.c +++ b/src/c_fsm.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/c_fsm.h b/src/c_fsm.h index 1705216..875dc10 100644 --- a/src/c_fsm.h +++ b/src/c_fsm.h @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -52,8 +52,8 @@ extern "C" { * Macros *****************************************************************************/ -#define CFSM_VER_MAJOR 0 /**< semantic versioning major X.x.x */ -#define CFSM_VER_MINOR 3 /**< semantic versioning minor x.X.x */ +#define CFSM_VER_MAJOR 1 /**< semantic versioning major X.x.x */ +#define CFSM_VER_MINOR 0 /**< semantic versioning minor x.X.x */ #define CFSM_VER_PATCH 0 /**< semantic versioning patch x.x.X */ /****************************************************************************** @@ -155,7 +155,7 @@ void cfsm_process(struct cfsm_Ctx * fsm); * process cycles. * * An example for an event id could be a UI button press - * to trigger a state dependend reaction. + * to trigger a state dependent reaction. * * @param fsm The fsm data structure * @param eventId An application defined ID to identify the event. diff --git a/tests/test_c_fsm.c b/tests/test_c_fsm.c index df07e53..10a0319 100644 --- a/tests/test_c_fsm.c +++ b/tests/test_c_fsm.c @@ -1,6 +1,6 @@ /* MIT License * - * Copyright (C) 2024 Haju Schulz + * Copyright (C) 2024-2025 Haju Schulz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal