20 #ifndef INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_
21 #define INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_
56 uint8_t *data)
const = 0;
64 typedef const char* ArgType;
78 unsigned int DescriptionResponseSize()
const {
79 return sizeof(description_s);
82 unsigned int GenerateDescriptionResponse(uint8_t index,
86 struct description_s {
88 char description[MAX_RDM_STRING_LENGTH];
89 } __attribute__((packed));
91 std::string m_description;
128 unsigned int DescriptionResponseSize()
const {
129 return sizeof(description_s);
132 unsigned int GenerateDescriptionResponse(uint8_t index,
133 uint8_t *data)
const;
136 struct description_s {
139 char description[MAX_RDM_STRING_LENGTH];
140 } __attribute__((packed));
142 uint32_t m_frequency;
143 std::string m_description;
155 template <
class SettingType>
164 unsigned int arg_count,
165 bool zero_offset =
false)
166 : m_zero_offset(zero_offset) {
167 for (
unsigned int i = 0; i < arg_count; i++) {
168 m_settings.push_back(SettingType(args[i]));
172 uint8_t Count()
const {
return m_settings.size(); }
174 const SettingType *Lookup(uint8_t index)
const {
175 if (index > m_settings.size()) {
178 return &m_settings[index];
181 unsigned int Offset()
const {
182 return m_zero_offset ? 0 : 1;
189 std::vector<SettingType> m_settings;
190 const bool m_zero_offset;
197 template <
class SettingType>
201 : m_settings(settings),
202 m_current_setting(settings->Offset()) {
211 uint8_t Count()
const {
212 return m_settings->Count();
215 uint8_t CurrentSetting()
const {
216 return m_current_setting + m_settings->Offset();
219 bool ChangeSetting(uint8_t state);
223 uint8_t m_current_setting;
229 template <
class SettingType>
232 uint16_t data = ((m_current_setting + m_settings->Offset()) << 8 |
233 m_settings->Count());
234 if (m_settings->Offset() == 0) {
238 return ResponderHelper::GetUInt16Value(request, data);
241 template <
class SettingType>
242 const RDMResponse *SettingManager<SettingType>::Set(
243 const RDMRequest *request) {
245 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
246 return NackWithReason(request, NR_FORMAT_ERROR);
249 unsigned int offset = m_settings->Offset();
250 if (arg < offset || arg >= m_settings->Count() + offset) {
251 return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
253 m_current_setting = arg - offset;
254 return ResponderHelper::EmptySetResponse(request);
258 template <
class SettingType>
259 const RDMResponse *SettingManager<SettingType>::GetDescription(
260 const RDMRequest *request)
const {
262 if (!ResponderHelper::ExtractUInt8(request, &arg)) {
263 return NackWithReason(request, NR_FORMAT_ERROR);
266 unsigned int offset = m_settings->Offset();
268 if (arg == 0 || arg >= m_settings->Count() + offset) {
269 return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
271 const SettingType *setting = m_settings->Lookup(arg - offset);
272 uint8_t output[setting->DescriptionResponseSize()];
273 unsigned int size = setting->GenerateDescriptionResponse(arg, output);
274 return GetResponseFromData(request, output, size, RDM_ACK);
278 template <
class SettingType>
279 bool SettingManager<SettingType>::ChangeSetting(uint8_t new_setting) {
280 uint8_t offset = m_settings->Offset();
282 if (new_setting < offset || new_setting >= m_settings->Count() + offset)
285 m_current_setting = new_setting - offset;
290 #endif // INCLUDE_OLA_RDM_RESPONDERSETTINGS_H_