Skip to content

Commit f1e0067

Browse files
committed
Add update limiter to HandbrakeJoystick
Matching the behavior of the pedal position limiter, this only sends data whenever the handbrake position changes. It can be overridden with the "AlwaysSend" option.
1 parent f1724af commit f1e0067

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

examples/Handbrake/HandbrakeJoystick/HandbrakeJoystick.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Joystick_ Joystick(
4545
false, false, false, false, false, false, false, false); // no other axes
4646

4747
const int ADC_Max = 1023; // max value of the analog inputs, 10-bit on AVR boards
48+
const bool AlwaysSend = false; // override the position checks, *always* send data constantly
4849

4950

5051
void setup() {
@@ -53,13 +54,20 @@ void setup() {
5354
// if you have one, your calibration line should go here
5455

5556
Joystick.begin(false); // 'false' to disable auto-send
56-
5757
Joystick.setZAxisRange(0, ADC_Max);
58+
59+
updateJoystick(); // send initial state
5860
}
5961

6062
void loop() {
6163
handbrake.update();
6264

65+
if (handbrake.positionChanged() || AlwaysSend) {
66+
updateJoystick();
67+
}
68+
}
69+
70+
void updateJoystick() {
6371
int pos = handbrake.getPosition(0, ADC_Max);
6472
Joystick.setZAxis(pos);
6573

0 commit comments

Comments
 (0)