poll button state in statechart and raise internal events on change

This commit is contained in:
Joeri Exelmans 2025-06-06 10:42:23 +02:00
parent 675efff85c
commit 45c0844fc2
5 changed files with 738 additions and 354 deletions

View file

@ -35,6 +35,7 @@ typedef struct StatechartTimeEvents StatechartTimeEvents;
#include "../src/sc_types.h"
#include "../src/sc_rxc.h"
#include "../src/sc_rxc_int32_t.h"
#include "../src/sc_rxc_bool.h"
#include "../src/sc_rxc_int32_t.h"
#include "../src/sc_rxc_int32_t.h"
@ -52,30 +53,37 @@ Header of the state machine 'Statechart'.
#ifndef STATECHART_IN_EVENTQUEUE_BUFFERSIZE
#define STATECHART_IN_EVENTQUEUE_BUFFERSIZE STATECHART_EVENTQUEUE_BUFFERSIZE
#endif
#ifndef STATECHART_INTERNAL_EVENTQUEUE_BUFFERSIZE
#define STATECHART_INTERNAL_EVENTQUEUE_BUFFERSIZE STATECHART_EVENTQUEUE_BUFFERSIZE
#endif
#ifndef SC_INVALID_EVENT_VALUE
#define SC_INVALID_EVENT_VALUE 0
#endif
/*! Define number of states in the state enum */
#define STATECHART_STATE_COUNT 6
#define STATECHART_STATE_COUNT 9
/*! Define dimension of the state configuration vector for orthogonal states. */
#define STATECHART_MAX_ORTHOGONAL_STATES 2
#define STATECHART_MAX_ORTHOGONAL_STATES 3
/*! Define maximum number of time events that can be active at once */
#define STATECHART_MAX_PARALLEL_TIME_EVENTS 1
/*! Define indices of states in the StateConfVector */
#define SCVI_STATECHART_MAIN_REGION_ON 0
#define SCVI_STATECHART_MAIN_REGION_ON_R1_RESPONDING 0
#define SCVI_STATECHART_MAIN_REGION_ON_R1_SENSOR_ERROR 0
#define SCVI_STATECHART_MAIN_REGION_ON_R2_NOT_PRESSED 1
#define SCVI_STATECHART_MAIN_REGION_ON_R2_PRESSED 1
#define SCVI_STATECHART_MAIN_REGION_OFF 0
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING 0
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_OFF 0
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON 0
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R1_RESPONDING 0
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R1_SENSOR_ERROR 0
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R2_NOT_PRESSED 1
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R2_PRESSED 1
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_POLLBUTTON_BUTTON0 2
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_POLLBUTTON_BUTTON1 2
/*
* Union of all possible event value types.
*/
typedef union {
int32_t Statechart_sensor_value;
sc_boolean Statechart_buttonState_value;
} statechart_event_value;
/*
@ -84,9 +92,10 @@ typedef union {
typedef enum {
Statechart_invalid_event = SC_INVALID_EVENT_VALUE,
Statechart_sensor,
Statechart_buttonPressed,
Statechart_buttonReleased,
Statechart_Statechart_main_region_on_r2_pressed_time_event_0
Statechart_buttonState,
Statechart_internal_buttonPressed,
Statechart_internal_buttonReleased,
Statechart_Statechart_main_region_everything_r1_on_r2_pressed_time_event_0
} StatechartEventID;
/*
@ -113,12 +122,15 @@ typedef struct statechart_eventqueue_s {
typedef enum
{
Statechart_last_state,
Statechart_main_region_on,
Statechart_main_region_on_r1_responding,
Statechart_main_region_on_r1_sensor_error,
Statechart_main_region_on_r2_not_pressed,
Statechart_main_region_on_r2_pressed,
Statechart_main_region_off
Statechart_main_region_everything,
Statechart_main_region_everything_r1_off,
Statechart_main_region_everything_r1_on,
Statechart_main_region_everything_r1_on_r1_responding,
Statechart_main_region_everything_r1_on_r1_sensor_error,
Statechart_main_region_everything_r1_on_r2_not_pressed,
Statechart_main_region_everything_r1_on_r2_pressed,
Statechart_main_region_everything_pollButton_button0,
Statechart_main_region_everything_pollButton_button1
} StatechartStates;
@ -129,8 +141,8 @@ struct StatechartIface
{
sc_boolean sensor_raised;
int32_t sensor_value;
sc_boolean buttonPressed_raised;
sc_boolean buttonReleased_raised;
sc_boolean buttonState_raised;
sc_boolean buttonState_value;
sc_observable_int32_t setMotorR;
sc_observable_int32_t setMotorL;
};
@ -140,6 +152,8 @@ struct StatechartIface
/*! Type declaration of the data structure for the StatechartInternal interface scope. */
struct StatechartInternal
{
sc_boolean buttonPressed_raised;
sc_boolean buttonReleased_raised;
int32_t speed;
pid_vars_t pid_vars;
};
@ -149,7 +163,7 @@ struct StatechartInternal
/*! Type declaration of the data structure for the StatechartTimeEvents interface scope. */
struct StatechartTimeEvents
{
sc_boolean statechart_main_region_on_r2_pressed_tev0_raised;
sc_boolean statechart_main_region_everything_r1_on_r2_pressed_tev0_raised;
};
@ -169,6 +183,8 @@ struct Statechart
StatechartTimeEvents timeEvents;
sc_boolean isExecuting;
sc_integer stateConfVectorPosition;
statechart_eventqueue internal_event_queue;
statechart_event internal_buffer[STATECHART_INTERNAL_EVENTQUEUE_BUFFERSIZE];
statechart_eventqueue in_event_queue;
statechart_event in_buffer[STATECHART_IN_EVENTQUEUE_BUFFERSIZE];
};
@ -196,10 +212,8 @@ extern void statechart_raise_time_event(Statechart* handle, sc_eventid evid);
/*! Raises the in event 'sensor' that is defined in the default interface scope. */
extern void statechart_raise_sensor(Statechart* handle, int32_t value);
/*! Raises the in event 'buttonPressed' that is defined in the default interface scope. */
extern void statechart_raise_buttonPressed(Statechart* handle);
/*! Raises the in event 'buttonReleased' that is defined in the default interface scope. */
extern void statechart_raise_buttonReleased(Statechart* handle);
/*! Raises the in event 'buttonState' that is defined in the default interface scope. */
extern void statechart_raise_buttonState(Statechart* handle, sc_boolean value);
/*! Returns the observable for the out event 'setMotorR' that is defined in the default interface scope. */
extern sc_observable_int32_t* statechart_get_setMotorR(Statechart* handle);