Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an optional context pointer #40

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a4e0293
Make trigger function more synchronous with new parameter immidiate. …
Troyhy Dec 1, 2017
82a6853
Added defaults parameters, solved initialization bug that causes crash
Mar 20, 2019
11f07b9
implemented reset of the timer
stellarshenson Mar 26, 2020
c8f239f
fixed small code issues
stellarshenson Mar 26, 2020
46cd8db
reduced code size and debugged timers
stellarshenson Mar 26, 2020
58d6504
updated documentation
stellarshenson Mar 26, 2020
bf5a4b6
added get_current_state method
stellarshenson Mar 26, 2020
5a551e1
added get current state method and tested
stellarshenson Mar 26, 2020
f4910a2
Added optional context
tig Jul 6, 2021
234de69
merged pr #29(Added defaults parameters, solved initialization bug th…
tig Jul 7, 2021
aafefbd
now includes fix to /jonblack/arduino-fsm/ PR #29
tig Jul 7, 2021
6f3b918
merged pr #34 Timed Transition Timer Reset
tig Jul 7, 2021
89ca9df
merges PR#22 (Mkae trigger async) from Troyhy:master. Fixes typos and…
tig Jul 7, 2021
06c3725
fixed spelling & other minor issues. Also delted Fsm.cpp from sample
tig Jul 7, 2021
e0d1c60
Made everying work with PlatformIO as well as Android IDE
tig Jul 9, 2021
8ec82be
re-merge with updated master
tig Jul 9, 2021
e0e686e
re-merged; I somehow lost changes
tig Jul 9, 2021
84cbf21
Used flash strings.
tig Jul 12, 2021
bce4015
Fixed get_current_state returning prev state when called in on_enter
tig Jul 12, 2021
d44bc79
Fixed get_current_state returning prev state when called in on_enter
tig Jul 12, 2021
c04a05d
fixed light_switch sample
tig Jul 12, 2021
95ff98a
added is_valid_event() for validating events
tig Jul 14, 2021
f2c5a08
bumped version
tig Jul 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ pix
*~
*.swp
*.swo

# VSCode
.vscode

# PlatformIO
.pio
23 changes: 16 additions & 7 deletions examples/light_switch/light_switch.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// If using PlatformIO, see the platformio.ini file for instructions
// on how to pick which sample to run

#include "Fsm.h"

// State machine variables
Expand All @@ -10,38 +13,43 @@ Fsm fsm(&state_light_off);
// Transition callback functions
void on_light_on_enter()
{
Serial.println("Entering LIGHT_ON");
Serial.println(F("Entering LIGHT_ON"));
}

void on_light_on_exit()
{
Serial.println("Exiting LIGHT_ON");
Serial.println(F("Exiting LIGHT_ON"));
}

void on_light_off_enter()
{
Serial.println("Entering LIGHT_OFF");
Serial.println(F("Entering LIGHT_OFF"));
}

void on_light_off_exit()
{
Serial.println("Exiting LIGHT_OFF");
Serial.println(F("Exiting LIGHT_OFF"));
}

void on_trans_light_on_light_off()
{
Serial.println("Transitioning from LIGHT_ON to LIGHT_OFF");
Serial.println(F("Transitioning from LIGHT_ON to LIGHT_OFF"));
}

void on_trans_light_off_light_on()
{
Serial.println("Transitioning from LIGHT_OFF to LIGHT_ON");
Serial.println(F("Transitioning from LIGHT_OFF to LIGHT_ON"));
}

// standard arduino functions
void setup()
{
Serial.begin(9600);
while (!Serial && !Serial.available()) {
}
delay(1000);

Serial.println(F("starting light_switch example"));

fsm.add_transition(&state_light_on, &state_light_off,
FLIP_LIGHT_SWITCH,
Expand All @@ -53,7 +61,8 @@ void setup()

void loop()
{
// No "fsm.run_machine()" call needed as no "on_state" funcions or timmed transitions exists
// "fsm.run_machine()" call needed because Fsm needs to be initialized
fsm.run_machine();
delay(2000);
fsm.trigger(FLIP_LIGHT_SWITCH);
delay(2000);
Expand Down
13 changes: 8 additions & 5 deletions examples/multitasking/multitasking.ino
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
// If using PlatformIO, see the platformio.ini file for instructions
// on how to pick which sample to run

// This example shows how two finite state machines can be used to simulate
// multitasking on an arduino. Two LED's are turned on and off at irregular
// intervals; the finite state machines take care of the transitions.

#include "Fsm.h"
#include <Fsm.h>

#define LED1_PIN 10
#define LED2_PIN 11

void on_led1_on_enter() {
Serial.println("on_led1_on_enter");
Serial.println(F("on_led1_on_enter"));
digitalWrite(LED1_PIN, HIGH);
}

void on_led1_off_enter() {
Serial.println("on_led1_off_enter");
Serial.println(F("on_led1_off_enter"));
digitalWrite(LED1_PIN, LOW);
}

void on_led2_on_enter() {
Serial.println("on_led2_on_enter");
Serial.println(F("on_led2_on_enter"));
digitalWrite(LED2_PIN, HIGH);
}

void on_led2_off_enter() {
Serial.println("on_led2_off_enter");
Serial.println(F("on_led2_off_enter"));
digitalWrite(LED2_PIN, LOW);
}

Expand Down
174 changes: 0 additions & 174 deletions examples/timed_switchoff/Fsm.cpp

This file was deleted.

11 changes: 7 additions & 4 deletions examples/timed_switchoff/timed_switchoff.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// If using PlatformIO, see the platformio.ini file for instructions
// on how to pick which sample to run

#include "Fsm.h"

/*
Expand Down Expand Up @@ -29,21 +32,21 @@ Fsm fsm(&state_led_off);
// Transition functions
void led_off()
{
Serial.println("led_off");
Serial.println(F("led_off"));
digitalWrite(LED_PIN, LOW);
}

void led_on()
{
Serial.println("led_on");
Serial.println(F("led_on"));
digitalWrite(LED_PIN, HIGH);
}

void check_button()
{
int buttonState = digitalRead(BUTTON_PIN);
if (buttonState == LOW) {
Serial.println("button_pressed");
Serial.println(F("button_pressed"));
fsm.trigger(BUTTON_EVENT);
}
}
Expand All @@ -60,7 +63,7 @@ void setup()
BUTTON_EVENT, NULL);
fsm.add_timed_transition(&state_led_on, &state_led_off, 3000, NULL);
fsm.add_transition(&state_led_on, &state_led_off, BUTTON_EVENT, NULL);
Serial.println("Setup END");
Serial.println(F("Setup END"));
}

void loop()
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=arduino-fsm
version=2.2.0
version=2.3.0
author=Jon Black <jon@humblecoder.com>
maintainer=Jon Black <jon@humblecoder.com>
sentence=A library for implementing a finite state machine
paragraph=Supports events for exiting and entering states.
category=Other
url=https://github.com/jonblack/arduino-fsm
architectures=avr
architectures=avr
21 changes: 21 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; NOTE: When changing these platformio.ini files it sometimes helps to delete
; the ./.pio folder before rebuilding.

[platformio]
; Uncomment one of the following to pick wwhich example PlatformIO will build & run
src_dir = ./examples/light_switch
;src_dir = ./examples/multitasking
;src_dir = ./examples/timed_switchoff

; This is just a default environment. Change it to match your Ardruino hardware.
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino

; Uncomment this to use the locally-built verison of the arduino-fsm library
lib_deps = file://src

; Uncomment this to use the verison of the arduino-fsm library found in the PlatformIO registry
;lib_deps = arduino-fsm