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>
235 uint16_t data = ((m_current_setting + m_settings->Offset()) << 8 |
236 m_settings->Count());
237 if (m_settings->Offset() == 0) {
241 return ResponderHelper::GetUInt16Value(request, data);
244 template <
class SettingType>
245 const RDMResponse *SettingManager<SettingType>::Set(
246 const RDMRequest *request) {
248 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
252 unsigned int offset = m_settings->Offset();
253 if (arg < offset || arg >= m_settings->Count() + offset) {
256 m_current_setting = arg - offset;
257 return ResponderHelper::EmptySetResponse(request);
261 template <
class SettingType>
262 const RDMResponse *SettingManager<SettingType>::GetDescription(
263 const RDMRequest *request)
const {
265 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
269 unsigned int offset = m_settings->Offset();
271 if (arg == 0 || arg >= m_settings->Count() + offset) {
274 const SettingType *setting = m_settings->Lookup(arg - offset);
276 setting->DescriptionResponseSize()];
277 unsigned int size = setting->GenerateDescriptionResponse(arg, output);
282 template <
class SettingType>
283 bool SettingManager<SettingType>::ChangeSetting(uint8_t new_setting) {
284 uint8_t offset = m_settings->Offset();
286 if (new_setting < offset || new_setting >= m_settings->Count() + offset)
289 m_current_setting = new_setting - offset;
294 #endif // INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_