50 lines
1.0 KiB
C++
50 lines
1.0 KiB
C++
#include "encoder.h"
|
|
|
|
#include <Arduino.h>
|
|
#include <FreeRTOS_SAMD21.h>
|
|
#include <Versatile_RotaryEncoder.h>
|
|
|
|
#include "main.h"
|
|
#include "mapping.h"
|
|
#include "priority.h"
|
|
#include "spinner.h"
|
|
#include "util.h"
|
|
|
|
void handle_press();
|
|
void handle_rotate(int8_t rotation);
|
|
void encoder_task(void *pvParameters);
|
|
|
|
TaskHandle_t encoder_task_handle;
|
|
|
|
Versatile_RotaryEncoder *encoder;
|
|
|
|
void setup_encoder() {
|
|
encoder = new Versatile_RotaryEncoder(ENCODER_PIN_CLK, ENCODER_PIN_DT, ENCODER_PIN_SW);
|
|
encoder->setHandlePress(handle_press);
|
|
encoder->setHandleRotate(handle_rotate);
|
|
|
|
xTaskCreate(encoder_task, "encoder_task", 64, NULL, ENCODER_PRIORITY, &encoder_task_handle);
|
|
}
|
|
|
|
void encoder_task(void *pvParameters) {
|
|
for(;;) {
|
|
encoder->ReadEncoder();
|
|
delay_ms(10);
|
|
}
|
|
}
|
|
|
|
void handle_press() {
|
|
Serial.println("Pressed");
|
|
next_main_menu_item();
|
|
}
|
|
|
|
void handle_rotate(int8_t rotation) {
|
|
Serial.println("Rotated");
|
|
rotation = -rotation;
|
|
if (rotation > 0) {
|
|
next_meter();
|
|
} else if (rotation < 0) {
|
|
previous_meter();
|
|
}
|
|
update_fader(rotation);
|
|
} |