Skip to content

Commit

Permalink
Exaggerate Yaw & Cleanup a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Martouta committed Jun 1, 2020
1 parent 01eb301 commit e56c4e7
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions switch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,34 @@ boolean shouldAccelerate(float freq) {
}

void sendGameData(float freq, float yaw) {
//TODO: Clean Up!

digitalRead(pinButtonR);
digitalRead(pinButtonAdd);
digitalRead(pinButtonA);
digitalRead(pinButtonB);

Joystick.setButton(4, pressOrReleaseValue(pinButtonL)); // L
Joystick.setButton(5, pressOrReleaseValue(pinButtonR)); // R
Joystick.setButton(9, pressOrReleaseValue(pinButtonAdd)); // +
Joystick.setButton(1, pressOrReleaseValue(pinButtonB)); // B
Joystick.setButton(2, (((digitalRead(pinButtonA) == LOW) || shouldAccelerate(freq))) ? 1 : 0); // A


if (freq > 0) { setSteerFromYaw(yaw); }

Joystick.sendState();
}

if (freq > 0) {
// Move
float filteredYaw = yaw;
void setSteerFromYaw(float yaw) {
float filteredYaw = yaw;
if(filteredYaw > 1.57079633) { // > 90 degrees
filteredYaw = 1.57079633;
} else if(filteredYaw < -1.57079633){ // < -90 degrees
filteredYaw = -1.57079633;
}

float exaggeratedYaw = filteredYaw * 1.5;

float u = 128 * sin(filteredYaw),
v = 128 * cos(filteredYaw);
float u = 128 * sin(exaggeratedYaw),
v = 128 * cos(exaggeratedYaw);
int x = 128 + ((int) u),
y = 128 - ((int) v);

Joystick.setXAxis(x);
Joystick.setYAxis(y);
} else {
// Stay in the center
Joystick.setXAxis(128);
Joystick.setYAxis(128);
}



Joystick.sendState();
}

int pressOrReleaseValue(int button) {
Expand Down

0 comments on commit e56c4e7

Please sign in to comment.