Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lights: fix broken unsigned arithmetic + refactoring #1938

Merged
merged 7 commits into from
Oct 9, 2019

Conversation

mcspr
Copy link
Collaborator

@mcspr mcspr commented Oct 9, 2019

  • replace unsigned return values with the signed ones to avoid undefined behaviour when mixing signed and unsigned in one expression or accidentally casting negative values to unsigned (like lightBrightness(...), lightChannel(id, ...), causing value to become 100% when the intent was to set it to 0%)
  • update encoder configure method to only configure encoder objects once, on boot. should be cleaned-up anyway for runtime pin config, either requiring reboot re-using existing objects when nothing had changed.
    fixes Xiaomi Desklamp Rotary Encoder Bugs #1934

some related changes

  • clean-up adjustment code for terminal, reuse same code for mqtt and http api
  • clean-up lights code casting const char * back to char * when parsing using strtok, use local stack buffer with memmove strncpy
  • update toCSV to use the same logic as the other methods, slightly smaller code size. and a small fix for mqtt groups never allowing values to increase (should be properly fixed later with brightness sent separately and maybe the same settings as relay groups)
  • update comms masks usage, move hardcoded values to the header as named variables
  • move declarations outside of the prototypes header

@mcspr mcspr force-pushed the light/unsigned-signed-kerf branch from bb93691 to ab0fcb4 Compare October 9, 2019 19:38
@mcspr mcspr merged commit cf4540a into xoseperez:dev Oct 9, 2019
@mcspr mcspr deleted the light/unsigned-signed-kerf branch October 9, 2019 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Xiaomi Desklamp Rotary Encoder Bugs
1 participant