Library for DMX and MIDI protocol

Dependents:   Arts_DMX512_carteV3_MIDI Arts_DMX512_carteV3_MIDI_nRF

Committer:
villemejane
Date:
Sun Dec 12 12:41:49 2021 +0000
Revision:
0:9cf6898e6b66
Library for DMX and MIDI protocol

Who changed what in which revision?

UserRevisionLine numberNew contents of line
villemejane 0:9cf6898e6b66 1 /****************************************************************************/
villemejane 0:9cf6898e6b66 2 /* DMX_MIDI module library */
villemejane 0:9cf6898e6b66 3 /****************************************************************************/
villemejane 0:9cf6898e6b66 4 /* LEnsE / Julien VILLEMEJANE / Institut d'Optique Graduate School */
villemejane 0:9cf6898e6b66 5 /****************************************************************************/
villemejane 0:9cf6898e6b66 6 /* Library - projecteurs.cpp file */
villemejane 0:9cf6898e6b66 7 /* Spots are defined as follow : */
villemejane 0:9cf6898e6b66 8 /* * ADR (uint_16) : DMX first address */
villemejane 0:9cf6898e6b66 9 /* * TYPE (char) : (L)yre, (S)canner, (P)ar, (R)gbawu, Stro(B)e */
villemejane 0:9cf6898e6b66 10 /* * ID (char) : unique identifier of the spot */
villemejane 0:9cf6898e6b66 11 /* * GROUP(char) : group of the spots */
villemejane 0:9cf6898e6b66 12 /* */
villemejane 0:9cf6898e6b66 13 /* * DIM (char) : channel used for DIMMER - 0 if not used */
villemejane 0:9cf6898e6b66 14 /* */
villemejane 0:9cf6898e6b66 15 /* * RED (char) : channel used for RED color - 0 if not used */
villemejane 0:9cf6898e6b66 16 /* * GRN (char) : channel used for GREEN color - 0 if not used */
villemejane 0:9cf6898e6b66 17 /* * BLU (char) : channel used for BLUE color - 0 if not used */
villemejane 0:9cf6898e6b66 18 /* * WHT (char) : channel used for WHITE color - 0 if not used */
villemejane 0:9cf6898e6b66 19 /* * AMB (char) : channel used for AMBER color - 0 if not used */
villemejane 0:9cf6898e6b66 20 /* * UV (char) : channel used for UV color - 0 if not used */
villemejane 0:9cf6898e6b66 21 /* */
villemejane 0:9cf6898e6b66 22 /* * PAN (char) : channel used for PAN moves - 0 if not used */
villemejane 0:9cf6898e6b66 23 /* * TIL (char) : channel used for TILT moves - 0 if not used */
villemejane 0:9cf6898e6b66 24 /* * SPD (char) : channel used for SPEED setup - 0 if not used */
villemejane 0:9cf6898e6b66 25 /* * STB (char) : channel used for STROBE function- 0 if not used */
villemejane 0:9cf6898e6b66 26 /* */
villemejane 0:9cf6898e6b66 27 /****************************************************************************/
villemejane 0:9cf6898e6b66 28 /* Tested on Nucleo-L476RG / 16th nov 2021 */
villemejane 0:9cf6898e6b66 29 /****************************************************************************/
villemejane 0:9cf6898e6b66 30
villemejane 0:9cf6898e6b66 31 #include "projecteurs.h"
villemejane 0:9cf6898e6b66 32 #include "controleurs.h"
villemejane 0:9cf6898e6b66 33
villemejane 0:9cf6898e6b66 34 /* Global Variables */
villemejane 0:9cf6898e6b66 35 char projecteurs[PROJ_NB_TOTAL][DMX_PROJ_NB_DATA];
villemejane 0:9cf6898e6b66 36 int groups[MIDI_NOTES_GROUPS];
villemejane 0:9cf6898e6b66 37
villemejane 0:9cf6898e6b66 38
villemejane 0:9cf6898e6b66 39 /* Functions */
villemejane 0:9cf6898e6b66 40 /* initialisation of spots */
villemejane 0:9cf6898e6b66 41 void initProjectors(void){
villemejane 0:9cf6898e6b66 42 for(int k = 0; k < MIDI_NOTES_GROUPS; k++){
villemejane 0:9cf6898e6b66 43 groups[k] = 0;
villemejane 0:9cf6898e6b66 44 }
villemejane 0:9cf6898e6b66 45 for(int j = 0; j < PROJ_NB_TOTAL; j++){
villemejane 0:9cf6898e6b66 46 for(int i = 0; i < DMX_PROJ_NB_DATA; i++){
villemejane 0:9cf6898e6b66 47 projecteurs[j][i] = 0;
villemejane 0:9cf6898e6b66 48 }
villemejane 0:9cf6898e6b66 49 }
villemejane 0:9cf6898e6b66 50
villemejane 0:9cf6898e6b66 51 /* LED PARTY Eurolite */
villemejane 0:9cf6898e6b66 52 projecteurs[0][DMX_PROJ_ADR] = 0;
villemejane 0:9cf6898e6b66 53 projecteurs[0][DMX_PROJ_ADR + 1] = 1;
villemejane 0:9cf6898e6b66 54 projecteurs[0][DMX_PROJ_TYPE] = 'R';
villemejane 0:9cf6898e6b66 55 projecteurs[0][DMX_PROJ_ID] = 1;
villemejane 0:9cf6898e6b66 56 projecteurs[0][DMX_PROJ_GROUP] = 1;
villemejane 0:9cf6898e6b66 57 projecteurs[0][DMX_PROJ_DIM] = 5;
villemejane 0:9cf6898e6b66 58 projecteurs[0][DMX_PROJ_RED] = 1;
villemejane 0:9cf6898e6b66 59 projecteurs[0][DMX_PROJ_GRN] = 2;
villemejane 0:9cf6898e6b66 60 projecteurs[0][DMX_PROJ_BLU] = 3;
villemejane 0:9cf6898e6b66 61 projecteurs[0][DMX_PROJ_WHT] = 4;
villemejane 0:9cf6898e6b66 62 projecteurs[0][DMX_PROJ_STB] = 6;
villemejane 0:9cf6898e6b66 63 groups[1] = 0b1;
villemejane 0:9cf6898e6b66 64 /* LED PARTY Eurolite */
villemejane 0:9cf6898e6b66 65 projecteurs[1][DMX_PROJ_ADR] = 0;
villemejane 0:9cf6898e6b66 66 projecteurs[1][DMX_PROJ_ADR + 1] = 9;
villemejane 0:9cf6898e6b66 67 projecteurs[1][DMX_PROJ_TYPE] = 'R';
villemejane 0:9cf6898e6b66 68 projecteurs[1][DMX_PROJ_ID] = 2;
villemejane 0:9cf6898e6b66 69 projecteurs[1][DMX_PROJ_GROUP] = 2;
villemejane 0:9cf6898e6b66 70 projecteurs[1][DMX_PROJ_DIM] = 5;
villemejane 0:9cf6898e6b66 71 projecteurs[1][DMX_PROJ_RED] = 1;
villemejane 0:9cf6898e6b66 72 projecteurs[1][DMX_PROJ_GRN] = 2;
villemejane 0:9cf6898e6b66 73 projecteurs[1][DMX_PROJ_BLU] = 3;
villemejane 0:9cf6898e6b66 74 projecteurs[1][DMX_PROJ_WHT] = 4;
villemejane 0:9cf6898e6b66 75 projecteurs[1][DMX_PROJ_STB] = 6;
villemejane 0:9cf6898e6b66 76 groups[2] = 0b10;
villemejane 0:9cf6898e6b66 77 }
villemejane 0:9cf6898e6b66 78
villemejane 0:9cf6898e6b66 79 /* get adress of a spot with number */
villemejane 0:9cf6898e6b66 80 uint16_t getProjAddress(char num){ return ((projecteurs[num][DMX_PROJ_ADR] << 8) + projecteurs[num][DMX_PROJ_ADR + 1]); }
villemejane 0:9cf6898e6b66 81 /* get channel of green of a spot with number */
villemejane 0:9cf6898e6b66 82 char getProjGroup(char num){ return projecteurs[num][DMX_PROJ_GROUP]; }
villemejane 0:9cf6898e6b66 83 /* get channel of dimmer of a spot with number */
villemejane 0:9cf6898e6b66 84 char getProjDimmer(char num){ return projecteurs[num][DMX_PROJ_DIM]; }
villemejane 0:9cf6898e6b66 85 /* get channel of red of a spot with number */
villemejane 0:9cf6898e6b66 86 char getProjRed(char num){ return projecteurs[num][DMX_PROJ_RED]; }
villemejane 0:9cf6898e6b66 87 /* get channel of blue of a spot with number */
villemejane 0:9cf6898e6b66 88 char getProjBlue(char num){ return projecteurs[num][DMX_PROJ_BLU]; }
villemejane 0:9cf6898e6b66 89 /* get channel of green of a spot with number */
villemejane 0:9cf6898e6b66 90 char getProjGreen(char num){ return projecteurs[num][DMX_PROJ_GRN]; }
villemejane 0:9cf6898e6b66 91
villemejane 0:9cf6898e6b66 92 /* update spots with MIDI notes */ // TO TEST AND FINISH + TEST TIMING
villemejane 0:9cf6898e6b66 93 void updateProjFromMidi(char note){
villemejane 0:9cf6898e6b66 94 // Finding Note and Light to update
villemejane 0:9cf6898e6b66 95 for(int grp = 0; grp < MIDI_NOTES_GROUPS; grp++){
villemejane 0:9cf6898e6b66 96 char ctl_M = notes[note][grp][MIDI_CTL_CTL_M];
villemejane 0:9cf6898e6b66 97 char ctl_L = notes[note][grp][MIDI_CTL_CTL_L];
villemejane 0:9cf6898e6b66 98
villemejane 0:9cf6898e6b66 99 if((ctl_M != 0) || (ctl_L != 0)){
villemejane 0:9cf6898e6b66 100 int spots = groups[grp];
villemejane 0:9cf6898e6b66 101 if(spots != 0){
villemejane 0:9cf6898e6b66 102 // get lights to update
villemejane 0:9cf6898e6b66 103 for(int spot = 0; spot < PROJ_NB_TOTAL; spot++){
villemejane 0:9cf6898e6b66 104 if((spots & 1) == 1){
villemejane 0:9cf6898e6b66 105 updateProj(spot, note, grp, ctl_M, ctl_L);
villemejane 0:9cf6898e6b66 106 }
villemejane 0:9cf6898e6b66 107 spots = spots >> 1;
villemejane 0:9cf6898e6b66 108 }
villemejane 0:9cf6898e6b66 109 }
villemejane 0:9cf6898e6b66 110 }
villemejane 0:9cf6898e6b66 111 }
villemejane 0:9cf6898e6b66 112 }
villemejane 0:9cf6898e6b66 113
villemejane 0:9cf6898e6b66 114 /* update a spot */ // TO TEST AND FINISH + TEST TIMING
villemejane 0:9cf6898e6b66 115 void updateProj(char num, char note, char grp, char ctl_M, char ctl_L){
villemejane 0:9cf6898e6b66 116 char add = getProjAddress(num);
villemejane 0:9cf6898e6b66 117
villemejane 0:9cf6898e6b66 118 // Dimmer
villemejane 0:9cf6898e6b66 119 if((ctl_M & MIDI_CTL_DIM_MASK) == MIDI_CTL_DIM_MASK )
villemejane 0:9cf6898e6b66 120 dmx_data[getProjDimmer(num)+add-2] = notes[note][grp][MIDI_CTL_DIM];
villemejane 0:9cf6898e6b66 121 else
villemejane 0:9cf6898e6b66 122 dmx_data[getProjDimmer(num)+add-2] = 0;
villemejane 0:9cf6898e6b66 123 // Red
villemejane 0:9cf6898e6b66 124 if((ctl_M & MIDI_CTL_RED_MASK) == MIDI_CTL_RED_MASK )
villemejane 0:9cf6898e6b66 125 dmx_data[getProjRed(num)+add-2] = notes[note][grp][MIDI_CTL_RED];
villemejane 0:9cf6898e6b66 126 else
villemejane 0:9cf6898e6b66 127 dmx_data[getProjRed(num)+add-2] = 0;
villemejane 0:9cf6898e6b66 128 // Blue
villemejane 0:9cf6898e6b66 129 if((ctl_M & MIDI_CTL_BLUE_MASK) == MIDI_CTL_BLUE_MASK )
villemejane 0:9cf6898e6b66 130 dmx_data[getProjBlue(num)+add-2] = notes[note][grp][MIDI_CTL_BLUE];
villemejane 0:9cf6898e6b66 131 else
villemejane 0:9cf6898e6b66 132 dmx_data[getProjBlue(num)+add-2] = 0;
villemejane 0:9cf6898e6b66 133 // Green
villemejane 0:9cf6898e6b66 134 if((ctl_M & MIDI_CTL_GREEN_MASK) == MIDI_CTL_GREEN_MASK )
villemejane 0:9cf6898e6b66 135 dmx_data[getProjGreen(num)+add-2] = notes[note][grp][MIDI_CTL_GREEN];
villemejane 0:9cf6898e6b66 136 else
villemejane 0:9cf6898e6b66 137 dmx_data[getProjGreen(num)+add-2] = 0;
villemejane 0:9cf6898e6b66 138 }