Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/AudioThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <AudioOutputI2S.h>
#include <ESP8266SAM.h>

#ifdef USE_XL9555
#include "ExtensionIOXL9555.hpp"
extern ExtensionIOXL9555 io;
#endif

#define AUDIO_THREAD_INTERVAL_MS 100

class AudioThread : public concurrency::OSThread
Expand All @@ -20,6 +25,9 @@ class AudioThread : public concurrency::OSThread

void beginRttl(const void *data, uint32_t len)
{
#ifdef USE_XL9555
Comment thread
WillyJL marked this conversation as resolved.
Outdated
io.digitalWrite(EXPANDS_AMP_EN, HIGH);
#endif
setCPUFast(true);
rtttlFile = new AudioFileSourcePROGMEM(data, len);
i2sRtttl = new AudioGeneratorRTTTL();
Expand All @@ -45,6 +53,9 @@ class AudioThread : public concurrency::OSThread
rtttlFile = nullptr;

setCPUFast(false);
#ifdef USE_XL9555
io.digitalWrite(EXPANDS_AMP_EN, LOW);
#endif
}

void readAloud(const char *text)
Expand All @@ -55,10 +66,16 @@ class AudioThread : public concurrency::OSThread
i2sRtttl = nullptr;
}

#ifdef USE_XL9555
io.digitalWrite(EXPANDS_AMP_EN, HIGH);
#endif
ESP8266SAM *sam = new ESP8266SAM;
sam->Say(audioOut, text);
delete sam;
setCPUFast(false);
#ifdef USE_XL9555
io.digitalWrite(EXPANDS_AMP_EN, LOW);
#endif
}

protected:
Expand Down
65 changes: 46 additions & 19 deletions src/input/RotaryEncoderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#define ORIGIN_NAME "RotaryEncoder"

#define ROTARY_INTERRUPT_FLAG _BV(0)

RotaryEncoderImpl *rotaryEncoderImpl;

RotaryEncoderImpl::RotaryEncoderImpl() : concurrency::OSThread(ORIGIN_NAME), originName(ORIGIN_NAME)
Expand All @@ -30,6 +32,17 @@ bool RotaryEncoderImpl::init()
moduleConfig.canned_message.inputbroker_pin_press);
rotary->resetButton();

inputQueue = xQueueCreate(5, sizeof(input_broker_event));
interruptFlag = xEventGroupCreate();
interruptInstance = this;
auto interruptHandler = []() {
xEventGroupSetBits(interruptInstance->interruptFlag, ROTARY_INTERRUPT_FLAG);
};
attachInterrupt(moduleConfig.canned_message.inputbroker_pin_a, interruptHandler, CHANGE);
attachInterrupt(moduleConfig.canned_message.inputbroker_pin_b, interruptHandler, CHANGE);
attachInterrupt(moduleConfig.canned_message.inputbroker_pin_press, interruptHandler, CHANGE);
xTaskCreate(inputWorker, "rotary", 2 * 1024, this, 10, &inputWorkerTask);

inputBroker->registerSource(this);

LOG_INFO("RotaryEncoder initialized pins(%d, %d, %d), events(%d, %d, %d)", moduleConfig.canned_message.inputbroker_pin_a,
Expand All @@ -38,35 +51,49 @@ bool RotaryEncoderImpl::init()
return true;
}

