Merge develop into main (#307)
## 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)
This commit is contained in:
committed by
GitHub
parent
e9f72490fc
commit
50007ea9ed
@@ -0,0 +1,141 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/encoder/EncoderDevice.h>
|
||||
#include <driver/pulse_cnt.h>
|
||||
|
||||
class TpagerEncoder final : public tt::hal::encoder::EncoderDevice {
|
||||
|
||||
lv_indev_t* _Nullable encHandle = nullptr;
|
||||
pcnt_unit_handle_t encPcntUnit = nullptr;
|
||||
|
||||
void initEncoder();
|
||||
|
||||
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
|
||||
|
||||
public:
|
||||
|
||||
TpagerEncoder() {}
|
||||
~TpagerEncoder() {}
|
||||
|
||||
std::string getName() const override { return "T-Lora Pager Encoder"; }
|
||||
std::string getDescription() const override { return "The encoder wheel next to the display"; }
|
||||
|
||||
bool startLvgl(lv_display_t* display) override;
|
||||
bool stopLvgl() override;
|
||||
|
||||
int getEncoderPulses();
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return encHandle; }
|
||||
};
|
||||
@@ -7,15 +7,12 @@
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#define TAG "tpager_keyboard"
|
||||
constexpr auto* TAG = "TpagerKeyboard";
|
||||
|
||||
#define ENCODER_A GPIO_NUM_40
|
||||
#define ENCODER_B GPIO_NUM_41
|
||||
#define ENCODER_ENTER GPIO_NUM_7
|
||||
#define BACKLIGHT GPIO_NUM_46
|
||||
constexpr auto BACKLIGHT = GPIO_NUM_46;
|
||||
|
||||
#define KB_ROWS 4
|
||||
#define KB_COLS 11
|
||||
constexpr auto KB_ROWS = 4;
|
||||
constexpr auto KB_COLS = 11;
|
||||
|
||||
// Lowercase Keymap
|
||||
static constexpr char keymap_lc[KB_ROWS][KB_COLS] = {
|
||||
@@ -41,58 +38,16 @@ static constexpr char keymap_sy[KB_ROWS][KB_COLS] = {
|
||||
{'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
|
||||
};
|
||||
|
||||
static QueueHandle_t keyboardMsg;
|
||||
|
||||
static void keyboard_read_callback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
TpagerKeyboard* kb = (TpagerKeyboard*)lv_indev_get_user_data(indev);
|
||||
static bool enter_prev = false;
|
||||
void TpagerKeyboard::readCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
auto keyboard = static_cast<TpagerKeyboard*>(lv_indev_get_user_data(indev));
|
||||
char keypress = 0;
|
||||
|
||||
// Defaults
|
||||
data->key = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
if (xQueueReceive(keyboardMsg, &keypress, pdMS_TO_TICKS(50)) == pdPASS) {
|
||||
if (xQueueReceive(keyboard->queue, &keypress, pdMS_TO_TICKS(50)) == pdPASS) {
|
||||
data->key = keypress;
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
}
|
||||
}
|
||||
|
||||
static void encoder_read_callback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
TpagerKeyboard* kb = (TpagerKeyboard*)lv_indev_get_user_data(indev);
|
||||
const int enter_filter_threshold = 2;
|
||||
static int enter_filter = 0;
|
||||
const int pulses_click = 4;
|
||||
static int pulses_prev = 0;
|
||||
bool anyinput = false;
|
||||
|
||||
// Defaults
|
||||
data->enc_diff = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
int pulses = kb->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;
|
||||
anyinput = true;
|
||||
}
|
||||
|
||||
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;
|
||||
anyinput = true;
|
||||
}
|
||||
|
||||
if (anyinput) {
|
||||
kb->makeBacklightImpulse();
|
||||
} else {
|
||||
data->key = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +91,7 @@ void TpagerKeyboard::processKeyboard() {
|
||||
chr = keymap_lc[row][col];
|
||||
}
|
||||
|
||||
if (chr != '\0') xQueueSend(keyboardMsg, (void*)&chr, portMAX_DELAY);
|
||||
if (chr != '\0') xQueueSend(queue, &chr, portMAX_DELAY);
|
||||
}
|
||||
|
||||
for (int i = 0; i < keypad->released_key_count; i++) {
|
||||
@@ -163,9 +118,7 @@ void TpagerKeyboard::processKeyboard() {
|
||||
|
||||
bool TpagerKeyboard::startLvgl(lv_display_t* display) {
|
||||
backlightOkay = initBacklight(BACKLIGHT, 30000, LEDC_TIMER_0, LEDC_CHANNEL_1);
|
||||
initEncoder();
|
||||
keypad->init(KB_ROWS, KB_COLS);
|
||||
gpio_input_enable(ENCODER_ENTER);
|
||||
|
||||
assert(inputTimer == nullptr);
|
||||
inputTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, [this] {
|
||||
@@ -174,21 +127,15 @@ bool TpagerKeyboard::startLvgl(lv_display_t* display) {
|
||||
|
||||
assert(backlightImpulseTimer == nullptr);
|
||||
backlightImpulseTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, [this] {
|
||||
processBacklightImpuse();
|
||||
processBacklightImpulse();
|
||||
});
|
||||
|
||||
kbHandle = lv_indev_create();
|
||||
lv_indev_set_type(kbHandle, LV_INDEV_TYPE_KEYPAD);
|
||||
lv_indev_set_read_cb(kbHandle, &keyboard_read_callback);
|
||||
lv_indev_set_read_cb(kbHandle, &readCallback);
|
||||
lv_indev_set_display(kbHandle, display);
|
||||
lv_indev_set_user_data(kbHandle, this);
|
||||
|
||||
encHandle = lv_indev_create();
|
||||
lv_indev_set_type(encHandle, LV_INDEV_TYPE_ENCODER);
|
||||
lv_indev_set_read_cb(encHandle, &encoder_read_callback);
|
||||
lv_indev_set_display(encHandle, display);
|
||||
lv_indev_set_user_data(encHandle, this);
|
||||
|
||||
inputTimer->start(20 / portTICK_PERIOD_MS);
|
||||
backlightImpulseTimer->start(50 / portTICK_PERIOD_MS);
|
||||
|
||||
@@ -206,8 +153,6 @@ bool TpagerKeyboard::stopLvgl() {
|
||||
|
||||
lv_indev_delete(kbHandle);
|
||||
kbHandle = nullptr;
|
||||
lv_indev_delete(encHandle);
|
||||
encHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -215,81 +160,6 @@ bool TpagerKeyboard::isAttached() const {
|
||||
return tt::hal::i2c::masterHasDeviceAtAddress(keypad->getPort(), keypad->getAddress(), 100);
|
||||
}
|
||||
|
||||
void TpagerKeyboard::initEncoder(void) {
|
||||
const int low_limit = -127;
|
||||
const 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 = 5000,
|
||||
};
|
||||
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 = NULL;
|
||||
pcnt_channel_handle_t pcnt_chan_2 = NULL;
|
||||
|
||||
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 TpagerKeyboard::getEncoderPulses() {
|
||||
int pulses = 0;
|
||||
pcnt_unit_get_count(encPcntUnit, &pulses);
|
||||
return pulses;
|
||||
}
|
||||
|
||||
|
||||
bool TpagerKeyboard::initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel) {
|
||||
backlightPin = pin;
|
||||
backlightTimer = timer;
|
||||
@@ -344,16 +214,9 @@ void TpagerKeyboard::makeBacklightImpulse() {
|
||||
setBacklightDuty(backlightImpulseDuty);
|
||||
}
|
||||
|
||||
void TpagerKeyboard::processBacklightImpuse() {
|
||||
void TpagerKeyboard::processBacklightImpulse() {
|
||||
if (backlightImpulseDuty > 64) {
|
||||
backlightImpulseDuty--;
|
||||
setBacklightDuty(backlightImpulseDuty);
|
||||
}
|
||||
}
|
||||
|
||||
extern std::shared_ptr<Tca8418> tca8418;
|
||||
std::shared_ptr<tt::hal::keyboard::KeyboardDevice> createKeyboard() {
|
||||
keyboardMsg = xQueueCreate(20, sizeof(char));
|
||||
|
||||
return std::make_shared<TpagerKeyboard>(tca8418);
|
||||
}
|
||||
|
||||
@@ -5,33 +5,38 @@
|
||||
#include <Tca8418.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <driver/pulse_cnt.h>
|
||||
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice {
|
||||
|
||||
lv_indev_t* _Nullable kbHandle = nullptr;
|
||||
lv_indev_t* _Nullable encHandle = nullptr;
|
||||
pcnt_unit_handle_t encPcntUnit = nullptr;
|
||||
gpio_num_t backlightPin = GPIO_NUM_NC;
|
||||
ledc_timer_t backlightTimer;
|
||||
ledc_channel_t backlightChannel;
|
||||
bool backlightOkay = false;
|
||||
int backlightImpulseDuty = 0;
|
||||
QueueHandle_t queue;
|
||||
|
||||
std::shared_ptr<Tca8418> keypad;
|
||||
std::unique_ptr<tt::Timer> inputTimer;
|
||||
std::unique_ptr<tt::Timer> backlightImpulseTimer;
|
||||
|
||||
void initEncoder(void);
|
||||
bool initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel);
|
||||
void processKeyboard();
|
||||
void processBacklightImpuse();
|
||||
void processBacklightImpulse();
|
||||
|
||||
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
|
||||
|
||||
public:
|
||||
|
||||
TpagerKeyboard(std::shared_ptr<Tca8418> tca) : keypad(std::move(tca)) {}
|
||||
TpagerKeyboard(const std::shared_ptr<Tca8418>& tca) : keypad(tca) {
|
||||
queue = xQueueCreate(20, sizeof(char));
|
||||
}
|
||||
|
||||
~TpagerKeyboard() {
|
||||
vQueueDelete(queue);
|
||||
}
|
||||
|
||||
std::string getName() const override { return "T-Lora Pager Keyboard"; }
|
||||
std::string getDescription() const override { return "T-Lora Pager I2C keyboard with encoder"; }
|
||||
@@ -42,9 +47,6 @@ public:
|
||||
bool isAttached() const override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return kbHandle; }
|
||||
|
||||
int getEncoderPulses();
|
||||
bool setBacklightDuty(uint8_t duty);
|
||||
void makeBacklightImpulse();
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::keyboard::KeyboardDevice> createKeyboard();
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
#include "TpagerPower.h"
|
||||
|
||||
#include <Bq25896.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#define TAG "power"
|
||||
constexpr auto* TAG = "TpagerPower";
|
||||
|
||||
#define TPAGER_GAUGE_I2C_BUS_HANDLE I2C_NUM_0
|
||||
|
||||
/*
|
||||
TpagerPower::TpagerPower() : gauge(TPAGER_GAUGE_I2C_BUS_HANDLE) {
|
||||
gauge->configureCapacity(1500, 1500);
|
||||
}*/
|
||||
constexpr auto TPAGER_GAUGE_I2C_BUS_HANDLE = I2C_NUM_0;
|
||||
|
||||
TpagerPower::~TpagerPower() {}
|
||||
|
||||
@@ -29,12 +25,6 @@ bool TpagerPower::supportsMetric(MetricType type) const {
|
||||
}
|
||||
|
||||
bool TpagerPower::getMetric(MetricType type, MetricData& data) {
|
||||
/* IsCharging, // bool
|
||||
Current, // int32_t, mAh - battery current: either during charging (positive value) or discharging (negative value)
|
||||
BatteryVoltage, // uint32_t, mV
|
||||
ChargeLevel, // uint8_t [0, 100]
|
||||
*/
|
||||
|
||||
uint16_t u16 = 0;
|
||||
int16_t s16 = 0;
|
||||
switch (type) {
|
||||
@@ -46,7 +36,6 @@ bool TpagerPower::getMetric(MetricType type, MetricData& data) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case Current:
|
||||
if (gauge->getCurrent(s16)) {
|
||||
data.valueAsInt32 = s16;
|
||||
@@ -54,7 +43,6 @@ bool TpagerPower::getMetric(MetricType type, MetricData& data) {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BatteryVoltage:
|
||||
if (gauge->getVoltage(u16)) {
|
||||
data.valueAsUint32 = u16;
|
||||
@@ -62,7 +50,6 @@ bool TpagerPower::getMetric(MetricType type, MetricData& data) {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ChargeLevel:
|
||||
if (gauge->getStateOfCharge(u16)) {
|
||||
data.valueAsUint8 = u16;
|
||||
@@ -70,21 +57,23 @@ bool TpagerPower::getMetric(MetricType type, MetricData& data) {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return false; // Safety guard for when new enum values are introduced
|
||||
}
|
||||
|
||||
static std::shared_ptr<PowerDevice> power;
|
||||
extern std::shared_ptr<Bq27220> bq27220;
|
||||
void TpagerPower::powerOff() {
|
||||
auto device = tt::hal::findDevice([](auto device) {
|
||||
return device->getName() == "BQ25896";
|
||||
});
|
||||
|
||||
std::shared_ptr<PowerDevice> tpager_get_power() {
|
||||
if (power == nullptr) {
|
||||
power = std::make_shared<TpagerPower>(bq27220);
|
||||
if (device == nullptr) {
|
||||
TT_LOG_E(TAG, "BQ25896 not found");
|
||||
return;
|
||||
}
|
||||
|
||||
auto bq25896 = std::reinterpret_pointer_cast<Bq25896>(device);
|
||||
if (bq25896 != nullptr) {
|
||||
bq25896->powerOff();
|
||||
}
|
||||
return power;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class TpagerPower : public PowerDevice {
|
||||
|
||||
public:
|
||||
|
||||
TpagerPower(std::shared_ptr<Bq27220> bq) : gauge(std::move(bq)) {}
|
||||
TpagerPower(const std::shared_ptr<Bq27220>& bq) : gauge(bq) {}
|
||||
~TpagerPower();
|
||||
|
||||
std::string getName() const final { return "T-LoRa Pager Power measument"; }
|
||||
@@ -20,7 +20,6 @@ public:
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
|
||||
private:
|
||||
bool supportsPowerOff() const override { return true; }
|
||||
void powerOff() override;
|
||||
};
|
||||
|
||||
std::shared_ptr<PowerDevice> tpager_get_power();
|
||||
|
||||
@@ -3,29 +3,27 @@
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
#define TPAGER_SDCARD_PIN_CS GPIO_NUM_21
|
||||
#define TPAGER_LCD_PIN_CS GPIO_NUM_38
|
||||
#define TPAGER_RADIO_PIN_CS GPIO_NUM_36
|
||||
constexpr auto TPAGER_SDCARD_PIN_CS = GPIO_NUM_21;
|
||||
constexpr auto TPAGER_LCD_PIN_CS = GPIO_NUM_38;
|
||||
constexpr auto TPAGER_RADIO_PIN_CS = GPIO_NUM_36;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createTpagerSdCard() {
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
TPAGER_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
{TPAGER_RADIO_PIN_CS,
|
||||
TPAGER_LCD_PIN_CS}
|
||||
std::vector {
|
||||
TPAGER_RADIO_PIN_CS,
|
||||
TPAGER_LCD_PIN_CS
|
||||
}
|
||||
);
|
||||
|
||||
auto* sdcard = (SdCardDevice*)new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user