Library for DMX and MIDI protocol

Dependents:   Arts_DMX512_carteV3_MIDI Arts_DMX512_carteV3_MIDI_nRF

Files at this revision

API Documentation at this revision

Comitter:
villemejane
Date:
Sun Dec 12 12:41:49 2021 +0000
Commit message:
Library for DMX and MIDI protocol

Changed in this revision

DMX_MIDI.cpp Show annotated file Show diff for this revision Revisions of this file
DMX_MIDI.h Show annotated file Show diff for this revision Revisions of this file
controleurs.cpp Show annotated file Show diff for this revision Revisions of this file
controleurs.h Show annotated file Show diff for this revision Revisions of this file
preset.h Show annotated file Show diff for this revision Revisions of this file
projecteurs.cpp Show annotated file Show diff for this revision Revisions of this file
projecteurs.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9cf6898e6b66 DMX_MIDI.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DMX_MIDI.cpp	Sun Dec 12 12:41:49 2021 +0000
@@ -0,0 +1,218 @@
+/****************************************************************************/
+/*  DMX_MIDI module library                                                 */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - DMX_MIDI.cpp file                                             */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 11th nov 2021                                 */
+/****************************************************************************/
+
+#include "DMX_MIDI.h"
+
+/* Entrées - Sorties */
+// DMX
+Serial      dmx(PA_0, PA_1);
+DigitalOut  out_tx(D5);
+DigitalOut  start(D4);     //envoie des données
+DigitalOut  enableDMX(D6);
+// MIDI
+Serial      midi(D8, D2);
+// Analogiques
+AnalogIn    CV_volume(PC_1);
+AnalogIn    CV_pitch(PB_0);
+AnalogIn    variationR(PC_0);
+AnalogIn    variationG(PC_2);
+AnalogIn    variationB(PC_3);
+
+/* Variables globales */
+char        dmx_data[SAMPLES] = {0};
+int         rgb;
+// Midi
+char        cpt_midi;
+char        new_data_midi, new_note_midi;
+char        midi_data[3], note_data, velocity_data;
+char        control_ch, control_value;
+
+
+/* Variation de lumière douce - Projet Arts et Sciences */
+const uint8_t vague[360]={
+  0,   0,   0,   0,   0,   1,   1,   2,   2,   3,   4,   5,   6,   7,   8,   9, 
+ 11,  12,  13,  15,  17,  18,  20,  22,  24,  26,  28,  30,  32,  35,  37,  39, 
+ 42,  44,  47,  49,  52,  55,  58,  60,  63,  66,  69,  72,  75,  78,  81,  85, 
+ 88,  91,  94,  97, 101, 104, 107, 111, 114, 117, 121, 124, 127, 131, 134, 137, 
+141, 144, 147, 150, 154, 157, 160, 163, 167, 170, 173, 176, 179, 182, 185, 188, 
+191, 194, 197, 200, 202, 205, 208, 210, 213, 215, 217, 220, 222, 224, 226, 229, 
+231, 232, 234, 236, 238, 239, 241, 242, 244, 245, 246, 248, 249, 250, 251, 251, 
+252, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 253, 253, 
+252, 251, 251, 250, 249, 248, 246, 245, 244, 242, 241, 239, 238, 236, 234, 232, 
+231, 229, 226, 224, 222, 220, 217, 215, 213, 210, 208, 205, 202, 200, 197, 194, 
+191, 188, 185, 182, 179, 176, 173, 170, 167, 163, 160, 157, 154, 150, 147, 144, 
+141, 137, 134, 131, 127, 124, 121, 117, 114, 111, 107, 104, 101,  97,  94,  91, 
+ 88,  85,  81,  78,  75,  72,  69,  66,  63,  60,  58,  55,  52,  49,  47,  44, 
+ 42,  39,  37,  35,  32,  30,  28,  26,  24,  22,  20,  18,  17,  15,  13,  12, 
+ 11,   9,   8,   7,   6,   5,   4,   3,   2,   2,   1,   1,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
+  0,   0,   0,   0,   0,   0,   0,   0};
+
+/* Fonction d'initialisation de la liaison DMX */
+void initDMX(void){
+    dmx.baud(250000);
+    dmx.format (8, SerialBase::None, 2);
+    enableDMX = 0;
+    // Initialisation canaux DMX
+    for(int k = 0; k < SAMPLES; k++){
+        dmx_data[k] = 0;
+    }    
+    updateDMX();
+} 
+
+/* Fonction de mise à jour de la sortie DMX */
+void updateDMX(){
+        enableDMX = 1;
+        start = 1;      // /start
+        out_tx = 0;     // break
+        wait_us(88);    
+        out_tx = 1;     // mb
+        wait_us(8);     
+        out_tx = 0;     // break
+        start = 0;
+        dmx.putc(0);     // Start
+        for(int i = 0; i < SAMPLES; i++){
+            dmx.putc(dmx_data[i]);     // data
+        }
+        wait_us(23000); // time between frame  
+}
+
+/* Fonction d'initialisation de la liaison MIDI */
+void initMIDI(void){
+    midi.baud(31250);
+    midi.format(8, SerialBase::None, 1);
+    midi.attach(&ISR_midi_in, Serial::RxIrq);
+}
+/* Fonction d'initialisation de la liaison MIDI - version beta */
+void initMIDI2(void){
+    debug_pc.baud(115200);
+    debug_pc.format(8, SerialBase::None, 1);
+    debug_pc.attach(&ISR_midi_in2, Serial::RxIrq);
+}
+/* Detection d'une note reçue en MIDI */
+bool isNoteMIDIdetected(void){
+    if(new_note_midi == 1)
+        return true;
+    else
+        return false;
+}
+/* Note reçue en MIDI traitée */
+void resetNoteMIDI(void){
+    new_note_midi = 0;
+}
+
+/* Detection d'un controle reçu en MIDI */
+bool isCCMIDIdetected(void){
+    if(new_data_midi == 1)
+        return true;
+    else
+        return false;
+}
+/* Controle reçu en MIDI traité */
+void resetCCMIDI(void){
+    new_data_midi = 0;
+}
+
+/* Renvoie la note reçue sur la liaison MIDI */
+void resendNoteMIDI(void){
+    midi.putc(MIDI_NOTE_ON);
+    midi.putc(note_data);
+    midi.putc(127);
+}
+
+/* Renvoie la note reçue sur la liaison MIDI - version beta */
+void resendNoteMIDI2(void){
+    debug_pc.putc(MIDI_NOTE_ON);
+    debug_pc.putc(note_data);
+    debug_pc.putc(127);
+}
+/* Joue une note sur la liaison MIDI */
+void playNoteMIDI(char note, char velocity){
+    midi.putc(MIDI_NOTE_ON);
+    midi.putc(note);
+    midi.putc(velocity);
+}
+/* Joue une note sur la liaison MIDI - version beta */
+void playNoteMIDI2(char note, char velocity){
+    debug_pc.printf("%x %x \r\n", note, velocity);
+}
+
+/* Stoppe une note sur la liaison MIDI */
+void stopNoteMIDI(char note, char velocity){
+    midi.putc(MIDI_NOTE_OFF);
+    midi.putc(note);
+    midi.putc(velocity);
+}
+
+/* Fonction d'appel à une variation de lumière en fonction d'un angle
+    @out : R G B au format 24 bits
+*/
+int sineLED(int angle)
+{
+    return (vague[(angle+120)%360] << 16) + (vague[angle] << 8) + vague[(angle+240)%360];
+}
+
+
+/* Fonction d'interruption sur MIDI */
+void ISR_midi_in(void){
+    debug_out = !debug_out;
+    char data = midi.getc();
+    if(data >= 128)
+        cpt_midi = 0;
+    else
+        cpt_midi++;
+    midi_data[cpt_midi] = data;
+    if(cpt_midi == 2){
+        cpt_midi = 0;
+        if((midi_data[0] == MIDI_NOTE_ON) || (midi_data[0] == MIDI_NOTE_OFF)){
+            new_note_midi = 1;
+            note_data = midi_data[1];
+            velocity_data = midi_data[2];
+        }
+        else{
+            if(midi_data[0] == MIDI_CC){
+                new_data_midi = 1;
+                control_ch = midi_data[1];
+                control_value = midi_data[2];
+            }
+        }
+    }
+}
+/* Fonction d'interruption sur MIDI - version beta */
+void ISR_midi_in2(void){
+    debug_out = !debug_out;
+    char data = debug_pc.getc();
+    if(data >= 128)
+        cpt_midi = 0;
+    else
+        cpt_midi++;
+    midi_data[cpt_midi] = data;
+    if(cpt_midi == 2){
+        cpt_midi = 0;
+        if((midi_data[0] == MIDI_NOTE_ON)){ // || (midi_data[0] == MIDI_NOTE_OFF)){
+            new_note_midi = 1;
+            note_data = midi_data[1];
+            velocity_data = midi_data[2];
+        }
+        else{
+            if(midi_data[0] == MIDI_CC){
+                new_data_midi = 1;
+                control_ch = midi_data[1];
+                control_value = midi_data[2];
+            }
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 9cf6898e6b66 DMX_MIDI.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DMX_MIDI.h	Sun Dec 12 12:41:49 2021 +0000
@@ -0,0 +1,90 @@
+/****************************************************************************/
+/*  DMX_MIDI module library                                                 */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - DMX_MIDI.h file                                               */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 11th nov 2021                                 */
+/****************************************************************************/
+
+#ifndef     DMX_MIDI_H_INCLUDED
+#define     DMX_MIDI_H_INCLUDED
+#include    "projecteurs.h"
+#include    "preset.h"
+#include    "projecteurs.h"
+#include    "controleurs.h"
+
+#define     SAMPLES     512 
+
+#define     MIDI_NOTE_ON        0x90
+#define     MIDI_NOTE_OFF       0x80
+#define     MIDI_CC             0xB0
+
+#include    "mbed.h"
+
+/* Entrées - Sorties */
+extern      Serial      debug_pc;
+extern      DigitalOut  debug_out;
+
+extern      Serial      dmx;
+extern      DigitalOut  out_tx;
+extern      DigitalOut  start;     //envoie des données
+extern      DigitalOut  enableDMX;
+extern      AnalogIn    CV_volume;
+extern      AnalogIn    CV_pitch;
+
+extern      AnalogIn    variationR;
+extern      AnalogIn    variationG;
+extern      AnalogIn    variationB;
+
+/* Variables globales */
+extern      const uint8_t vague[];
+extern      char        dmx_data[];
+extern      int         rgb;
+extern      char        cpt_midi;
+extern      char        new_data_midi, new_note_midi;
+extern      char        midi_data[], note_data, velocity_data;
+extern      char        control_ch, control_value;
+
+/* Fonctions */  
+/* Fonction d'initialisation de la liaison DMX */
+void initDMX(void);
+/* Fonction de mise à jour de la sortie DMX */
+void updateDMX();
+
+/* Fonction d'initialisation de la liaison MIDI */
+void initMIDI(void);
+/* Fonction d'initialisation de la liaison MIDI - version beta */
+void initMIDI2(void);
+/* Detection d'une note reçue en MIDI */
+bool isNoteMIDIdetected(void);
+/* Note reçue en MIDI traitée */
+void resetNoteMIDI(void);
+/* Renvoie la note reçue sur la liaison MIDI */
+void resendNoteMIDI(void);
+/* Renvoie la note reçue sur la liaison MIDI - version beta */
+void resendNoteMIDI2(void);
+/* Joue une note sur la liaison MIDI */
+void playNoteMIDI(char note, char velocity);
+/* Joue une note sur la liaison MIDI - version beta */
+void playNoteMIDI2(char note, char velocity);
+/* Stoppe une note sur la liaison MIDI */
+void stopNoteMIDI(char note, char velocity);
+
+/* Detection d'un controle reçu en MIDI */
+bool isCCMIDIdetected(void);
+/* Controle reçu en MIDI traité */
+void resetCCMIDI(void);
+
+/* Fonction d'appel à une variation de lumière en fonction d'un angle
+    @out : R G B au format 24 bits
+*/
+int sineLED(int angle);
+
+/* Fonction d'interruption sur MIDI */
+void ISR_midi_in(void);
+/* Fonction d'interruption sur MIDI - version beta */
+void ISR_midi_in2(void);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 9cf6898e6b66 controleurs.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controleurs.cpp	Sun Dec 12 12:41:49 2021 +0000
@@ -0,0 +1,104 @@
+/****************************************************************************/
+/*  DMX_MIDI module library                                                 */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - controleurs.cpp file                                          */
+/*      MIDI notes are from 0 to 127                                        */
+/*      MIDI notes are defined as follow :                                  */
+/*          * CTL_M(char) : effect on spot ;                                */
+/*              + bit 7 :   Dimmer                                          */
+/*              + bit 6 :   RED                                             */
+/*              + bit 5 :   GREEN                                           */
+/*              + bit 4 :   BLUE                                            */
+/*              + bit 3 :   WHITE                                           */
+/*              + bit 2 :   AMBER                                           */
+/*              + bit 1 :   UV                                              */
+/*              + bit 0 :   not used yet                                    */
+/*          * CTL_L(char) : effect on spot ;                                */
+/*              + bit 7 :   Pan                                             */
+/*              + bit 6 :   Tilt                                            */
+/*              + bit 5 :   Speed                                           */
+/*              + bit 4 :   Strobe                                          */
+/*              + bit 3 :   not used yet                                    */
+/*              + bit 2 :   not used yet                                    */
+/*              + bit 1 :   not used yet                                    */
+/*              + bit 0 :   not used yet                                    */
+/*          * C1 to C16 (char) : value to affect to each type of CTL_M or L */
+/*                                                                          */
+/*      MIDI control changes CC are from 0 to 127                           */
+/*      MIDI controls are defined as follow :   TO DO                            */
+/*          * CTL_M(char) : effect on spot ;                                */
+/*              + bit 7 :   Dimmer                                          */
+/*              + bit 6 :   RED                                             */
+/*                                                                          */
+/*                                                                          */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 16th nov 2021                                 */
+/****************************************************************************/
+
+#include    "controleurs.h"
+
+char    notes[MIDI_NOTES_NB][MIDI_NOTES_GROUPS][MIDI_NOTES_CHAN] = {0};
+
+/* Functions */
+/* initialisation of notes */
+void initController(void){
+    for(int j = 0; j < MIDI_NOTES_NB; j++){
+        for(int g = 0; g < MIDI_NOTES_GROUPS; g++){
+            for(int i = 0; i < MIDI_NOTES_CHAN; i++){
+                notes[j][g][i] = 0;
+            }
+        }
+    }
+    
+    /* Note 0 */
+    // Groupe 0
+    notes[0][0][MIDI_CTL_CTL_M] = 0b11110000;
+    notes[0][0][MIDI_CTL_CTL_L] = 0b00000000;
+    notes[0][0][MIDI_CTL_DIM] = 255;
+    notes[0][0][MIDI_CTL_GREEN] = 0; 
+    notes[0][0][MIDI_CTL_BLUE] = 0; 
+    notes[0][0][MIDI_CTL_RED] = 255;  
+    // Groupe 1
+    notes[0][1][MIDI_CTL_CTL_M] = 0b11110000;
+    notes[0][1][MIDI_CTL_CTL_L] = 0b00000000;
+    notes[0][1][MIDI_CTL_DIM] = 255;
+    notes[0][1][MIDI_CTL_GREEN] = 120; 
+    notes[0][1][MIDI_CTL_BLUE] = 0; 
+    notes[0][1][MIDI_CTL_RED] = 255;  
+
+    /* Note 1 */
+    // Groupe 0
+    notes[1][0][MIDI_CTL_CTL_M] = 0b11110000;
+    notes[1][0][MIDI_CTL_CTL_L] = 0b00000000;
+    notes[1][0][MIDI_CTL_DIM] = 255;
+    notes[1][0][MIDI_CTL_BLUE] = 255; 
+    notes[1][0][MIDI_CTL_RED] = 255; 
+    notes[1][0][MIDI_CTL_GREEN] = 0;
+    // Groupe 1    
+    notes[1][1][MIDI_CTL_CTL_M] = 0b11110000;
+    notes[1][1][MIDI_CTL_CTL_L] = 0b00000000;
+    notes[1][1][MIDI_CTL_DIM] = 255;
+    notes[1][1][MIDI_CTL_BLUE] = 255; 
+    notes[1][1][MIDI_CTL_RED] = 0; 
+    notes[1][1][MIDI_CTL_GREEN] = 0;   
+    
+    /* Note 2 */
+    // Groupe 0
+    notes[2][0][MIDI_CTL_CTL_M] = 0b11110000;
+    notes[2][0][MIDI_CTL_CTL_L] = 0b00000000;
+    notes[2][0][MIDI_CTL_DIM] = 255;
+    notes[2][0][MIDI_CTL_GREEN] = 255; 
+    notes[2][0][MIDI_CTL_BLUE] = 0; 
+    notes[2][0][MIDI_CTL_RED] = 0;    
+    // Groupe 1    
+    notes[2][1][MIDI_CTL_CTL_M] = 0b11110000;
+    notes[2][1][MIDI_CTL_CTL_L] = 0b00000000;
+    notes[2][1][MIDI_CTL_DIM] = 255;
+    notes[2][1][MIDI_CTL_GREEN] = 0; 
+    notes[2][1][MIDI_CTL_BLUE] = 50; 
+    notes[2][1][MIDI_CTL_RED] = 200;   
+
+}
+    
diff -r 000000000000 -r 9cf6898e6b66 controleurs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controleurs.h	Sun Dec 12 12:41:49 2021 +0000
@@ -0,0 +1,86 @@
+/****************************************************************************/
+/*  DMX_MIDI module library                                                 */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - controleurs.h file                                            */
+/*      MIDI notes are from 0 to 127                                        */
+/*          and MIDI CC controls are from 128 to 512                        */
+/*      MIDI controls are defined as follow :                               */
+/*          * CTL_M(char) : effect on spot ;                                */
+/*              + bit 7 :   Dimmer                                          */
+/*              + bit 6 :   RED                                             */
+/*              + bit 5 :   GREEN                                           */
+/*              + bit 4 :   BLUE                                            */
+/*              + bit 3 :   WHITE                                           */
+/*              + bit 2 :   AMBER                                           */
+/*              + bit 1 :   UV                                              */
+/*              + bit 0 :   not used yet                                    */
+/*          * CTL_L(char) : effect on spot ;                                */
+/*              + bit 7 :   Pan                                             */
+/*              + bit 6 :   Tilt                                            */
+/*              + bit 5 :   Speed                                           */
+/*              + bit 4 :   Strobe                                          */
+/*              + bit 3 :   not used yet                                    */
+/*              + bit 2 :   not used yet                                    */
+/*              + bit 1 :   not used yet                                    */
+/*              + bit 0 :   not used yet                                    */
+/*          * C1 to C16 (char) : value to affect to each type of CTL_M or L */
+/*                                                                          */
+/*                                                                          */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 16th nov 2021                                 */
+/****************************************************************************/
+/* Next upgrade : include CC controls */
+
+#include    "mbed.h"
+#include    "DMX_MIDI.h"
+
+#define     MIDI_CONTROLS_NB        128
+#define     MIDI_NOTES_NB           128
+#define     MIDI_NOTES_GROUPS       16
+#define     MIDI_NOTES_CHAN         18
+
+#define     MIDI_CTL_CTL_M          0
+#define     MIDI_CTL_CTL_L          1
+#define     MIDI_CTL_DIM            2
+#define     MIDI_CTL_RED            3
+#define     MIDI_CTL_GREEN          4
+#define     MIDI_CTL_BLUE           5
+#define     MIDI_CTL_WHITE          6
+#define     MIDI_CTL_AMBER          7
+#define     MIDI_CTL_UV             8
+#define     MIDI_CTL_M0             9
+#define     MIDI_CTL_PAN            10
+#define     MIDI_CTL_TILT           11
+#define     MIDI_CTL_SPEED          12
+#define     MIDI_CTL_STROBE         13
+#define     MIDI_CTL_L3             14
+#define     MIDI_CTL_L2             15
+#define     MIDI_CTL_L1             16
+#define     MIDI_CTL_L0             17
+
+#define     MIDI_CTL_DIM_MASK       0b10000000
+#define     MIDI_CTL_RED_MASK       0b01000000
+#define     MIDI_CTL_GREEN_MASK     0b00100000
+#define     MIDI_CTL_BLUE_MASK      0b00010000
+#define     MIDI_CTL_WHITE_MASK     0b00001000
+#define     MIDI_CTL_AMBER_MASK     0b00000100
+#define     MIDI_CTL_UV_MASK        0b00000010
+#define     MIDI_CTL_M0_MASK        0b00000001
+#define     MIDI_CTL_PAN_MASK       0b10000000
+#define     MIDI_CTL_TILT_MASK      0b01000000
+#define     MIDI_CTL_SPEED_MASK     0b00100000
+#define     MIDI_CTL_STROBE_MASK    0b00010000
+#define     MIDI_CTL_L3_MASK        0b00001000
+#define     MIDI_CTL_L2_MASK        0b00000100
+#define     MIDI_CTL_L1_MASK        0b00000010
+#define     MIDI_CTL_L0_MASK        0b00000001
+
+/* Global variables */
+/* controls : [number of possible notes values in MIDI][number of groups of light][number of commands] */
+extern      char        notes[MIDI_NOTES_NB][MIDI_NOTES_GROUPS][MIDI_NOTES_CHAN];
+
+/* Functions */
+/* initialisation of controls */
+void initController(void);
\ No newline at end of file
diff -r 000000000000 -r 9cf6898e6b66 preset.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/preset.h	Sun Dec 12 12:41:49 2021 +0000
@@ -0,0 +1,14 @@
+#ifndef     PRESET_H_INCLUDED
+#define     PRESET_H_INCLUDED
+
+#define     MIDI_PRESET_AKAI_MPD26          1
+#define     MIDI_PRESET_AKAI_MPD26_PADS     16
+#define     MIDI_PRESET_AKAI_MPD26_PAD_1    0
+#define     MIDI_PRESET_AKAI_MPD26_BANKS    4
+#define     MIDI_PRESET_AKAI_MPD26_FADERS   6
+#define     MIDI_PRESET_AKAI_MPD26_FADER_1  1
+#define     MIDI_PRESET_AKAI_MPD26_POTS     6
+#define     MIDI_PRESET_AKAI_MPD26_POT_1    7
+
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 9cf6898e6b66 projecteurs.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/projecteurs.cpp	Sun Dec 12 12:41:49 2021 +0000
@@ -0,0 +1,138 @@
+/****************************************************************************/
+/*  DMX_MIDI module library                                                 */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - projecteurs.cpp file                                          */
+/*      Spots are defined as follow :                                       */
+/*          * ADR  (uint_16) : DMX first address                            */
+/*          * TYPE (char) : (L)yre, (S)canner, (P)ar, (R)gbawu, Stro(B)e    */
+/*          * ID   (char) : unique identifier of the spot                   */
+/*          * GROUP(char) : group of the spots                              */
+/*                                                                          */
+/*          * DIM  (char) : channel used for DIMMER         - 0 if not used */
+/*                                                                          */
+/*          * RED  (char) : channel used for RED color      - 0 if not used */
+/*          * GRN  (char) : channel used for GREEN color    - 0 if not used */
+/*          * BLU  (char) : channel used for BLUE color     - 0 if not used */
+/*          * WHT  (char) : channel used for WHITE color    - 0 if not used */
+/*          * AMB  (char) : channel used for AMBER color    - 0 if not used */
+/*          * UV   (char) : channel used for UV color       - 0 if not used */
+/*                                                                          */
+/*          * PAN  (char) : channel used for PAN moves      - 0 if not used */
+/*          * TIL  (char) : channel used for TILT moves     - 0 if not used */
+/*          * SPD  (char) : channel used for SPEED setup    - 0 if not used */
+/*          * STB  (char) : channel used for STROBE function- 0 if not used */
+/*                                                                          */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 16th nov 2021                                 */
+/****************************************************************************/
+
+#include    "projecteurs.h"
+#include    "controleurs.h"
+
+/* Global Variables */
+char        projecteurs[PROJ_NB_TOTAL][DMX_PROJ_NB_DATA];
+int         groups[MIDI_NOTES_GROUPS];
+
+
+/* Functions */
+/* initialisation of spots */
+void initProjectors(void){
+    for(int k = 0; k < MIDI_NOTES_GROUPS; k++){
+        groups[k] = 0;
+    }
+    for(int j = 0; j < PROJ_NB_TOTAL; j++){
+        for(int i = 0; i < DMX_PROJ_NB_DATA; i++){
+            projecteurs[j][i] = 0;
+        }
+    }
+    
+    /* LED PARTY Eurolite */
+    projecteurs[0][DMX_PROJ_ADR] = 0;
+    projecteurs[0][DMX_PROJ_ADR + 1] = 1;
+    projecteurs[0][DMX_PROJ_TYPE] = 'R';
+    projecteurs[0][DMX_PROJ_ID] = 1;
+    projecteurs[0][DMX_PROJ_GROUP] = 1;
+    projecteurs[0][DMX_PROJ_DIM] = 5;
+    projecteurs[0][DMX_PROJ_RED] = 1;
+    projecteurs[0][DMX_PROJ_GRN] = 2;
+    projecteurs[0][DMX_PROJ_BLU] = 3;
+    projecteurs[0][DMX_PROJ_WHT] = 4;
+    projecteurs[0][DMX_PROJ_STB] = 6;
+    groups[1] = 0b1;
+    /* LED PARTY Eurolite */
+    projecteurs[1][DMX_PROJ_ADR] = 0;
+    projecteurs[1][DMX_PROJ_ADR + 1] = 9;
+    projecteurs[1][DMX_PROJ_TYPE] = 'R';
+    projecteurs[1][DMX_PROJ_ID] = 2;
+    projecteurs[1][DMX_PROJ_GROUP] = 2;
+    projecteurs[1][DMX_PROJ_DIM] = 5;
+    projecteurs[1][DMX_PROJ_RED] = 1;
+    projecteurs[1][DMX_PROJ_GRN] = 2;
+    projecteurs[1][DMX_PROJ_BLU] = 3;
+    projecteurs[1][DMX_PROJ_WHT] = 4;
+    projecteurs[1][DMX_PROJ_STB] = 6;
+    groups[2] = 0b10;
+}
+
+/* get adress of a spot with number */
+uint16_t getProjAddress(char num){   return ((projecteurs[num][DMX_PROJ_ADR] << 8) + projecteurs[num][DMX_PROJ_ADR + 1]);    }
+/* get channel of green of a spot with number */
+char getProjGroup(char num){   return projecteurs[num][DMX_PROJ_GROUP];    }
+/* get channel of dimmer of a spot with number */
+char getProjDimmer(char num){   return projecteurs[num][DMX_PROJ_DIM];    }
+/* get channel of red of a spot with number */
+char getProjRed(char num){   return projecteurs[num][DMX_PROJ_RED];    }
+/* get channel of blue of a spot with number */
+char getProjBlue(char num){   return projecteurs[num][DMX_PROJ_BLU];    }
+/* get channel of green of a spot with number */
+char getProjGreen(char num){   return projecteurs[num][DMX_PROJ_GRN];    }
+
+/* update spots with MIDI notes */ // TO TEST AND FINISH + TEST TIMING
+void updateProjFromMidi(char note){
+    // Finding Note and Light to update
+    for(int grp = 0; grp < MIDI_NOTES_GROUPS; grp++){
+        char ctl_M = notes[note][grp][MIDI_CTL_CTL_M];
+        char ctl_L = notes[note][grp][MIDI_CTL_CTL_L];
+        
+        if((ctl_M != 0) || (ctl_L != 0)){
+            int spots = groups[grp];
+            if(spots != 0){
+                // get lights to update
+                for(int spot = 0; spot < PROJ_NB_TOTAL; spot++){
+                    if((spots & 1) == 1){
+                        updateProj(spot, note, grp, ctl_M, ctl_L);
+                    }
+                    spots = spots >> 1;
+                }
+            }
+        }
+    }
+}
+
+/* update a spot */ // TO TEST AND FINISH + TEST TIMING
+void updateProj(char num, char note, char grp, char ctl_M, char ctl_L){
+    char add = getProjAddress(num);  
+    
+    // Dimmer
+    if((ctl_M & MIDI_CTL_DIM_MASK) == MIDI_CTL_DIM_MASK )
+        dmx_data[getProjDimmer(num)+add-2] = notes[note][grp][MIDI_CTL_DIM];
+    else
+        dmx_data[getProjDimmer(num)+add-2] = 0;
+    // Red
+    if((ctl_M & MIDI_CTL_RED_MASK) == MIDI_CTL_RED_MASK )
+        dmx_data[getProjRed(num)+add-2] = notes[note][grp][MIDI_CTL_RED];
+    else
+        dmx_data[getProjRed(num)+add-2] = 0;
+    // Blue
+    if((ctl_M & MIDI_CTL_BLUE_MASK) == MIDI_CTL_BLUE_MASK )
+        dmx_data[getProjBlue(num)+add-2] = notes[note][grp][MIDI_CTL_BLUE];
+    else
+        dmx_data[getProjBlue(num)+add-2] = 0;
+    // Green
+    if((ctl_M & MIDI_CTL_GREEN_MASK) == MIDI_CTL_GREEN_MASK )
+        dmx_data[getProjGreen(num)+add-2] = notes[note][grp][MIDI_CTL_GREEN];
+    else
+        dmx_data[getProjGreen(num)+add-2] = 0;    
+}
\ No newline at end of file
diff -r 000000000000 -r 9cf6898e6b66 projecteurs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/projecteurs.h	Sun Dec 12 12:41:49 2021 +0000
@@ -0,0 +1,82 @@
+/****************************************************************************/
+/*  DMX_MIDI module library                                                 */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - projecteurs.h file                                            */
+/*      Spots are defined as follow :                                       */
+/*          * TYPE (char) : (L)yre, (S)canner, (P)ar, (R)gbawu, Stro(B)e    */
+/*          * ID   (char) : unique identifier of the spot                   */
+/*          * ADR  (uint_16) : DMX first address                            */
+/*          * GROUP(char) : group of the spots                              */
+/*                                                                          */
+/*          * DIM  (char) : channel used for DIMMER         - 0 if not used */
+/*                                                                          */
+/*          * RED  (char) : channel used for RED color      - 0 if not used */
+/*          * GRN  (char) : channel used for GREEN color    - 0 if not used */
+/*          * BLU  (char) : channel used for BLUE color     - 0 if not used */
+/*          * WHT  (char) : channel used for WHITE color    - 0 if not used */
+/*          * AMB  (char) : channel used for AMBER color    - 0 if not used */
+/*          * UV   (char) : channel used for UV color       - 0 if not used */
+/*                                                                          */
+/*          * PAN  (char) : channel used for PAN moves      - 0 if not used */
+/*          * TIL  (char) : channel used for TILT moves     - 0 if not used */
+/*          * SPD  (char) : channel used for SPEED setup    - 0 if not used */
+/*          * STB  (char) : channel used for STROBE function- 0 if not used */
+/*                                                                          */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 16th nov 2021                                 */
+/****************************************************************************/
+
+#ifndef     PROJECTEURS_H_INCLUDED
+#define     PROJECTEURS_H_INCLUDED
+
+#include    "mbed.h"
+#include    "DMX_MIDI.h"
+#include    "controleurs.h"
+
+#define     PROJ_NB_TOTAL       32
+
+#define     DMX_PROJ_NB_DATA    16
+
+#define     DMX_PROJ_ADR        0
+#define     DMX_PROJ_TYPE       2
+#define     DMX_PROJ_ID         3
+#define     DMX_PROJ_GROUP      4
+#define     DMX_PROJ_DIM        5
+#define     DMX_PROJ_RED        6
+#define     DMX_PROJ_GRN        7
+#define     DMX_PROJ_BLU        8
+#define     DMX_PROJ_WHT        9
+#define     DMX_PROJ_AMB        10
+#define     DMX_PROJ_UV         11
+#define     DMX_PROJ_PAN        12
+#define     DMX_PROJ_TIL        13
+#define     DMX_PROJ_SPD        14
+#define     DMX_PROJ_STB        15
+
+/* Global Variables */
+extern      char        projecteurs[PROJ_NB_TOTAL][DMX_PROJ_NB_DATA];
+
+/* Functions */
+/* initialisation of spots */
+void initProjectors(void);
+
+/* get adress of a spot with number */
+uint16_t getProjAddress(char num);
+/* get channel of green of a spot with number */
+char getProjGroup(char num);
+/* get channel of dimmer of a spot with number */
+char getProjDimmer(char num);
+/* get channel of red of a spot with number */
+char getProjRed(char num);
+/* get channel of blue of a spot with number */
+char getProjBlue(char num);
+/* get channel of green of a spot with number */
+char getProjGreen(char num);
+/* update spots */
+void updateProjFromMidi(char  note);
+/* update a spot */
+void updateProj(char num, char note, char grp, char ctl_M, char ctl_L);
+
+#endif
\ No newline at end of file