int32_t RotaryEncoderImpl::runOnce()
void RotaryEncoderImpl::dispatchInputs()
{
InputEvent e{originName, INPUT_BROKER_NONE, 0, 0, 0};
static uint32_t lastPressed = millis();
if (rotary->readButton() == RotaryEncoder::ButtonState::BUTTON_PRESSED) {
if (lastPressed + 200 < millis()) {
LOG_DEBUG("Rotary event Press");
// LOG_DEBUG("Rotary event Press");
lastPressed = millis();
e.inputEvent = this->eventPressed;
}
} else {
switch (rotary->process()) {
case RotaryEncoder::DIRECTION_CW:
LOG_DEBUG("Rotary event CW");
e.inputEvent = this->eventCw;
break;
case RotaryEncoder::DIRECTION_CCW:
LOG_DEBUG("Rotary event CCW");
e.inputEvent = this->eventCcw;
break;
default:
break;
xQueueSend(inputQueue, &this->eventPressed, portMAX_DELAY);
}
}

if (e.inputEvent != INPUT_BROKER_NONE) {
this->notifyObservers(&e);
switch (rotary->process()) {
case RotaryEncoder::DIRECTION_CW:
// LOG_DEBUG("Rotary event CW");
xQueueSend(inputQueue, &this->eventCw, portMAX_DELAY);
break;
case RotaryEncoder::DIRECTION_CCW:
// LOG_DEBUG("Rotary event CCW");
xQueueSend(inputQueue, &this->eventCcw, portMAX_DELAY);
break;
default:
break;
}
}

void RotaryEncoderImpl::inputWorker(void *p)
{
RotaryEncoderImpl* instance = (RotaryEncoderImpl*)p;
while (true) {
xEventGroupWaitBits(instance->interruptFlag, ROTARY_INTERRUPT_FLAG, pdTRUE, pdTRUE, portMAX_DELAY);
instance->dispatchInputs();
}
vTaskDelete(NULL);
}

RotaryEncoderImpl* RotaryEncoderImpl::interruptInstance;

int32_t RotaryEncoderImpl::runOnce()
{
InputEvent e{originName, INPUT_BROKER_NONE, 0, 0, 0};
while(xQueueReceive(inputQueue, &e.inputEvent, 0) == pdPASS) {
this->notifyObservers(&e);
}
return 10;
}

Expand Down
13 changes: 12 additions & 1 deletion src/input/RotaryEncoderImpl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

// This is a non-interrupt version of RotaryEncoder which is based on a debounce inherent FSM table (see RotaryEncoder library)
#ifdef T_LORA_PAGER

// This is a version of RotaryEncoder which is based on a debounce inherent FSM table (see RotaryEncoder library)

#include "InputBroker.h"
#include "concurrency/OSThread.h"
Expand All @@ -17,6 +19,13 @@ class RotaryEncoderImpl : public Observable<const InputEvent *>, public concurre
protected:
virtual int32_t runOnce() override;

QueueHandle_t inputQueue;
void dispatchInputs(void);
TaskHandle_t inputWorkerTask;
static void inputWorker(void *p);
EventGroupHandle_t interruptFlag;
static RotaryEncoderImpl* interruptInstance;

input_broker_event eventCw = INPUT_BROKER_NONE;
input_broker_event eventCcw = INPUT_BROKER_NONE;
input_broker_event eventPressed = INPUT_BROKER_NONE;
Expand All @@ -26,3 +35,5 @@ class RotaryEncoderImpl : public Observable<const InputEvent *>, public concurre
};

extern RotaryEncoderImpl *rotaryEncoderImpl;

#endif
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void setup()
io.pinMode(EXPANDS_DRV_EN, OUTPUT);
io.digitalWrite(EXPANDS_DRV_EN, HIGH);
io.pinMode(EXPANDS_AMP_EN, OUTPUT);
io.digitalWrite(EXPANDS_AMP_EN, HIGH);
io.digitalWrite(EXPANDS_AMP_EN, LOW);
io.pinMode(EXPANDS_LORA_EN, OUTPUT);
io.digitalWrite(EXPANDS_LORA_EN, HIGH);
io.pinMode(EXPANDS_GPS_EN, OUTPUT);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/Modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "buzz/BuzzerFeedbackThread.h"
#include "input/ExpressLRSFiveWay.h"
#include "input/InputBroker.h"
#ifdef T_LORA_PAGER
#include "input/RotaryEncoderImpl.h"
#endif
#include "input/RotaryEncoderInterruptImpl1.h"
#include "input/SerialKeyboardImpl.h"
#include "input/UpDownInterruptImpl1.h"
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32s3/tlora-pager/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build_flags = ${esp32s3_base.build_flags}
-D SDCARD_USE_SPI1
-D ENABLE_ROTARY_PULLUP
-D ENABLE_BUTTON_PULLUP
-D HALF_STEP
-D ROTARY_BUXTRONICS

lib_deps = ${esp32s3_base.lib_deps}
lovyan03/LovyanGFX@1.2.7
Expand All @@ -26,7 +26,7 @@ lib_deps = ${esp32s3_base.lib_deps}
lewisxhe/SensorLib@0.3.1
https://github.com/pschatzmann/arduino-audio-driver/archive/refs/tags/v0.1.3.zip
https://github.com/mverch67/BQ27220/archive/07d92be846abd8a0258a50c23198dac0858b22ed.zip
https://github.com/mverch67/RotaryEncoder/archive/25a59d5745a6645536f921427d80b08e78f886d4.zip
https://github.com/mverch67/RotaryEncoder/archive/da958a21389cbcd485989705df602a33e092dd88.zip

[env:tlora-pager-tft]
board_level = extra
Expand Down
Loading