new aproach for deactivating generators, not finshed yet
This commit is contained in:
38
main/GPIO.c
38
main/GPIO.c
@@ -18,18 +18,14 @@ static volatile int64_t last_AB_time = 0;
|
||||
|
||||
|
||||
//internal Encoder
|
||||
static void IRAM_ATTR enc_in_a_isr_handler(void *arg);
|
||||
static void IRAM_ATTR enc_in_b_isr_handler(void *arg);
|
||||
static void IRAM_ATTR enc_in_isr_handler(void *arg);
|
||||
static void IRAM_ATTR enc_in_but_isr_handler(void *arg);
|
||||
|
||||
static volatile int16_t enc_in_counter = 0;
|
||||
static volatile int64_t last_interrupt_time_a = 0; // Entprellungs-Timer
|
||||
static volatile int64_t last_interrupt_time_b = 0; // Entprellungs-Timer
|
||||
static volatile int64_t last_interrupt_time = 0;
|
||||
static volatile uint16_t last_interrupt_time_but = 0;
|
||||
static volatile bool enc_in_button_state = false;
|
||||
|
||||
static volatile uint8_t last_state = 0;
|
||||
|
||||
/*############################################*/
|
||||
/*############### GPIO-Setup #################*/
|
||||
@@ -163,35 +159,7 @@ int get_direction(){//-1=Error,0=right,1=left
|
||||
/*############################################*/
|
||||
/*############ Internal Encoder ##############*/
|
||||
/*############################################*/
|
||||
static void IRAM_ATTR enc_in_a_isr_handler(void *arg) {
|
||||
uint64_t interrupt_time = esp_timer_get_time();
|
||||
|
||||
// Entprellung: Verhindert die Erfassung von Störungen aufgrund von Prellung
|
||||
if (interrupt_time - last_interrupt_time_a > (CONFIG_IN_ENCODER_DEBOUNCE_TIME)) { // Entprellungszeit
|
||||
last_interrupt_time_a = interrupt_time; // Entprellzeit zurücksetzen
|
||||
// Bestimmen der Richtung anhand des Zustands von Pin A und B
|
||||
if (gpio_get_level(CONFIG_IN_ENC_A_GPIO)==gpio_get_level(CONFIG_IN_ENC_B_GPIO)) {
|
||||
enc_in_counter++; // Drehung nach links
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void IRAM_ATTR enc_in_b_isr_handler(void *arg) {
|
||||
uint64_t interrupt_time = esp_timer_get_time();
|
||||
|
||||
// Entprellung: Verhindert die Erfassung von Störungen aufgrund von Prellung
|
||||
if (interrupt_time - last_interrupt_time_b > (CONFIG_IN_ENCODER_DEBOUNCE_TIME)) { // Entprellungszeit
|
||||
last_interrupt_time_b = interrupt_time; // Entprellzeit zurücksetzen
|
||||
// Bestimmen der Richtung anhand des Zustands von Pin A und B
|
||||
if (gpio_get_level(CONFIG_IN_ENC_A_GPIO)==gpio_get_level(CONFIG_IN_ENC_B_GPIO)) {
|
||||
enc_in_counter--;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static volatile uint8_t last_state = 0;
|
||||
|
||||
static void IRAM_ATTR enc_in_isr_handler(void *arg) {
|
||||
static uint64_t last_interrupt_time = 0;
|
||||
@@ -206,10 +174,10 @@ static void IRAM_ATTR enc_in_isr_handler(void *arg) {
|
||||
if ((interrupt_time - last_interrupt_time) > CONFIG_IN_ENCODER_DEBOUNCE_TIME) {
|
||||
if ((last_state == 0b01 && current_state == 0b11) ||
|
||||
(last_state == 0b10 && current_state == 0b00)) {
|
||||
enc_in_counter++; // Vorwärtsdrehen
|
||||
enc_in_counter--; // Vorwärtsdrehen
|
||||
} else if ((last_state == 0b10 && current_state == 0b11) ||
|
||||
(last_state == 0b01 && current_state == 0b00)) {
|
||||
enc_in_counter--; // Rückwärtsdrehen
|
||||
enc_in_counter++; // Rückwärtsdrehen
|
||||
}
|
||||
last_state = current_state; // Zustand aktualisieren
|
||||
last_interrupt_time = interrupt_time;
|
||||
|
||||
Reference in New Issue
Block a user