Open Lighting Architecture
 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 
32 #include <ola/rdm/ResponderOps.h>
33 #include <ola/rdm/ResponderPersonality.h>
34 #include <ola/rdm/ResponderSettings.h>
35 #include <ola/rdm/UID.h>
36 #include <memory>
37 #include <string>
38 #include <vector>
39 
40 namespace ola {
41 namespace rdm {
42 
43 using std::auto_ptr;
44 
49  public:
50  explicit AdvancedDimmerResponder(const UID &uid);
51 
52  void SendRDMRequest(const RDMRequest *request, RDMCallback *callback);
53 
54  private:
58  class RDMOps : public ResponderOps<AdvancedDimmerResponder> {
59  public:
60  static RDMOps *Instance() {
61  if (!instance)
62  instance = new RDMOps();
63  return instance;
64  }
65 
66  private:
67  RDMOps() : ResponderOps<AdvancedDimmerResponder>(PARAM_HANDLERS) {}
68  static RDMOps *instance;
69  };
70 
74  class Personalities : public PersonalityCollection {
75  public:
76  static const Personalities *Instance();
77 
78  private:
79  explicit Personalities(const PersonalityList &personalities) :
80  PersonalityCollection(personalities) {
81  }
82 
83  static Personalities *instance;
84  };
85 
86  class LockManager: public BasicSettingManager {
87  public:
88  explicit LockManager(const SettingCollection<BasicSetting> *settings)
89  : BasicSettingManager(settings) {
90  }
91 
92  const RDMResponse *SetWithPin(const RDMRequest *request, uint16_t pin);
93  };
94 
95  struct min_level_s {
96  uint16_t min_level_increasing;
97  uint16_t min_level_decreasing;
98  uint8_t on_below_min;
99  } __attribute__((packed));
100 
101  struct preset_playback_s {
102  uint16_t mode;
103  uint8_t level;
104  } __attribute__((packed));
105 
106  struct preset_status_s {
107  uint16_t scene;
108  uint16_t fade_up_time;
109  uint16_t fade_down_time;
110  uint16_t wait_time;
111  uint8_t programmed;
112  } __attribute__((packed));
113 
114  struct fail_mode_s {
115  uint16_t scene;
116  uint16_t delay;
117  uint16_t hold_time;
118  uint8_t level;
119  } __attribute__((packed));
120 
121  typedef fail_mode_s startup_mode_s;
122 
123  /*
124  * Represents a preset
125  */
126  class Preset {
127  public:
128  Preset()
129  : fade_up_time(0),
130  fade_down_time(0),
131  wait_time(0),
132  programmed(PRESET_NOT_PROGRAMMED) {
133  }
134 
135  // Times are in 1/0ths of a second.
136  uint16_t fade_up_time;
137  uint16_t fade_down_time;
138  uint16_t wait_time;
139  rdm_preset_programmed_mode programmed;
140  };
141 
142  const UID m_uid;
143  bool m_identify_state;
144  uint16_t m_start_address;
145  uint16_t m_lock_pin;
146  uint16_t m_maximum_level;
147  min_level_s m_min_level;
148  rdm_identify_mode m_identify_mode;
149  uint8_t m_burn_in;
150  bool m_power_on_self_test;
151  PersonalityManager m_personality_manager;
152  BasicSettingManager m_curve_settings;
153  BasicSettingManager m_response_time_settings;
154  LockManager m_lock_settings;
155  SettingManager<FrequencyModulationSetting> m_frequency_settings;
156  std::vector<Preset> m_presets;
157  uint16_t m_preset_scene;
158  uint8_t m_preset_level;
159  rdm_preset_merge_mode m_preset_merge_mode;
160  fail_mode_s m_fail_mode;
161  startup_mode_s m_startup_mode;
162 
163  // Helpers
164  bool ValueBetweenRange(const uint16_t value,
165  const uint16_t lower,
166  const uint16_t upper);
167 
168  // Pids
169  const RDMResponse *GetDeviceInfo(const RDMRequest *request);
170  const RDMResponse *GetProductDetailList(const RDMRequest *request);
171  const RDMResponse *GetDeviceModelDescription(const RDMRequest *request);
172  const RDMResponse *GetManufacturerLabel(const RDMRequest *request);
173  const RDMResponse *GetDeviceLabel(const RDMRequest *request);
174  const RDMResponse *GetSoftwareVersionLabel(const RDMRequest *request);
175  const RDMResponse *GetPersonality(const RDMRequest *request);
176  const RDMResponse *SetPersonality(const RDMRequest *request);
177  const RDMResponse *GetPersonalityDescription(const RDMRequest *request);
178  const RDMResponse *GetDmxStartAddress(const RDMRequest *request);
179  const RDMResponse *SetDmxStartAddress(const RDMRequest *request);
180  const RDMResponse *GetDimmerInfo(const RDMRequest *request);
181  const RDMResponse *GetMinimumLevel(const RDMRequest *request);
182  const RDMResponse *SetMinimumLevel(const RDMRequest *request);
183  const RDMResponse *GetMaximumLevel(const RDMRequest *request);
184  const RDMResponse *SetMaximumLevel(const RDMRequest *request);
185  const RDMResponse *GetIdentify(const RDMRequest *request);
186  const RDMResponse *SetIdentify(const RDMRequest *request);
187  const RDMResponse *SetCapturePreset(const RDMRequest *request);
188  const RDMResponse *GetPresetPlayback(const RDMRequest *request);
189  const RDMResponse *SetPresetPlayback(const RDMRequest *request);
190  const RDMResponse *GetPresetStatus(const RDMRequest *request);
191  const RDMResponse *SetPresetStatus(const RDMRequest *request);
192  const RDMResponse *GetPresetMergeMode(const RDMRequest *request);
193  const RDMResponse *SetPresetMergeMode(const RDMRequest *request);
194  const RDMResponse *GetPresetInfo(const RDMRequest *request);
195  const RDMResponse *GetFailMode(const RDMRequest *request);
196  const RDMResponse *SetFailMode(const RDMRequest *request);
197  const RDMResponse *GetStartUpMode(const RDMRequest *request);
198  const RDMResponse *SetStartUpMode(const RDMRequest *request);
199  const RDMResponse *GetIdentifyMode(const RDMRequest *request);
200  const RDMResponse *SetIdentifyMode(const RDMRequest *request);
201  const RDMResponse *GetBurnIn(const RDMRequest *request);
202  const RDMResponse *SetBurnIn(const RDMRequest *request);
203  const RDMResponse *GetCurve(const RDMRequest *request);
204  const RDMResponse *SetCurve(const RDMRequest *request);
205  const RDMResponse *GetCurveDescription(const RDMRequest *request);
206  const RDMResponse *GetResponseTime(const RDMRequest *request);
207  const RDMResponse *SetResponseTime(const RDMRequest *request);
208  const RDMResponse *GetResponseTimeDescription(const RDMRequest *request);
209  const RDMResponse *GetPWMFrequency(const RDMRequest *request);
210  const RDMResponse *SetPWMFrequency(const RDMRequest *request);
211  const RDMResponse *GetPWMFrequencyDescription(const RDMRequest *request);
212  const RDMResponse *GetLockState(const RDMRequest *request);
213  const RDMResponse *SetLockState(const RDMRequest *request);
214  const RDMResponse *GetLockStateDescription(const RDMRequest *request);
215  const RDMResponse *GetLockPin(const RDMRequest *request);
216  const RDMResponse *SetLockPin(const RDMRequest *request);
217  const RDMResponse *GetPowerOnSelfTest(const RDMRequest *request);
218  const RDMResponse *SetPowerOnSelfTest(const RDMRequest *request);
219 
220  static const uint8_t DIMMER_RESOLUTION;
221  static const uint16_t LOWER_MIN_LEVEL;
222  static const uint16_t UPPER_MIN_LEVEL;
223  static const uint16_t LOWER_MAX_LEVEL;
224  static const uint16_t UPPER_MAX_LEVEL;
225  static const unsigned int PRESET_COUNT;
226 
227  static const uint16_t MIN_FAIL_DELAY_TIME;
228  static const uint16_t MIN_FAIL_HOLD_TIME;
229  static const uint16_t MAX_FAIL_DELAY_TIME;
230  static const uint16_t MAX_FAIL_HOLD_TIME;
231  static const uint16_t MIN_STARTUP_DELAY_TIME;
232  static const uint16_t MIN_STARTUP_HOLD_TIME;
233  static const uint16_t MAX_STARTUP_DELAY_TIME;
234  static const uint16_t MAX_STARTUP_HOLD_TIME;
235  static const uint16_t INFINITE_TIME;
236 
238  PARAM_HANDLERS[];
239  static const char* CURVES[];
240  static const char* RESPONSE_TIMES[];
241  static const char* LOCK_STATES[];
243  PWM_FREQUENCIES[];
244 
245  static const SettingCollection<BasicSetting> CurveSettings;
246  static const SettingCollection<BasicSetting> ResponseTimeSettings;
248  FrequencySettings;
249  static const SettingCollection<BasicSetting> LockSettings;
250 };
251 } // namespace rdm
252 } // namespace ola
253 #endif // INCLUDE_OLA_RDM_ADVANCEDDIMMERRESPONDER_H_