mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-26 11:05:43 +00:00
tlora-pager wake on button, and kb backlight toggling (#8090)
This commit is contained in:
parent
e1485b530f
commit
07b58a82d5
@ -83,6 +83,11 @@ extern uint16_t TFT_MESH;
|
||||
#include "platform/portduino/PortduinoGlue.h"
|
||||
#endif
|
||||
|
||||
#if defined(T_LORA_PAGER)
|
||||
// KB backlight control
|
||||
#include "input/cardKbI2cImpl.h"
|
||||
#endif
|
||||
|
||||
using namespace meshtastic; /** @todo remove */
|
||||
|
||||
namespace graphics
|
||||
@ -617,6 +622,19 @@ void Screen::setup()
|
||||
MeshModule::observeUIEvents(&uiFrameEventObserver);
|
||||
}
|
||||
|
||||
void Screen::setOn(bool on, FrameCallback einkScreensaver)
|
||||
{
|
||||
#if defined(T_LORA_PAGER)
|
||||
if (cardKbI2cImpl)
|
||||
cardKbI2cImpl->toggleBacklight(on);
|
||||
#endif
|
||||
if (!on)
|
||||
// We handle off commands immediately, because they might be called because the CPU is shutting down
|
||||
handleSetOn(false, einkScreensaver);
|
||||
else
|
||||
enqueueCmd(ScreenCmd{.cmd = Cmd::SET_ON});
|
||||
}
|
||||
|
||||
void Screen::forceDisplay(bool forceUiUpdate)
|
||||
{
|
||||
// Nasty hack to force epaper updates for 'key' frames. FIXME, cleanup.
|
||||
|
@ -259,15 +259,7 @@ class Screen : public concurrency::OSThread
|
||||
void setup();
|
||||
|
||||
/// Turns the screen on/off. Optionally, pass a custom screensaver frame for E-Ink
|
||||
void setOn(bool on, FrameCallback einkScreensaver = NULL)
|
||||
{
|
||||
if (!on)
|
||||
// We handle off commands immediately, because they might be called because the CPU is shutting down
|
||||
handleSetOn(false, einkScreensaver);
|
||||
else
|
||||
enqueueCmd(ScreenCmd{.cmd = Cmd::SET_ON});
|
||||
}
|
||||
|
||||
void setOn(bool on, FrameCallback einkScreensaver = NULL);
|
||||
/**
|
||||
* Prepare the display for the unit going to the lowest power mode possible. Most screens will just
|
||||
* poweroff, but eink screens will show a "I'm sleeping" graphic, possibly with a QR code
|
||||
|
@ -200,6 +200,11 @@ uint8_t TCA8418KeyboardBase::flush()
|
||||
return count;
|
||||
}
|
||||
|
||||
void TCA8418KeyboardBase::clearInt()
|
||||
{
|
||||
writeRegister(TCA8418_REG_INT_STAT, 3);
|
||||
}
|
||||
|
||||
uint8_t TCA8418KeyboardBase::digitalRead(uint8_t pinnum) const
|
||||
{
|
||||
if (pinnum > TCA8418_COL9)
|
||||
|
@ -37,6 +37,8 @@ class TCA8418KeyboardBase
|
||||
virtual void begin(i2c_com_fptr_t r, i2c_com_fptr_t w, uint8_t addr = TCA8418_KB_ADDR);
|
||||
|
||||
virtual void reset(void);
|
||||
void clearInt(void);
|
||||
|
||||
virtual void trigger(void);
|
||||
|
||||
virtual void setBacklight(bool on);
|
||||
|
@ -105,7 +105,14 @@ void TLoraPagerKeyboard::trigger()
|
||||
|
||||
void TLoraPagerKeyboard::setBacklight(bool on)
|
||||
{
|
||||
toggleBacklight(!on);
|
||||
uint32_t _brightness = 0;
|
||||
if (on)
|
||||
_brightness = brightness;
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
ledcWrite(KB_BL_PIN, _brightness);
|
||||
#else
|
||||
ledcWrite(LEDC_BACKLIGHT_CHANNEL, _brightness);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TLoraPagerKeyboard::pressed(uint8_t key)
|
||||
@ -192,7 +199,6 @@ void TLoraPagerKeyboard::hapticFeedback()
|
||||
// toggle brightness of the backlight in three steps
|
||||
void TLoraPagerKeyboard::toggleBacklight(bool off)
|
||||
{
|
||||
static uint32_t brightness = 0;
|
||||
if (off) {
|
||||
brightness = 0;
|
||||
} else {
|
||||
@ -206,11 +212,7 @@ void TLoraPagerKeyboard::toggleBacklight(bool off)
|
||||
}
|
||||
LOG_DEBUG("Toggle backlight: %d", brightness);
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
ledcWrite(KB_BL_PIN, brightness);
|
||||
#else
|
||||
ledcWrite(LEDC_BACKLIGHT_CHANNEL, brightness);
|
||||
#endif
|
||||
setBacklight(true);
|
||||
}
|
||||
|
||||
void TLoraPagerKeyboard::updateModifierFlag(uint8_t key)
|
||||
|
@ -26,4 +26,5 @@ class TLoraPagerKeyboard : public TCA8418KeyboardBase
|
||||
uint32_t last_tap;
|
||||
uint8_t char_idx;
|
||||
int32_t tap_interval;
|
||||
uint32_t brightness = 0;
|
||||
};
|
||||
|
@ -333,6 +333,7 @@ int32_t KbI2cBase::runOnce()
|
||||
}
|
||||
TCAKeyboard.trigger();
|
||||
}
|
||||
TCAKeyboard.clearInt();
|
||||
break;
|
||||
}
|
||||
case 0x02: {
|
||||
@ -519,4 +520,11 @@ int32_t KbI2cBase::runOnce()
|
||||
LOG_WARN("Unknown kb_model 0x%02x", kb_model);
|
||||
}
|
||||
return 300;
|
||||
}
|
||||
}
|
||||
|
||||
void KbI2cBase::toggleBacklight(bool on)
|
||||
{
|
||||
#if defined(T_LORA_PAGER)
|
||||
TCAKeyboard.setBacklight(on);
|
||||
#endif
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ class KbI2cBase : public Observable<const InputEvent *>, public concurrency::OST
|
||||
{
|
||||
public:
|
||||
explicit KbI2cBase(const char *name);
|
||||
void toggleBacklight(bool on);
|
||||
|
||||
protected:
|
||||
virtual int32_t runOnce() override;
|
||||
|
@ -367,6 +367,7 @@ void setup()
|
||||
digitalWrite(SDCARD_CS, HIGH);
|
||||
pinMode(TFT_CS, OUTPUT);
|
||||
digitalWrite(TFT_CS, HIGH);
|
||||
pinMode(KB_INT, INPUT_PULLUP);
|
||||
// io expander
|
||||
io.begin(Wire, XL9555_SLAVE_ADDRESS0, SDA, SCL);
|
||||
io.pinMode(EXPANDS_DRV_EN, OUTPUT);
|
||||
|
@ -411,12 +411,16 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
|
||||
// assert(uart_set_wakeup_threshold(UART_NUM_0, 3) == ESP_OK);
|
||||
// assert(esp_sleep_enable_uart_wakeup(0) == ESP_OK);
|
||||
#endif
|
||||
#ifdef BUTTON_PIN
|
||||
#ifdef ROTARY_PRESS
|
||||
// The enableLoraInterrupt() method is using ext0_wakeup, so we are forced to use GPIO wakeup
|
||||
gpio_wakeup_enable((gpio_num_t)ROTARY_PRESS, GPIO_INTR_LOW_LEVEL);
|
||||
#endif
|
||||
#ifdef KB_INT
|
||||
gpio_wakeup_enable((gpio_num_t)KB_INT, GPIO_INTR_LOW_LEVEL);
|
||||
#endif
|
||||
#ifdef BUTTON_PIN
|
||||
gpio_num_t pin = (gpio_num_t)(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN);
|
||||
|
||||
gpio_wakeup_enable(pin, GPIO_INTR_LOW_LEVEL);
|
||||
esp_sleep_enable_gpio_wakeup();
|
||||
#endif
|
||||
#ifdef INPUTDRIVER_ENCODER_BTN
|
||||
gpio_wakeup_enable((gpio_num_t)INPUTDRIVER_ENCODER_BTN, GPIO_INTR_LOW_LEVEL);
|
||||
@ -450,7 +454,12 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
|
||||
// commented out because it's not that crucial;
|
||||
// if it sporadically happens the node will go into light sleep during the next round
|
||||
// assert(res == ESP_OK);
|
||||
|
||||
#ifdef ROTARY_PRESS
|
||||
gpio_wakeup_disable((gpio_num_t)ROTARY_PRESS);
|
||||
#endif
|
||||
#ifdef KB_INT
|
||||
gpio_wakeup_disable((gpio_num_t)KB_INT);
|
||||
#endif
|
||||
#ifdef BUTTON_PIN
|
||||
// Disable wake-on-button interrupt. Re-attach normal button-interrupts
|
||||
gpio_wakeup_disable(pin);
|
||||
|
Loading…
Reference in New Issue
Block a user