cueOS  2.4
cueOS - Universal Show Control OS for ARM
DMX512_chaser_step.c
1/***============================================================================================================================
2 * Dependencies inclusion
3 * Necessary dependencies should be declared here. Header file should contain as little dependencies 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_step.h"
12
13
14/***============================================================================================================================
15 * Private functions definitions
16 * These functions are only accessible from within the file's scope
17 *=============================================================================================================================*/
18
24static void _DMX512_step_fadein(DMX512_chaser_step_s *chaser_step){
25 for(uint16_t i=0; i<chaser_step->scene->fixture_preset_count; i++){
26 for(uint16_t j=0; j<chaser_step->scene->fixture_presets[i].ch_count; j++){
27 uint16_t addr = chaser_step->scene->fixture_presets[i].fixture->addr + chaser_step->scene->fixture_presets[i].channels[j];
28 uint16_t value = chaser_step->scene->fixture_presets[i].values[j];
29 uint32_t time = ms_chronometer_get_elapsed_ms(&chaser_step->ms_chronometer);
30 if(time < chaser_step->fadein_time){
31 value = floor(((float)value/(float)chaser_step->fadein_time)*((float)(time)));
32 }else{
33 chaser_step->state = DMX512_CHASER_STEP_HOLD;
34 }
35
36 DMX512_driver_set_single(addr, value);
37 }
38 }
39}
40
46static void _DMX512_step_hold(DMX512_chaser_step_s *chaser_step){
47 if(ms_chronometer_get_elapsed_ms(&chaser_step->ms_chronometer) > chaser_step->hold_time){
49 }
50}
51
57static void _DMX512_step_fadeout(DMX512_chaser_step_s *chaser_step){
58 for(uint16_t i=0; i<chaser_step->scene->fixture_preset_count; i++){
59 for(uint16_t j=0; j<chaser_step->scene->fixture_presets[i].ch_count; j++){
60 uint16_t addr = chaser_step->scene->fixture_presets[i].fixture->addr + chaser_step->scene->fixture_presets[i].channels[j];
61 uint16_t value = chaser_step->scene->fixture_presets[i].values[j];
62 uint32_t time = ms_chronometer_get_elapsed_ms(&chaser_step->ms_chronometer);
63 if(time < chaser_step->fadeout_time){
64 value = floor(((float)value/(float)chaser_step->fadeout_time)*((float)(time + value)));
65 }else{
66 chaser_step->state = DMX512_CHASER_STEP_IDLE;
67 }
68
69 DMX512_driver_set_single(addr, value);
70 }
71 }
72}
73
74
75/***============================================================================================================================
76 * Public functions definitions
77 * These functions can be accessed outside of the file's scope
78 *=============================================================================================================================*/
79
89DMX512_chaser_step_s DMX512_chaser_step_new(DMX512_scene_s *scene, uint16_t fadein_time, uint16_t fadeout_time, uint16_t hold_time){
90
92
93 if(scene != NULL){
94 chaser_step.scene = scene;
95 chaser_step.fadein_time = fadein_time;
96 chaser_step.fadeout_time = fadeout_time;
97 chaser_step.hold_time = hold_time;
99 }
100
101 return chaser_step;
102
103}
104
111 switch(chaser_step->state){
112 case DMX512_CHASER_STEP_FADE_IN: _DMX512_step_fadein(chaser_step); break;
113 case DMX512_CHASER_STEP_HOLD: _DMX512_step_hold(chaser_step); break;
114 case DMX512_CHASER_STEP_FADE_OUT: _DMX512_step_fadeout(chaser_step); break;
115 case DMX512_CHASER_STEP_IDLE: /*TODO: handle IDLE case ?*/ break;
116 }
117}
118
126 chaser_step->state = DMX512_CHASER_STEP_FADE_IN;
127}
128
136 chaser_step->state = DMX512_CHASER_STEP_IDLE;
137}
138
139#endif
#define DMX512_CHASER_STEP_DEFAULT
chaser step instance default values
void DMX512_chaser_step_stop(DMX512_chaser_step_s *chaser_step)
Stops a chaser step by assigning it to its idle state.
void DMX512_chaser_step_manage(DMX512_chaser_step_s *chaser_step)
Chaser step state machine. Manage a chaser step's state over time.
void DMX512_chaser_step_start(DMX512_chaser_step_s *chaser_step)
Starts a chaser step by assigning it to its fade_in state.
@ DMX512_CHASER_STEP_INITIALISED
@ DMX512_CHASER_STEP_HOLD
@ DMX512_CHASER_STEP_IDLE
@ DMX512_CHASER_STEP_FADE_OUT
@ DMX512_CHASER_STEP_FADE_IN
DMX512_driver_err_e DMX512_driver_set_single(uint16_t address, uint8_t value)
Sets a buffer's address to a given value.
void ms_chronometer_reset(ms_chronometer_s *ms_chronometer)
Resets an mschronometer instance time delta to zero.
uint32_t ms_chronometer_get_elapsed_ms(ms_chronometer_s *ms_chronometer)
Returns elapsed time in milliseconds since last reset.
DMX512 chaser step structure object.
DMX512_scene_s * scene
ms_chronometer_s ms_chronometer
DMX512_fixture_chaser_step_state_e state
DMX512_fixture_chaser_step_status_e status
DMX512 scene structure object.
Definition: DMX512_scene.h:54
DMX512_fixture_preset_s * fixture_presets
Definition: DMX512_scene.h:59
uint16_t fixture_preset_count
Definition: DMX512_scene.h:58