cueOS  2.4
cueOS - Universal Show Control OS for ARM
DMX512_chaser.c
1/***============================================================================================================================
2 * Dependencies inclusion
3 * Necessary dependencies should be declared here. Header file should contain as little dependecies declarations as possible
4 *=============================================================================================================================*/
5
6#include "cueos_config.h"
7#if cueOS_CONFIG_NODETYPE == cueOS_NODETYPE_SLAVE_DMX
8#include <math.h>
9#include "cmsis_os.h"
10#include "DMX512_driver.h"
11#include "DMX512_chaser.h"
12
13
14/***============================================================================================================================
15 * Private functions definitions
16 * These functions are only accessible from within the file's scope
17 *=============================================================================================================================*/
18
26static int16_t _DMX512_chaser_search(DMX512_chaser_s *chaser, uint16_t fixture_id){
27 for(uint16_t i=0; i<chaser->step_count; i++){
28 if(fixture_id == chaser->steps[i].scene->id){
29 return i;
30 }
31 }
32 return -1;
33}
34
40static void _DMX512_chaser_iterate_steps_forward(DMX512_chaser_s *chaser){
41 chaser->current_step = (chaser->current_step + 1) % chaser->step_count;
44}
45
51static void _DMX512_chaser_iterate_steps_backward(DMX512_chaser_s *chaser){
52 chaser->current_step = chaser->current_step > 0 ? chaser->current_step - 1 : chaser->step_count - 1;
55}
56
62static void _DMX512_chaser_iterate_steps_pingpong(DMX512_chaser_s *chaser){
64 chaser->current_step = (chaser->current_step + 1);
67 }else{
68 chaser->current_step = chaser->current_step > 0 ? chaser->current_step - 1 : chaser->step_count - 1;
72 }
73}
74
75
76/***============================================================================================================================
77 * Public functions definitions
78 * These functions can be accessed outside of the file's scope
79 * @see DMX512_chaser.h for declarations
80 *=============================================================================================================================*/
81
82//TODO: Implement chaser fade-in fade-out
83
93
95
96 chaser.id = id;
97 chaser.mode = mode;
98 chaser.direction = direction;
100
101 return chaser;
102
103}
104
113
115
118 }else if(_DMX512_chaser_search(chaser, step.scene->id) >= 0){
120 }else{
121 chaser->steps = (DMX512_chaser_step_s*) pvPortRealloc(chaser->steps, sizeof(DMX512_chaser_step_s) * (chaser->step_count + 1));
122 chaser->steps[chaser->step_count] = step;
123 chaser->step_count++;
124 }
125
126 return err;
127
128}
129
138
140 int16_t index = _DMX512_chaser_search(chaser, id);
141
142 if(index >= 0){
143 for(uint16_t i=index+1; i< chaser->step_count; i++){
144 chaser->steps[i-1] = chaser->steps[i];
145 }
146 chaser->step_count--;
147 chaser->steps = pvPortRealloc(chaser->steps, sizeof(DMX512_chaser_step_s) * (chaser->step_count));
148 err = DMX512_ENGINE_OK;
149 }
150
151 return err;
152
153}
154
163 int16_t index = _DMX512_chaser_search(chaser, id);
164 if(index >= 0){
165 return &chaser->steps[index];
166 }else{
167 return NULL;
168 }
169}
170
177 if(chaser->state == DMX512_CHASER_PLAYING){
179 if(chaser->steps[chaser->current_step].state == DMX512_CHASER_STEP_IDLE){
180 switch(chaser->direction){
181 case DMX512_CHASER_DIRECTION_FORWARD: _DMX512_chaser_iterate_steps_forward(chaser); break;
182 case DMX512_CHASER_DIRECTION_BACKWARD: _DMX512_chaser_iterate_steps_backward(chaser); break;
183 case DMX512_CHASER_DIRECTION_PINGPONG: _DMX512_chaser_iterate_steps_pingpong(chaser); break;
184 case DMX512_CHASER_DIRECTION_RANDOM: /*TODO: handle RNG for random step iteration*/ break;
185 }
186 }
187 }
188}
189
196 //TODO: see if current step preselection could be handled better
197 chaser->current_step = chaser->direction == DMX512_CHASER_DIRECTION_BACKWARD ? chaser->step_count - 1 : 0;
200}
201
207void DMX512_chaser_free(DMX512_chaser_s *chaser){
208 vPortFree(chaser->steps);
209 chaser->step_count = 0;
210}
211
212#endif
void DMX512_chaser_step_manage(DMX512_chaser_step_s *this)
Chaser step state machine. Manage a chaser step's state over time.
void DMX512_chaser_step_start(DMX512_chaser_step_s *this)
Starts a chaser step by assigning it to its fade_in state.
@ DMX512_CHASER_STEP_INITIALISED
@ DMX512_CHASER_STEP_IDLE
DMX512_engine_err_e DMX512_chaser_del_step(DMX512_chaser_s *chaser, uint16_t id)
Deletes a fixture preset instance from the chaser.
void DMX512_chaser_start(DMX512_chaser_s *chaser)
Starts a scene fade-in process.
#define DMX512_CHASER_DEFAULT
chaser instance default values
Definition: DMX512_chaser.h:27
DMX512_engine_err_e DMX512_chaser_add_step(DMX512_chaser_s *chaser, DMX512_chaser_step_s step)
Adds a scene preset instance into the chaser.
DMX512_chaser_s DMX512_chaser_new(uint16_t id, DMX512_chaser_mode_e mode, DMX512_chaser_direction_e direction)
Creates and initialises a new chaser instance.
Definition: DMX512_chaser.c:92
void DMX512_chaser_manage(DMX512_chaser_s *chaser)
Handles step selection and trigger over time.
DMX512_chaser_step_s * DMX512_chaser_get_step(DMX512_chaser_s *chaser, uint16_t id)
Gets a fixture instance from the pool.
DMX512_chaser_mode_e
Playing mode of a chsaer.
Definition: DMX512_chaser.h:45
DMX512_chaser_direction_e
Playing direction of a chaser.
Definition: DMX512_chaser.h:55
@ DMX512_CHASER_IDLE
Definition: DMX512_chaser.h:81
@ DMX512_CHASER_PLAYING
Definition: DMX512_chaser.h:80
@ DMX512_CHASER_PINGPONG_PING
Definition: DMX512_chaser.h:69
@ DMX512_CHASER_PINGPONG_PONG
Definition: DMX512_chaser.h:70
@ DMX512_CHASER_INITIALISED
Definition: DMX512_chaser.h:37
@ DMX512_CHASER_MODE_SINGLE_SHOT
Definition: DMX512_chaser.h:47
@ DMX512_CHASER_DIRECTION_BACKWARD
Definition: DMX512_chaser.h:57
@ DMX512_CHASER_DIRECTION_PINGPONG
Definition: DMX512_chaser.h:58
@ DMX512_CHASER_DIRECTION_FORWARD
Definition: DMX512_chaser.h:56
@ DMX512_CHASER_DIRECTION_RANDOM
Definition: DMX512_chaser.h:59
DMX512_engine_err_e
DMX512 engine error index constants.
Definition: DMX512_defs.h:24
@ DMX512_ENGINE_INSTANCE_UNDEFINED
Definition: DMX512_defs.h:28
@ DMX512_ENGINE_INSTANCE_DUPLICATE
Definition: DMX512_defs.h:26
@ DMX512_ENGINE_OK
Definition: DMX512_defs.h:25
@ DMX512_ENGINE_INSTANCE_INVALID
Definition: DMX512_defs.h:27
DMX512 chaser structure object.
Definition: DMX512_chaser.h:88
DMX512_chaser_pingpong_state_e pingpong
Definition: DMX512_chaser.h:97
uint16_t step_count
Definition: DMX512_chaser.h:93
DMX512_chaser_status_e status
Definition: DMX512_chaser.h:96
DMX512_chaser_mode_e mode
Definition: DMX512_chaser.h:91
uint16_t current_step
Definition: DMX512_chaser.h:94
DMX512_chaser_direction_e direction
Definition: DMX512_chaser.h:92
DMX512_chaser_step_s * steps
Definition: DMX512_chaser.h:90
DMX512_chaser_state_e state
Definition: DMX512_chaser.h:95
DMX512 chaser step structure object.
DMX512_scene_s * scene
DMX512_fixture_chaser_step_state_e state
DMX512_fixture_chaser_step_status_e status