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