mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-19 03:13:14 +00:00
## Launcher - Launcher now has optional power button to show - Launcher layout improvements - Removed text from Launcher (translations with larger amounts of text did not fit small device formats) ## T-Lora Pager - Implement power off (created `BQ25896` driver) - Implemented haptics (created `DRV2605` driver project) and buzz on startup - Reversed scroll wheel - Created `TloraEncoder` device and relocated its logic from `TloraKeyboard` - Disabled SPIRAM test to save 0.5 seconds of boot time (current boot time is very slow) - Update `ST7796` esp_lcd driver to v1.3.4 - Fixed keyboard bug: delete queue in destructor - Fixed driver dependencies: Avoiding usage of global static shared_ptr. Properly constructor-inject everywhere, or use `tt::hal::findDevices()` - I2C configuration is now immutable (you cannot disable it anymore from the I2C Settings app, as it would break crucial drivers) - Renamed I2C and UART subsystems to "Internal" ## Drivers - On/off interface added to `PowerDevice` - Created `tt::hal::Configuration.createDevices`, which is intended to replace all custom create calls for display, keyboard, etc. - Created `EncoderDevice` as a `Device` subtype ## Other Improvements - Changed `findDevices(type, function)` into a templatized function. - Improved SD card mounting ## Fixes - Show Screenshot app again - Fixed Statusbar: some updates were allowed to time out and fail silently: When the Statusbar service would do a state update, the LVGL statusbar would never get updated due to this timeout. - Fixed memory leaks in all `createSdCard()` functions (in most board implementations)
142 lines
4.5 KiB
C++
142 lines
4.5 KiB
C++
#include "TpagerEncoder.h"
|
|
|
|
#include <Tactility/Log.h>
|
|
#include <Tactility/hal/Gpio.h>
|
|
|
|
constexpr auto* TAG = "TpagerEncoder";
|
|
constexpr auto ENCODER_A = GPIO_NUM_40;
|
|
constexpr auto ENCODER_B = GPIO_NUM_41;
|
|
constexpr auto ENCODER_ENTER = GPIO_NUM_7;
|
|
|
|
void TpagerEncoder::readCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
|
TpagerEncoder* encoder = static_cast<TpagerEncoder*>(lv_indev_get_user_data(indev));
|
|
constexpr int enter_filter_threshold = 2;
|
|
static int enter_filter = 0;
|
|
constexpr int pulses_click = 4;
|
|
static int pulses_prev = 0;
|
|
|
|
// Defaults
|
|
data->enc_diff = 0;
|
|
data->state = LV_INDEV_STATE_RELEASED;
|
|
|
|
int pulses = encoder->getEncoderPulses();
|
|
int pulse_diff = (pulses - pulses_prev);
|
|
if ((pulse_diff > pulses_click) || (pulse_diff < -pulses_click)) {
|
|
data->enc_diff = pulse_diff / pulses_click;
|
|
pulses_prev = pulses;
|
|
}
|
|
|
|
bool enter = !gpio_get_level(ENCODER_ENTER);
|
|
if (enter && (enter_filter < enter_filter_threshold)) {
|
|
enter_filter++;
|
|
}
|
|
if (!enter && (enter_filter > 0)) {
|
|
enter_filter--;
|
|
}
|
|
|
|
if (enter_filter == enter_filter_threshold) {
|
|
data->state = LV_INDEV_STATE_PRESSED;
|
|
}
|
|
}
|
|
|
|
void TpagerEncoder::initEncoder() {
|
|
constexpr int LOW_LIMIT = -127;
|
|
constexpr int HIGH_LIMIT = 126;
|
|
|
|
// Accum. count makes it that over- and underflows are automatically compensated.
|
|
// Prerequisite: watchpoints at low and high limit
|
|
pcnt_unit_config_t unit_config = {
|
|
.low_limit = LOW_LIMIT,
|
|
.high_limit = HIGH_LIMIT,
|
|
.flags = {.accum_count = 1},
|
|
};
|
|
|
|
if (pcnt_new_unit(&unit_config, &encPcntUnit) != ESP_OK) {
|
|
TT_LOG_E(TAG, "Pulsecounter intialization failed");
|
|
}
|
|
|
|
pcnt_glitch_filter_config_t filter_config = {
|
|
.max_glitch_ns = 1000,
|
|
};
|
|
|
|
if (pcnt_unit_set_glitch_filter(encPcntUnit, &filter_config) != ESP_OK) {
|
|
TT_LOG_E(TAG, "Pulsecounter glitch filter config failed");
|
|
}
|
|
|
|
pcnt_chan_config_t chan_1_config = {
|
|
.edge_gpio_num = ENCODER_B,
|
|
.level_gpio_num = ENCODER_A,
|
|
};
|
|
|
|
pcnt_chan_config_t chan_2_config = {
|
|
.edge_gpio_num = ENCODER_A,
|
|
.level_gpio_num = ENCODER_B,
|
|
};
|
|
|
|
pcnt_channel_handle_t pcnt_chan_1 = nullptr;
|
|
pcnt_channel_handle_t pcnt_chan_2 = nullptr;
|
|
|
|
if ((pcnt_new_channel(encPcntUnit, &chan_1_config, &pcnt_chan_1) != ESP_OK) ||
|
|
(pcnt_new_channel(encPcntUnit, &chan_2_config, &pcnt_chan_2) != ESP_OK)) {
|
|
TT_LOG_E(TAG, "Pulsecounter channel config failed");
|
|
}
|
|
|
|
// Second argument is rising edge, third argument is falling edge
|
|
if ((pcnt_channel_set_edge_action(pcnt_chan_1, PCNT_CHANNEL_EDGE_ACTION_DECREASE, PCNT_CHANNEL_EDGE_ACTION_INCREASE) != ESP_OK) ||
|
|
(pcnt_channel_set_edge_action(pcnt_chan_2, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_DECREASE) != ESP_OK)) {
|
|
TT_LOG_E(TAG, "Pulsecounter edge action config failed");
|
|
}
|
|
|
|
// Second argument is low level, third argument is high level
|
|
if ((pcnt_channel_set_level_action(pcnt_chan_1, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_INVERSE) != ESP_OK) ||
|
|
(pcnt_channel_set_level_action(pcnt_chan_2, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_INVERSE) != ESP_OK)) {
|
|
TT_LOG_E(TAG, "Pulsecounter level action config failed");
|
|
}
|
|
|
|
if ((pcnt_unit_add_watch_point(encPcntUnit, LOW_LIMIT) != ESP_OK) ||
|
|
(pcnt_unit_add_watch_point(encPcntUnit, HIGH_LIMIT) != ESP_OK)) {
|
|
TT_LOG_E(TAG, "Pulsecounter watch point config failed");
|
|
}
|
|
|
|
if (pcnt_unit_enable(encPcntUnit) != ESP_OK) {
|
|
TT_LOG_E(TAG, "Pulsecounter could not be enabled");
|
|
}
|
|
|
|
if (pcnt_unit_clear_count(encPcntUnit) != ESP_OK) {
|
|
TT_LOG_E(TAG, "Pulsecounter could not be cleared");
|
|
}
|
|
|
|
if (pcnt_unit_start(encPcntUnit) != ESP_OK) {
|
|
TT_LOG_E(TAG, "Pulsecounter could not be started");
|
|
}
|
|
}
|
|
|
|
int TpagerEncoder::getEncoderPulses() {
|
|
int pulses = 0;
|
|
pcnt_unit_get_count(encPcntUnit, &pulses);
|
|
return pulses;
|
|
}
|
|
|
|
|
|
bool TpagerEncoder::startLvgl(lv_display_t* display) {
|
|
initEncoder();
|
|
|
|
gpio_input_enable(ENCODER_ENTER);
|
|
|
|
encHandle = lv_indev_create();
|
|
|
|
lv_indev_set_type(encHandle, LV_INDEV_TYPE_ENCODER);
|
|
lv_indev_set_read_cb(encHandle, &readCallback);
|
|
lv_indev_set_display(encHandle, display);
|
|
lv_indev_set_user_data(encHandle, this);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TpagerEncoder::stopLvgl() {
|
|
lv_indev_delete(encHandle);
|
|
encHandle = nullptr;
|
|
|
|
return true;
|
|
}
|