Encoder: Move handling encoder events to main
parent
efc318c99a
commit
771c135cd2
|
@ -1,6 +1,7 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "encoder.h"
|
||||
|
||||
/*
|
||||
|
||||
|
@ -14,16 +15,6 @@ When rotated clockwise, CLK changes before DT; when rotated counter-clockwise, D
|
|||
|
||||
#define SW_DEBOUNCE_MS 10
|
||||
|
||||
typedef uint8_t SwitchEvent;
|
||||
#define SWITCH_NONE 0
|
||||
#define SWITCH_PRESSED 1
|
||||
#define SWITCH_RELEASED 2
|
||||
|
||||
typedef int8_t EncoderEvent;
|
||||
#define ENCODER_NONE 0
|
||||
#define ENCODER_CLOCKWISE 1
|
||||
#define ENCODER_COUNTER_CLOCKWISE -1
|
||||
|
||||
bool previousClk = false;
|
||||
bool previousDt = false;
|
||||
|
||||
|
@ -37,19 +28,6 @@ void setupEncoder() {
|
|||
previousDt = digitalRead(DT_PIN);
|
||||
}
|
||||
|
||||
SwitchEvent handleSwitch();
|
||||
EncoderEvent handleEncoder();
|
||||
|
||||
void demoEncoder() {
|
||||
if (auto event = handleSwitch()) {
|
||||
Serial.println(event == SWITCH_PRESSED ? "Pressed" : "Released");
|
||||
}
|
||||
|
||||
if (auto event = handleEncoder()) {
|
||||
Serial.println(event == ENCODER_CLOCKWISE ? "Clockwise" : "Counter-clockwise");
|
||||
}
|
||||
}
|
||||
|
||||
bool previousPressed = false;
|
||||
unsigned long lastChangeAt = 0;
|
||||
|
||||
|
|
|
@ -1,4 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
typedef uint8_t SwitchEvent;
|
||||
#define SWITCH_NONE 0
|
||||
#define SWITCH_PRESSED 1
|
||||
#define SWITCH_RELEASED 2
|
||||
|
||||
typedef int8_t EncoderEvent;
|
||||
#define ENCODER_NONE 0
|
||||
#define ENCODER_CLOCKWISE 1
|
||||
#define ENCODER_COUNTER_CLOCKWISE -1
|
||||
|
||||
void setupEncoder();
|
||||
void demoEncoder();
|
||||
|
||||
SwitchEvent handleSwitch();
|
||||
EncoderEvent handleEncoder();
|
||||
|
|
|
@ -22,12 +22,19 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
tick();
|
||||
// tick();
|
||||
|
||||
debugScanI2C();
|
||||
demoScreen();
|
||||
// debugScanI2C();
|
||||
// demoScreen();
|
||||
// demoKeyboard();
|
||||
// demoEncoder();
|
||||
|
||||
delay(200);
|
||||
if (auto event = handleSwitch()) {
|
||||
tick();
|
||||
Serial.println(event == SWITCH_PRESSED ? "Pressed" : "Released");
|
||||
}
|
||||
|
||||
if (auto event = handleEncoder()) {
|
||||
tick();
|
||||
Serial.println(event == ENCODER_CLOCKWISE ? "Clockwise" : "Counter-clockwise");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue