Add support for dimmer curves per E1.37-1 - #1476
Conversation
peternewman
left a comment
There was a problem hiding this comment.
Thanks for this @kecramer ! Some comments, mostly fairly minor.
The blue sky ideal is to rewrite this whole bit to do something dynamic which will hence support all PIDs (including manufacturer ones) by generating JSON schema and a dynamic UI (although it will still need some smarts for linked PIDs like these). It also needs lots of coding, so feel free to keep hacking in quick fix copy/pastes like these where appropriate. The current web UI also unfortunately doesn't support sub-devices, which a lot of dimmers may represent themselves as.
|
|
||
| /* | ||
| * Fetch the dimmer curve | ||
| * @param uid the UID to fetch the DNS domain name for |
|
|
||
| /* | ||
| * Fetch the dimmer curve description (name) | ||
| * @param uid the UID to fetch the DNS domain name for |
| } | ||
|
|
||
| /* | ||
| * Fetch the dimmer curve |
There was a problem hiding this comment.
In theory these, and all the others already in the file should be @brief, but given we haven't enabled any of this as Doxygen for some reason, it doesn't really matter right now. But if you felt like fixing them, that would be awesome 👍
There was a problem hiding this comment.
Is this only for comment blocks with @params after them, or all comment blocks preceding a function call? I can take care of them in one go here.
There was a problem hiding this comment.
Generally if it's only one line we want to tag it as brief because then Doxygen can do some magic and show it in a few more places:
https://www.stack.nl/~dimitri/doxygen/manual/commands.html#cmdbrief
It would be all Doxygen style ones, so if they've already got @param or @return or whatever in there too.
|
|
||
| /* | ||
| * Set the dimmer curve | ||
| * @param uid the UID to set the DNS domain name for |
| * @param error a pointer to a string which it set if an error occurs | ||
| * @return true if the request is sent correctly, false otherwise | ||
| */ | ||
| bool RDMAPI::SetCurve( |
There was a problem hiding this comment.
Order wise, we probably want Get then Set for the same PID, so GetCurve, SetCurve, GetCurveDescription.
| if (i <= info->curves.size()) { | ||
| ostringstream str; | ||
| str << info->curves[i - 1].second << " (" << | ||
| info->curves[i - 1].first << ")"; |
There was a problem hiding this comment.
Can you move the << on the line above to this line and align them.
There was a problem hiding this comment.
You may want to not print the () if the description is empty; I'm not sure what we do elsewhere regarding this.
|
|
||
| section.AddItem(item); | ||
| section.AddItem(new StringItem("Available Curves", | ||
| std::to_string(info->total))); |
There was a problem hiding this comment.
Can you align this with the second ( above please.
| unsigned int active; | ||
| unsigned int next; | ||
| unsigned int total; | ||
| std::vector<std::pair<uint32_t, std::string> > curves; |
| static const char RESET_DEVICE_SECTION[]; | ||
| static const char SENSOR_SECTION[]; | ||
| static const char TILT_INVERT_SECTION[]; | ||
| static const char CURVE_SECTION[]; |
| static const char PROXIED_DEVICES_SECTION_NAME[]; | ||
| static const char RESET_DEVICE_SECTION_NAME[]; | ||
| static const char TILT_INVERT_SECTION_NAME[]; | ||
| static const char CURVE_SECTION_NAME[]; |
|
|
||
| section.AddItem(item); | ||
| section.AddItem(new StringItem("Available Curves", | ||
| std::to_string(info->total))); |
There was a problem hiding this comment.
This still needs converting to our IntToString function.
| } | ||
|
|
||
| info->curves.push_back(pair<uint32_t, string>(curve, description)); | ||
| info->curve_descriptions.push_back(description); |
There was a problem hiding this comment.
So now you've made this change, the curve parameter should now be OLA_UNUSED again!
| for (unsigned int i = 1; i <= info->total; i++) { | ||
| if (i <= info->curves.size()) { | ||
| if (i <= info->curve_descriptions.size() && | ||
| info->curve_descriptions[i - 1].length() > 0) { |
There was a problem hiding this comment.
You can use !.empty() for the string.
| for (unsigned int i = 1; i <= info->total; i++) { | ||
| if (i <= info->curve_descriptions.size() && | ||
| info->curve_descriptions[i - 1].length() > 0) { | ||
| info->curve_descriptions[i - 1].empty() == false) { |
There was a problem hiding this comment.
You can just use:
!info->curve_descriptions[i - 1].empty()
So the total bit is:
if (i <= info->curve_descriptions.size() &&
!info->curve_descriptions[i - 1].empty()) {
Which should be more readable.
There was a problem hiding this comment.
Sure thing, happy to change that. I've found using == false makes it more explicit in my personal coding.
There was a problem hiding this comment.
Yeah I think we generally go for ! rather than == false in the rest of the codebase. Personally the latter makes me do a bit of a double-take.
peternewman
left a comment
There was a problem hiding this comment.
LGTM, just one more minor grammar nit.
| * @param uid the UID to fetch the dimmer curve information for | ||
| * @param sub_device the sub device to use | ||
| * @param callback the callback to invoke when this request completes | ||
| * @param error a pointer to a string which it set if an error occurs |
There was a problem hiding this comment.
I don't know if this typo exists throughout, but it should be "which IS set", can you fix it wherever necessary please.
There was a problem hiding this comment.
Looks like it was present across all the functions. Changed all occurrences in RDMAPI.cpp
Tried to imitate the style and conventions of similar endpoints as best I could.
_HandleU16Response was used in the first iteration of this endpoint, but was no longer necessary when I moved the response to a struct. I left the method there as it seems like it could be useful in the future? It can easily be removed though.