@@ -39,6 +39,15 @@ long loop_start_time = 0;
39
39
// / Holds the expected end time of the current program loop.
40
40
long loop_end_time = 0 ;
41
41
42
+ // / Defines the rotary encoder object for the 2.0 boards
43
+ AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(
44
+ ROTARY_ENCODER_A_PIN,
45
+ ROTARY_ENCODER_B_PIN,
46
+ ROTARY_ENCODER_BUTTON_PIN,
47
+ ROTARY_ENCODER_VCC_PIN,
48
+ ROTARY_ENCODER_STEPS
49
+ );
50
+
42
51
/* ***********************************************
43
52
*
44
53
* HELPERS:
@@ -271,28 +280,28 @@ long timer_overrun(){
271
280
return (millis () < loop_end_time) ? 0 : millis () - loop_end_time + 1 ;
272
281
}
273
282
274
- AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);
275
-
283
+ // / @brief Processes the interrupt for the rotary encoder on 2.0 hardware
276
284
void IRAM_ATTR readEncoderISR (){
277
285
rotaryEncoder.readEncoder_ISR ();
278
286
}
279
287
288
+ // / @brief Performs initial setup for the rotary encoder
280
289
void setup_rotary_encoder (){
281
290
rotaryEncoder.begin ();
282
291
rotaryEncoder.setup (readEncoderISR);
283
292
rotaryEncoder.setBoundaries (0 , 1000 , true ); // minValue, maxValue, circleValues true|false (when max go to min and vice versa)
284
293
rotaryEncoder.setAcceleration (250 );
285
294
}
286
- int calculate_pattern_index (){
287
- int index = static_cast <int >(floor (rotaryEncoder.readEncoder () / ROTARY_ENCODER_STEPS)) % NUM_PATTERNS;
288
295
289
- return index ;
296
+ // / @brief Calculates the pattern index the rotary encoder currently
297
+ // / corresponds to.
298
+ // / @returns The pattern index the encoder is set to.
299
+ int calculate_pattern_index (){
300
+ return static_cast <int >(floor (rotaryEncoder.readEncoder () / ROTARY_ENCODER_STEPS)) % NUM_PATTERNS;
290
301
}
291
302
303
+ // / @brief Returns the current state of the rotary encoder button.
304
+ // / @returns True if pressed, false if not.
292
305
bool isEncoderButtonPressed (){
293
306
return rotaryEncoder.isEncoderButtonClicked ();
294
- }
295
-
296
- bool isEncoderBtnDown () {
297
- return rotaryEncoder.isEncoderButtonDown ();
298
307
}
0 commit comments