Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AdvancedDimmerResponder.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * AdvancedDimmerResponder_h
17  * Copyright (C) 2013 Simon Newton
18  */
19 
28 #ifndef INCLUDE_OLA_RDM_ADVANCEDDIMMERRESPONDER_H_
29 #define INCLUDE_OLA_RDM_ADVANCEDDIMMERRESPONDER_H_
30 
31 #include <ola/base/Macro.h>
33 #include <ola/rdm/ResponderOps.h>
34 #include <ola/rdm/ResponderPersonality.h>
35 #include <ola/rdm/ResponderSettings.h>
36 #include <ola/rdm/UID.h>
37 #include <memory>
38 #include <string>
39 #include <vector>
40 
41 namespace ola {
42 namespace rdm {
43 
48  public:
49  explicit AdvancedDimmerResponder(const UID &uid);
50 
51  void SendRDMRequest(const RDMRequest *request, RDMCallback *callback);
52 
53  private:
57  class RDMOps : public ResponderOps<AdvancedDimmerResponder> {
58  public:
59  static RDMOps *Instance() {
60  if (!instance)
61  instance = new RDMOps();
62  return instance;
63  }
64 
65  private:
66  RDMOps() : ResponderOps<AdvancedDimmerResponder>(PARAM_HANDLERS) {}
67  static RDMOps *instance;
68  };
69 
73  class Personalities : public PersonalityCollection {
74  public:
75  static const Personalities *Instance();
76 
77  private:
78  explicit Personalities(const PersonalityList &personalities) :
79  PersonalityCollection(personalities) {
80  }
81 
82  static Personalities *instance;
83  };
84 
85  class LockManager: public BasicSettingManager {
86  public:
87  explicit LockManager(const SettingCollection<BasicSetting> *settings)
88  : BasicSettingManager(settings) {
89  }
90 
91  const RDMResponse *SetWithPin(const RDMRequest *request, uint16_t pin);
92  };
93 
94  PACK(
95  struct min_level_s {
96  uint16_t min_level_increasing;
97  uint16_t min_level_decreasing;
98  uint8_t on_below_min;
99  });
100 
101  PACK(
102  struct preset_playback_s {
103  uint16_t mode;
104  uint8_t level;
105  });
106 
107  PACK(
108  struct preset_status_s {
109  uint16_t scene;
110  uint16_t fade_up_time;
111  uint16_t fade_down_time;
112  uint16_t wait_time;
113  uint8_t programmed;
114  });
115 
116  PACK(
117  struct fail_mode_s {
118  uint16_t scene;
119  uint16_t delay;
120  uint16_t hold_time;
121  uint8_t level;
122  });
123 
124  typedef fail_mode_s startup_mode_s;
125 
126  /*
127  * Represents a preset
128  */
129  class Preset {
130  public:
131  Preset()
132  : fade_up_time(0),
133  fade_down_time(0),
134  wait_time(0),
135  programmed(PRESET_NOT_PROGRAMMED) {
136  }
137 
138  // Times are in 1/0ths of a second.
139  uint16_t fade_up_time;
140  uint16_t fade_down_time;
141  uint16_t wait_time;
142  rdm_preset_programmed_mode programmed;
143  };
144 
145  const UID m_uid;
146  bool m_identify_state;
147  uint16_t m_start_address;
148  uint16_t m_lock_pin;
149  uint16_t m_maximum_level;
150  min_level_s m_min_level;
151  rdm_identify_mode m_identify_mode;
152  uint8_t m_burn_in;
153  bool m_power_on_self_test;
154  PersonalityManager m_personality_manager;
155  BasicSettingManager m_curve_settings;
156  BasicSettingManager m_response_time_settings;
157  LockManager m_lock_settings;
158  SettingManager<FrequencyModulationSetting> m_frequency_settings;
159  std::vector<Preset> m_presets;
160  uint16_t m_preset_scene;
161  uint8_t m_preset_level;
162  rdm_preset_mergemode m_preset_mergemode;
163  fail_mode_s m_fail_mode;
164  startup_mode_s m_startup_mode;
165 
166  // Helpers
167  bool ValueBetweenRange(const uint16_t value,
168  const uint16_t lower,
169  const uint16_t upper);
170 
171  // Pids
172  const RDMResponse *GetDeviceInfo(const RDMRequest *request);
173  const RDMResponse *GetProductDetailList(const RDMRequest *request);
174  const RDMResponse *GetDeviceModelDescription(const RDMRequest *request);
175  const RDMResponse *GetManufacturerLabel(const RDMRequest *request);
176  const RDMResponse *GetDeviceLabel(const RDMRequest *request);
177  const RDMResponse *GetSoftwareVersionLabel(const RDMRequest *request);
178  const RDMResponse *GetPersonality(const RDMRequest *request);
179  const RDMResponse *SetPersonality(const RDMRequest *request);
180  const RDMResponse *GetPersonalityDescription(const RDMRequest *request);
181  const RDMResponse *GetDmxStartAddress(const RDMRequest *request);
182  const RDMResponse *SetDmxStartAddress(const RDMRequest *request);
183  const RDMResponse *GetDimmerInfo(const RDMRequest *request);
184  const RDMResponse *GetMinimumLevel(const RDMRequest *request);
185  const RDMResponse *SetMinimumLevel(const RDMRequest *request);
186  const RDMResponse *GetMaximumLevel(const RDMRequest *request);
187  const RDMResponse *SetMaximumLevel(const RDMRequest *request);
188  const RDMResponse *GetIdentify(const RDMRequest *request);
189  const RDMResponse *SetIdentify(const RDMRequest *request);
190  const RDMResponse *SetCapturePreset(const RDMRequest *request);
191  const RDMResponse *GetPresetPlayback(const RDMRequest *request);
192  const RDMResponse *SetPresetPlayback(const RDMRequest *request);
193  const RDMResponse *GetPresetStatus(const RDMRequest *request);
194  const RDMResponse *SetPresetStatus(const RDMRequest *request);
195  const RDMResponse *GetPresetMergeMode(const RDMRequest *request);
196  const RDMResponse *SetPresetMergeMode(const RDMRequest *request);
197  const RDMResponse *GetPresetInfo(const RDMRequest *request);
198  const RDMResponse *GetFailMode(const RDMRequest *request);
199  const RDMResponse *SetFailMode(const RDMRequest *request);
200  const RDMResponse *GetStartUpMode(const RDMRequest *request);
201  const RDMResponse *SetStartUpMode(const RDMRequest *request);
202  const RDMResponse *GetIdentifyMode(const RDMRequest *request);
203  const RDMResponse *SetIdentifyMode(const RDMRequest *request);
204  const RDMResponse *GetBurnIn(const RDMRequest *request);
205  const RDMResponse *SetBurnIn(const RDMRequest *request);
206  const RDMResponse *GetCurve(const RDMRequest *request);
207  const RDMResponse *SetCurve(const RDMRequest *request);
208  const RDMResponse *GetCurveDescription(const RDMRequest *request);
209  const RDMResponse *GetResponseTime(const RDMRequest *request);
210  const RDMResponse *SetResponseTime(const RDMRequest *request);
211  const RDMResponse *GetResponseTimeDescription(const RDMRequest *request);
212  const RDMResponse *GetPWMFrequency(const RDMRequest *request);
213  const RDMResponse *SetPWMFrequency(const RDMRequest *request);
214  const RDMResponse *GetPWMFrequencyDescription(const RDMRequest *request);
215  const RDMResponse *GetLockState(const RDMRequest *request);
216  const RDMResponse *SetLockState(const RDMRequest *request);
217  const RDMResponse *GetLockStateDescription(const RDMRequest *request);
218  const RDMResponse *GetLockPin(const RDMRequest *request);
219  const RDMResponse *SetLockPin(const RDMRequest *request);
220  const RDMResponse *GetPowerOnSelfTest(const RDMRequest *request);
221  const RDMResponse *SetPowerOnSelfTest(const RDMRequest *request);
222 
223  static const uint8_t DIMMER_RESOLUTION;
224  static const uint16_t LOWER_MIN_LEVEL;
225  static const uint16_t UPPER_MIN_LEVEL;
226  static const uint16_t LOWER_MAX_LEVEL;
227  static const uint16_t UPPER_MAX_LEVEL;
228  static const unsigned int PRESET_COUNT;
229 
230  static const uint16_t MIN_FAIL_DELAY_TIME;
231  static const uint16_t MIN_FAIL_HOLD_TIME;
232  static const uint16_t MAX_FAIL_DELAY_TIME;
233  static const uint16_t MAX_FAIL_HOLD_TIME;
234  static const uint16_t MIN_STARTUP_DELAY_TIME;
235  static const uint16_t MIN_STARTUP_HOLD_TIME;
236  static const uint16_t MAX_STARTUP_DELAY_TIME;
237  static const uint16_t MAX_STARTUP_HOLD_TIME;
238  static const uint16_t INFINITE_TIME;
239 
241  PARAM_HANDLERS[];
242  static const char* CURVES[];
243  static const char* RESPONSE_TIMES[];
244  static const char* LOCK_STATES[];
246  PWM_FREQUENCIES[];
247 
248  static const SettingCollection<BasicSetting> CurveSettings;
249  static const SettingCollection<BasicSetting> ResponseTimeSettings;
251  FrequencySettings;
252  static const SettingCollection<BasicSetting> LockSettings;
253 };
254 } // namespace rdm
255 } // namespace ola
256 #endif // INCLUDE_OLA_RDM_ADVANCEDDIMMERRESPONDER_H_