20 #ifndef INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_
21 #define INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_
58 uint8_t *data)
const = 0;
66 typedef const char* ArgType;
80 unsigned int DescriptionResponseSize()
const {
81 return sizeof(description_s);
84 unsigned int GenerateDescriptionResponse(uint8_t index,
88 struct description_s {
90 char description[MAX_RDM_STRING_LENGTH];
91 } __attribute__((packed));
130 unsigned int DescriptionResponseSize()
const {
131 return sizeof(description_s);
134 unsigned int GenerateDescriptionResponse(uint8_t index,
135 uint8_t *data)
const;
138 struct description_s {
141 char description[MAX_RDM_STRING_LENGTH];
142 } __attribute__((packed));
144 uint32_t m_frequency;
145 string m_description;
157 template <
class SettingType>
166 unsigned int arg_count,
167 bool zero_offset =
false)
168 : m_zero_offset(zero_offset) {
169 for (
unsigned int i = 0; i < arg_count; i++) {
170 m_settings.push_back(SettingType(args[i]));
174 uint8_t Count()
const {
return m_settings.size(); }
176 const SettingType *Lookup(uint8_t index)
const {
177 if (index > m_settings.size()) {
180 return &m_settings[index];
183 unsigned int Offset()
const {
184 return m_zero_offset ? 0 : 1;
191 std::vector<SettingType> m_settings;
192 const bool m_zero_offset;
199 template <
class SettingType>
203 : m_settings(settings),
204 m_current_setting(settings->Offset()) {
213 uint8_t Count()
const {
214 return m_settings->Count();
217 uint8_t CurrentSetting()
const {
218 return m_current_setting + m_settings->Offset();
221 bool ChangeSetting(uint8_t state);
225 uint8_t m_current_setting;
231 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 const RDMResponse *SettingManager<SettingType>::Set(
245 const RDMRequest *request) {
247 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
248 return NackWithReason(request, NR_FORMAT_ERROR);
251 unsigned int offset = m_settings->Offset();
252 if (arg < offset || arg >= m_settings->Count() + offset) {
253 return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
255 m_current_setting = arg - offset;
256 return ResponderHelper::EmptySetResponse(request);
260 template <
class SettingType>
261 const RDMResponse *SettingManager<SettingType>::GetDescription(
262 const RDMRequest *request)
const {
264 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
265 return NackWithReason(request, NR_FORMAT_ERROR);
268 unsigned int offset = m_settings->Offset();
270 if (arg == 0 || arg >= m_settings->Count() + offset) {
271 return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
273 const SettingType *setting = m_settings->Lookup(arg - offset);
274 uint8_t output[setting->DescriptionResponseSize()];
275 unsigned int size = setting->GenerateDescriptionResponse(arg, output);
276 return GetResponseFromData(request, output, size, RDM_ACK);
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_