Skip to content

Commit

Permalink
Added 400 PPR and 360 PPR options
Browse files Browse the repository at this point in the history
  • Loading branch information
veroxzik committed Jul 25, 2020
1 parent 933d3b6 commit 2bb115c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
3 changes: 1 addition & 2 deletions roxy/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ struct config_t {
// Bit 3: LED1 always on
// Bit 4: LED2 always on (not used on Roxy)
// Bit 5: Enable analog knobs
int8_t qe1_sens;
int8_t qe2_sens;
int8_t qe_sens[2];
uint8_t ps2_mode;
uint8_t rgb_mode;
uint8_t rgb_brightness;
Expand Down
40 changes: 20 additions & 20 deletions roxy/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,13 @@ class QEAxis : public Axis {
tim.CR1 = 1;

if(sens < 0) {
// Special case for 600 PPR
// Special cases
if(sens == -127) {
tim.ARR = 2400 - 1;
tim.ARR = (600 * 4) - 1;
} else if(sens == -126) {
tim.ARR = (400 * 4) - 1;
} else if(sens == -125) {
tim.ARR = (360 * 4) - 1;
} else {
tim.ARR = 256 * -sens - 1;
}
Expand Down Expand Up @@ -422,7 +426,7 @@ int main() {
} else {
RCC.enable(RCC.TIM2);

axis_qe1.enable(config.flags & (1 << 1), config.qe1_sens);
axis_qe1.enable(config.flags & (1 << 1), config.qe_sens[0]);

qe1a.set_af(1);
qe1b.set_af(1);
Expand All @@ -444,7 +448,7 @@ int main() {
} else {
RCC.enable(RCC.TIM3);

axis_qe2.enable(config.flags & (1 << 2), config.qe2_sens);
axis_qe2.enable(config.flags & (1 << 2), config.qe_sens[1]);

qe2a.set_af(2);
qe2b.set_af(2);
Expand Down Expand Up @@ -593,22 +597,18 @@ int main() {
} else if(last_axis_state[i] == -1) {
buttons |= axis_buttons[2 * i + 1];
}
}

if(config.qe1_sens == -127) {
qe_count[0] *= (256.0f / 2400.0f);
} else if(config.qe1_sens < 0) {
qe_count[0] /= -config.qe1_sens;
} else if(config.qe1_sens > 0) {
qe_count[0] *= config.qe1_sens;
}

if(config.qe2_sens == -127) {
qe_count[1] *= (256.0f / 2400.0f);
} else if(config.qe2_sens < 0) {
qe_count[1] /= -config.qe2_sens;
} else if(config.qe2_sens > 0) {
qe_count[1] *= config.qe2_sens;

if(config.qe_sens[i] == -127) {
qe_count[i] *= (256.0f / (600.0f * 4.0f));
} else if(config.qe_sens[i] == -126) {
qe_count[i] *= (256.0f / (400.0f * 4.0f));
} else if(config.qe_sens[i] == -125) {
qe_count[i] *= (256.0f / (360.0f * 4.0f));
} else if(config.qe_sens[i] < 0) {
qe_count[i] /= -config.qe_sens[i];
} else if(config.qe_sens[i] > 0) {
qe_count[i] *= config.qe_sens[i];
}
}

input_report_t report = {1, buttons, uint8_t(qe_count[0]), uint8_t(qe_count[1])};
Expand Down

0 comments on commit 2bb115c

Please sign in to comment.