Lumiverse  2.5
A framework for creating lighting control applications
DMXDevicePatch.h
Go to the documentation of this file.
1 
4 #ifndef _DMXDEVICEPATCH_H_
5 #define _DMXDEVICEPATCH_H_
6 
7 #pragma once
8 #include "../Device.h"
9 #include <sstream>
10 #include <unordered_map>
11 
12 namespace Lumiverse {
20  ENUM,
28  };
29 #ifdef USE_C11_MAPS
30  static unordered_map<int, string> convTypeToString = {
31  { FLOAT_TO_SINGLE, "FLOAT_TO_SINGLE" }, { FLOAT_TO_FINE, "FLOAT_TO_FINE" },
32  { ENUM, "ENUM" }, { RGB_REPEAT2, "RGB_REPEAT2" }, { RGB_REPEAT3, "RGB_REPEAT3" },
33  { RGB_REPEAT4, "RGB_REPEAT4" }, { COLOR_RGB, "COLOR_RGB" }, { COLOR_RGBW, "COLOR_RGBW" },
34  { ORI_TO_FINE, "ORI_TO_FINE" }, { COLOR_LUSTRPLUS, "COLOR_LUSTRPLUS" }
35  };
36 
37  static unordered_map<string, int> stringToConvType = {
38  { "FLOAT_TO_SINGLE", FLOAT_TO_SINGLE }, { "FLOAT_TO_FINE", FLOAT_TO_FINE },
39  { "ENUM", ENUM }, { "RGB_REPEAT2", RGB_REPEAT2 }, { "RGB_REPEAT3", RGB_REPEAT3 },
40  { "RGB_REPEAT4", RGB_REPEAT4 }, { "COLOR_RGB", COLOR_RGB }, { "COLOR_RGBW", COLOR_RGBW },
41  { "ORI_TO_FINE", ORI_TO_FINE }, { "COLOR_LUSTRPLUS", COLOR_LUSTRPLUS }
42  };
43 #else
44  static string convTypeToString(conversionType t) {
45  if (t == FLOAT_TO_SINGLE) { return "FLOAT_TO_SINGLE"; }
46  else if (t == FLOAT_TO_FINE) { return "FLOAT_TO_FINE"; }
47  else if (t == ENUM) { return "ENUM"; }
48  else if (t == RGB_REPEAT2) { return "RGB_REPEAT2"; }
49  else if (t == RGB_REPEAT3) { return "RGB_REPEAT3"; }
50  else if (t == RGB_REPEAT4) { return "RGB_REPEAT4"; }
51  else if (t == COLOR_RGB) { return "COLOR_RGB"; }
52  else if (t == COLOR_RGBW) { return "COLOR_RGBW"; }
53  else if (t == ORI_TO_FINE) { return "ORI_TO_FINE"; }
54  else if (t == COLOR_LUSTRPLUS) { return "COLOR_LUSTRPLUS"; }
55  else {
56  Logger::log(WARN, "Unknown conversion type. Defaulting to float to single.");
57  return "FLOAT_TO_SINGLE";
58  }
59  }
60 
61  static conversionType stringToConvType(string t) {
62  if (t == "FLOAT_TO_SINGLE") { return FLOAT_TO_SINGLE; }
63  else if (t == "FLOAT_TO_FINE") { return FLOAT_TO_FINE; }
64  else if (t == "ENUM") { return ENUM; }
65  else if (t == "RGB_REPEAT2") { return RGB_REPEAT2; }
66  else if (t == "RGB_REPEAT3") { return RGB_REPEAT3; }
67  else if (t == "RGB_REPEAT4") { return RGB_REPEAT4; }
68  else if (t == "COLOR_RGB") { return COLOR_RGB; }
69  else if (t == "COLOR_RGBW") { return COLOR_RGBW; }
70  else if (t == "ORI_TO_FINE") { return ORI_TO_FINE; }
71  else if (t == "COLOR_LUSTRPLUS") { return COLOR_LUSTRPLUS; }
72  else {
73  Logger::log(WARN, "Unknown conversion type. Defaulting to float to single.");
74  return FLOAT_TO_SINGLE;
75  }
76  }
77 #endif
78 
84  struct patchData {
93  unsigned int startAddress;
94 
100 
105  patchData() : startAddress(0), type(FLOAT_TO_SINGLE) { }
106 
112  patchData(unsigned int addr, conversionType t) : startAddress(addr), type(t) { }
113 
118  patchData(unsigned int addr, string t) : startAddress(addr) {
119 #ifdef USE_C11_MAPS
120  type = (conversionType) stringToConvType[t];
121 #else
122  type = (conversionType) stringToConvType(t);
123 #endif
124  }
125  };
126 
138  {
139  public:
147  DMXDevicePatch(string mapKey, unsigned int baseAddress, unsigned int universe);
148 
150  ~DMXDevicePatch();
151 
160  void updateDMX(unsigned char* data, Device* device, map<string, patchData>& dmxMap);
161 
164  unsigned int getUniverse() { return m_universe; }
165 
170  void setUniverse(unsigned char newUniverse) { m_universe = newUniverse; }
171 
176  unsigned int getBaseAddress() { return m_baseAddress; }
177 
182  void setBaseAddress(unsigned int newAddress) { m_baseAddress = newAddress; }
183 
189  string getDMXMapKey() { return m_dmxMapKey; }
190 
191  private:
193  unsigned int m_baseAddress;
194 
196  unsigned int m_universe;
197 
199  unsigned int m_numAddresses;
200 
209  //map<string, patchData> m_dmxMap;
210  string m_dmxMapKey;
211 
212  // Conversion Functions
213  // These functions all take in a universe of DMX and stick their converted
214  // value in the right place.
215  // --------------------------------------------------------------------------
216 
225  void floatToSingle(unsigned char* data, unsigned int address, LumiverseFloat* val);
226 
237  void floatToFine(unsigned char* data, unsigned int address, float val);
238 
247  void toEnum(unsigned char* data, unsigned int address, LumiverseEnum* val);
248 
260  void RGBRepeat(unsigned char* data, unsigned int address, LumiverseFloat* val, int repeats);
261 
270  void ColorToRGB(unsigned char* data, unsigned int address, LumiverseColor* val);
271 
280  void ColorToRGBW(unsigned char* data, unsigned int address, LumiverseColor* val);
281 
291  void ColorToLustrPlus(unsigned char* data, unsigned int address, LumiverseColor* val);
292 
301  inline void setDMXVal(unsigned char* data, unsigned int address, unsigned char val);
302  };
303 }
304 
305 #endif
Defines an enumeration in Lumiverse.
Definition: LumiverseEnum.h:43
unsigned int m_universe
Universe number for the device (zero-indexed)
Definition: DMXDevicePatch.h:196
void ColorToLustrPlus(unsigned char *data, unsigned int address, LumiverseColor *val)
Converts a LumiverseColor to 7 channels of DMX data.
Definition: DMXDevicePatch.cpp:155
unsigned int m_numAddresses
Number of addresses this device uses on a DMX network.
Definition: DMXDevicePatch.h:199
void setDMXVal(unsigned char *data, unsigned int address, unsigned char val)
Helper for setting DMX values.
Definition: DMXDevicePatch.cpp:165
Definition: DMXDevicePatch.h:27
This class describes a color.
Definition: LumiverseColor.h:83
string getDMXMapKey()
Gets the key for the DMX map this device should use to translate its Lumiverse values to DMX values...
Definition: DMXDevicePatch.h:189
Definition: DMXDevicePatch.h:26
conversionType
Enumeration maps to a function that performs the appropriate conversion from Lumiverse value to DMX v...
Definition: DMXDevicePatch.h:17
void ColorToRGBW(unsigned char *data, unsigned int address, LumiverseColor *val)
Converts a LumiverseColor to 4 channels of DMX data.
Definition: DMXDevicePatch.cpp:143
patchData()
Constructs a default patch entry.
Definition: DMXDevicePatch.h:105
Definition: DMXDevicePatch.h:21
Definition: DMXDevicePatch.h:18
void ColorToRGB(unsigned char *data, unsigned int address, LumiverseColor *val)
Converts a LumiverseColor to 3 channels of DMX data.
Definition: DMXDevicePatch.cpp:132
~DMXDevicePatch()
Destroys the patch object.
Definition: DMXDevicePatch.cpp:11
DMXDevicePatch(string mapKey, unsigned int baseAddress, unsigned int universe)
Constructs an empty patch.
Definition: DMXDevicePatch.cpp:5
Definition: DMXDevicePatch.h:22
void setUniverse(unsigned char newUniverse)
Sets the universe the device is patched to.
Definition: DMXDevicePatch.h:170
This class includes information on how to translate the device properties for a given device to DMX v...
Definition: DMXDevicePatch.h:137
void floatToSingle(unsigned char *data, unsigned int address, LumiverseFloat *val)
Converts a float value to a single DMX channel of data. min-max -> 0-255.
Definition: DMXDevicePatch.cpp:105
Definition: DMXDevicePatch.h:25
unsigned int startAddress
Starting address for the parameter.
Definition: DMXDevicePatch.h:93
unsigned int getBaseAddress()
Gets the base address for the device.
Definition: DMXDevicePatch.h:176
Definition: DMXDevicePatch.h:23
Definition: DMXDevicePatch.h:24
void RGBRepeat(unsigned char *data, unsigned int address, LumiverseFloat *val, int repeats)
Converts a float value to a single DMX channel of data. min-max -> 0-255 and repeats it a number of t...
Definition: DMXDevicePatch.cpp:125
void toEnum(unsigned char *data, unsigned int address, LumiverseEnum *val)
Converts an enum to a single DMX channel of data.
Definition: DMXDevicePatch.cpp:118
void log(LOG_LEVEL level, string message)
Logs a meesage to the output file.
Definition: Logger.cpp:46
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
void updateDMX(unsigned char *data, Device *device, map< string, patchData > &dmxMap)
Given a universe of DMX, update the device.
Definition: DMXDevicePatch.cpp:15
Definition: DMXDevicePatch.h:20
Defines a float in Lumiverse.
Definition: LumiverseFloat.h:21
conversionType type
How the LumiverseType should be converted to DMX.
Definition: DMXDevicePatch.h:99
void floatToFine(unsigned char *data, unsigned int address, float val)
Converts a float value to two DMX channels of data. min-max -> 0 - 65535.
Definition: DMXDevicePatch.cpp:110
unsigned int getUniverse()
Gets the universe the device is patched to.
Definition: DMXDevicePatch.h:164
A Device in Lumiverse maintains information about a lighting device.
Definition: Device.h:55
Definition: DMXDevicePatch.h:19
patchData(unsigned int addr, string t)
Constructs a patch entry from a string conversionType.
Definition: DMXDevicePatch.h:118
Definition: Logger.h:25
string m_dmxMapKey
Key to get the map that maps device parameters to a start DMX address.
Definition: DMXDevicePatch.h:210
patchData(unsigned int addr, conversionType t)
Constructs a patch entry.
Definition: DMXDevicePatch.h:112
Small struct containing information on where the DMX parameter starts and how to convert it to the ri...
Definition: DMXDevicePatch.h:84
unsigned int m_baseAddress
Base address for the device (zero-indexed)
Definition: DMXDevicePatch.h:193
void setBaseAddress(unsigned int newAddress)
Sets the base address for the device.
Definition: DMXDevicePatch.h:182