Skip to content

Commit

Permalink
Fix rotary edge cases (#19164)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Aug 25, 2023
1 parent 16b1c55 commit 7f24d20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions tasmota/tasmota_support/support_rotary.ino
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ static void IRAM_ATTR RotaryIsrArgMiDesk(void *arg) {
encoder->state = (state >> 2);
}

void IRAM_ATTR RotaryIsrArg(void *arg);
void RotaryIsrArg(void *arg) {
static void IRAM_ATTR RotaryIsrArg(void *arg) {
tEncoder* encoder = static_cast<tEncoder*>(arg);

// Theo Arends
Expand All @@ -146,9 +145,9 @@ void RotaryInitMaxSteps(void) {
}
uint8_t max_steps = Settings->param[P_ROTARY_MAX_STEP];
if (!Rotary.model) { max_steps *= 3; }
Rotary.dimmer_increment = 100 / max_steps; // Dimmer 1..100 = 100
Rotary.ct_increment = 350 / max_steps; // Ct 153..500 = 347
Rotary.color_increment = 360 / max_steps; // Hue 0..359 = 360
Rotary.dimmer_increment = 100 / min((uint8_t)100, max_steps); // Dimmer 1..100 = 100
Rotary.ct_increment = 350 / min((uint8_t)350, max_steps); // Ct 153..500 = 347
Rotary.color_increment = 360 / min((uint8_t)360, max_steps); // Hue 0..359 = 360
}

void RotaryInit(void) {
Expand Down
7 changes: 4 additions & 3 deletions tasmota/tasmota_xdrv_driver/xdrv_04_light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1358,9 +1358,10 @@ void LightColorOffset(int32_t offset) {
uint16_t hue;
uint8_t sat;
light_state.getHSB(&hue, &sat, nullptr); // Allow user control over Saturation
hue += offset;
if (hue < 0) { hue += 359; }
if (hue > 359) { hue -= 359; }
int16_t hue_new = hue + offset;
if (hue_new < 0) { hue_new += 359; }
if (hue_new > 359) { hue_new -= 359; }
hue = hue_new;
if (!Light.pwm_multi_channels) {
light_state.setHS(hue, sat);
} else {
Expand Down

0 comments on commit 7f24d20

Please # to comment.