cueOS  2.4
cueOS - Universal Show Control OS for ARM
DMX512_scene_pool.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 "cmsis_os.h"
9#include "DMX512_scene_pool.h"
10
11
12/***============================================================================================================================
13 * Private functions definitions
14 * These functions are only accessible from within the file's scope
15 *=============================================================================================================================*/
16
25static int16_t _DMX512_scene_pool_search(DMX512_scene_pool_s *scene_pool, uint16_t id){
26 for(uint16_t i=0; i<scene_pool->scene_count; i++){
27 if(id == scene_pool->scenes[i].id){
28 return i;
29 }
30 }
31 return -1;
32}
33
34
35/***============================================================================================================================
36 * Public functions definitions
37 * These functions can be accessed outside of the file's scope
38 * @see DMX512_fixture_pool.h for declarations
39 *=============================================================================================================================*/
40
47 DMX512_scene_pool_s *scene_pool = pvPortMalloc(sizeof(DMX512_scene_pool_s));
48 scene_pool->scenes = NULL;
49 scene_pool->scene_count = 0;
50 return scene_pool;
51}
52
61
63
66 }else if(_DMX512_scene_pool_search(scene_pool, scene.id) >= 0){
68 }else if(err == DMX512_ENGINE_OK){
69 scene_pool->scenes = (DMX512_scene_s*) pvPortRealloc(scene_pool->scenes, sizeof(DMX512_scene_s) * (scene_pool->scene_count + 1));
70 scene_pool->scenes[scene_pool->scene_count] = scene;
71 scene_pool->scene_count++;
72 }
73
74 return err;
75
76}
77
86
88 int16_t index = _DMX512_scene_pool_search(scene_pool, id);
89
90 if(index >= 0){
91 for(uint16_t i=index+1; i<scene_pool->scene_count; i++){
92 scene_pool->scenes[i-1] = scene_pool->scenes[i];
93 }
94 scene_pool->scene_count--;
95 DMX512_scene_free(&scene_pool->scenes[index]);
96 scene_pool->scenes = pvPortRealloc(scene_pool->scenes, sizeof(DMX512_scene_s) * (scene_pool->scene_count));
97 }else{
99 }
100
101 return err;
102
103}
104
113
115
116 int16_t index = _DMX512_scene_pool_search(scene_pool, id);
117 if(index >= 0){
118 *scene = &scene_pool->scenes[index];
119 err = DMX512_ENGINE_OK;
120 }
121
122 return err;
123
124}
125
132 for(uint16_t i = 0; i<scene_pool->scene_count;i++){
133 DMX512_scene_manage(&scene_pool->scenes[i]);
134 }
135}
136
143 if(scene_pool != NULL){
144 for(uint16_t i = 0; i<scene_pool->scene_count; i++){
145 DMX512_scene_free(&scene_pool->scenes[i]);
146 }
147 vPortFree(scene_pool);
148 }
149}
150
151#endif
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
void DMX512_scene_pool_manage(DMX512_scene_pool_s *scene_pool)
Manages all scenes contained within the pool.
DMX512_engine_err_e DMX512_scene_pool_del(DMX512_scene_pool_s *scene_pool, uint16_t id)
Deletes a scene instance from the pool.
void DMX512_scene_pool_free(DMX512_scene_pool_s *scene_pool)
Safely Frees instance pool.
DMX512_engine_err_e DMX512_scene_pool_get(DMX512_scene_pool_s *scene_pool, uint16_t id, DMX512_scene_s **scene)
Gets a scene instance from the pool.
DMX512_engine_err_e DMX512_scene_pool_add(DMX512_scene_pool_s *scene_pool, DMX512_scene_s scene)
Adds a scene instance into the pool.
DMX512_scene_pool_s * DMX512_scene_pool_new(void)
Creates a new scene pool instance.
void DMX512_scene_manage(DMX512_scene_s *scene)
State machine to manage scene at a given state.
Definition: DMX512_scene.c:198
void DMX512_scene_free(DMX512_scene_s *scene)
Resets a scene to its uninitialised state. frees dynamically allocated scene Data.
Definition: DMX512_scene.c:212
@ DMX512_SCENE_INITIALISED
Definition: DMX512_scene.h:35
DMX512 scene pool structure object.
DMX512_scene_s * scenes
DMX512 scene structure object.
Definition: DMX512_scene.h:54
DMX512_scene_status_e status
Definition: DMX512_scene.h:62