20 #ifndef INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_
21 #define INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_
57 uint8_t *data)
const = 0;
65 typedef const char* ArgType;
79 unsigned int DescriptionResponseSize()
const {
80 return sizeof(description_s);
83 unsigned int GenerateDescriptionResponse(uint8_t index,
88 struct description_s {
90 char description[MAX_RDM_STRING_LENGTH];
93 std::string m_description;
130 unsigned int DescriptionResponseSize()
const {
131 return sizeof(description_s);
134 unsigned int GenerateDescriptionResponse(uint8_t index,
135 uint8_t *data)
const;
139 struct description_s {
142 char description[MAX_RDM_STRING_LENGTH];
145 uint32_t m_frequency;
146 std::string m_description;
158 template <
class SettingType>
167 unsigned int arg_count,
168 bool zero_offset =
false)
169 : m_zero_offset(zero_offset) {
170 for (
unsigned int i = 0; i < arg_count; i++) {
171 m_settings.push_back(SettingType(args[i]));
175 uint8_t Count()
const {
return m_settings.size(); }
177 const SettingType *Lookup(uint8_t index)
const {
178 if (index > m_settings.size()) {
181 return &m_settings[index];
184 unsigned int Offset()
const {
185 return m_zero_offset ? 0 : 1;
192 std::vector<SettingType> m_settings;
193 const bool m_zero_offset;
200 template <
class SettingType>
204 : m_settings(settings),
205 m_current_setting(settings->Offset()) {
214 uint8_t Count()
const {
215 return m_settings->Count();
218 uint8_t CurrentSetting()
const {
219 return m_current_setting + m_settings->Offset();
222 bool ChangeSetting(uint8_t state);
226 uint8_t m_current_setting;
232 template <
class SettingType>
234 uint16_t data = ((m_current_setting + m_settings->Offset()) << 8 |
235 m_settings->Count());
236 if (m_settings->Offset() == 0) {
240 return ResponderHelper::GetUInt16Value(request, data);
243 template <
class SettingType>
244 RDMResponse *SettingManager<SettingType>::Set(
const RDMRequest *request) {
246 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
250 unsigned int offset = m_settings->Offset();
251 if (arg < offset || arg >= m_settings->Count() + offset) {
254 m_current_setting = arg - offset;
255 return ResponderHelper::EmptySetResponse(request);
259 template <
class SettingType>
260 RDMResponse *SettingManager<SettingType>::GetDescription(
261 const RDMRequest *request)
const {
263 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
267 unsigned int offset = m_settings->Offset();
269 if (arg == 0 || arg >= m_settings->Count() + offset) {
272 const SettingType *setting = m_settings->Lookup(arg - offset);
274 setting->DescriptionResponseSize()];
275 unsigned int size = setting->GenerateDescriptionResponse(arg, output);
280 template <
class SettingType>
281 bool SettingManager<SettingType>::ChangeSetting(uint8_t new_setting) {
282 uint8_t offset = m_settings->Offset();
284 if (new_setting < offset || new_setting >= m_settings->Count() + offset)
287 m_current_setting = new_setting - offset;
292 #endif // INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_