Tab5 features, StackChan, fixes, drivers.... (#526)
This commit is contained in:
@@ -40,6 +40,10 @@ public:
|
||||
virtual bool isAllowedToCharge() const { return false; }
|
||||
virtual void setAllowedToCharge(bool canCharge) { /* NO-OP*/ }
|
||||
|
||||
virtual bool supportsQuickCharge() const { return false; }
|
||||
virtual bool isQuickChargeEnabled() const { return false; }
|
||||
virtual void setQuickChargeEnabled(bool enabled) { /* NO-OP */ }
|
||||
|
||||
virtual bool supportsPowerOff() const { return false; }
|
||||
virtual void powerOff() { /* NO-OP*/ }
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ enum class ScreensaverType {
|
||||
BouncingBalls,
|
||||
Mystify,
|
||||
MatrixRain,
|
||||
StackChan,
|
||||
Count // Sentinel for bounds checking - must be last
|
||||
};
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ public:
|
||||
|
||||
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
||||
// Note: order correlates with settings::display::ScreensaverType enum order
|
||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain");
|
||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan");
|
||||
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
|
||||
|
||||
@@ -38,6 +38,8 @@ class PowerApp : public App {
|
||||
|
||||
lv_obj_t* enableLabel = nullptr;
|
||||
lv_obj_t* enableSwitch = nullptr;
|
||||
lv_obj_t* quickChargeLabel = nullptr;
|
||||
lv_obj_t* quickChargeSwitch = nullptr;
|
||||
lv_obj_t* batteryVoltageLabel = nullptr;
|
||||
lv_obj_t* chargeStateLabel = nullptr;
|
||||
lv_obj_t* chargeLevelLabel = nullptr;
|
||||
@@ -68,7 +70,29 @@ class PowerApp : public App {
|
||||
app->onPowerEnabledChanged(event);
|
||||
}
|
||||
|
||||
void onQuickChargeChanged(lv_event_t* event) {
|
||||
lv_event_code_t code = lv_event_get_code(event);
|
||||
auto* qc_switch = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||
bool is_on = lv_obj_has_state(qc_switch, LV_STATE_CHECKED);
|
||||
|
||||
if (power->isQuickChargeEnabled() != is_on) {
|
||||
power->setQuickChargeEnabled(is_on);
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void onQuickChargeChangedCallback(lv_event_t* event) {
|
||||
auto* app = (PowerApp*)lv_event_get_user_data(event);
|
||||
app->onQuickChargeChanged(event);
|
||||
}
|
||||
|
||||
void updateUi() {
|
||||
if (chargeStateLabel == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* charge_state;
|
||||
hal::power::PowerDevice::MetricData metric_data;
|
||||
if (power->getMetric(hal::power::PowerDevice::MetricType::IsCharging, metric_data)) {
|
||||
@@ -87,6 +111,9 @@ class PowerApp : public App {
|
||||
bool charging_enabled_set = power->supportsChargeControl();
|
||||
bool charging_enabled_and_allowed = power->supportsChargeControl() && power->isAllowedToCharge();
|
||||
|
||||
bool quick_charge_set = power->supportsQuickCharge();
|
||||
bool quick_charge_enabled = power->supportsQuickCharge() && power->isQuickChargeEnabled();
|
||||
|
||||
int32_t current;
|
||||
bool current_set = false;
|
||||
if (power->getMetric(hal::power::PowerDevice::MetricType::Current, metric_data)) {
|
||||
@@ -112,6 +139,15 @@ class PowerApp : public App {
|
||||
lv_obj_add_flag(enableLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
if (quick_charge_set) {
|
||||
lv_obj_set_state(quickChargeSwitch, LV_STATE_CHECKED, quick_charge_enabled);
|
||||
lv_obj_remove_flag(quickChargeSwitch, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(quickChargeLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_obj_add_flag(quickChargeSwitch, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(quickChargeLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
lv_label_set_text_fmt(chargeStateLabel, "Charging: %s", charge_state);
|
||||
|
||||
if (battery_voltage_set) {
|
||||
@@ -127,7 +163,7 @@ class PowerApp : public App {
|
||||
}
|
||||
|
||||
if (current_set) {
|
||||
lv_label_set_text_fmt(currentLabel, "Current: %ld mAh", current);
|
||||
lv_label_set_text_fmt(currentLabel, "Current: %ld mA", current);
|
||||
} else {
|
||||
lv_label_set_text_fmt(currentLabel, "Current: N/A");
|
||||
}
|
||||
@@ -157,7 +193,7 @@ public:
|
||||
lv_obj_set_flex_grow(wrapper, 1);
|
||||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
// Top row: enable/disable
|
||||
// Row: charge enable/disable
|
||||
lv_obj_t* switch_container = lv_obj_create(wrapper);
|
||||
lv_obj_set_width(switch_container, LV_PCT(100));
|
||||
lv_obj_set_height(switch_container, LV_SIZE_CONTENT);
|
||||
@@ -172,8 +208,25 @@ public:
|
||||
lv_obj_t* enable_switch = lv_switch_create(switch_container);
|
||||
lv_obj_add_event_cb(enable_switch, onPowerEnabledChangedCallback, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_obj_set_align(enable_switch, LV_ALIGN_RIGHT_MID);
|
||||
|
||||
enableSwitch = enable_switch;
|
||||
|
||||
// Row: quick charge enable/disable
|
||||
lv_obj_t* qc_container = lv_obj_create(wrapper);
|
||||
lv_obj_set_width(qc_container, LV_PCT(100));
|
||||
lv_obj_set_height(qc_container, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(qc_container, 0, 0);
|
||||
lv_obj_set_style_pad_gap(qc_container, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(qc_container);
|
||||
|
||||
quickChargeLabel = lv_label_create(qc_container);
|
||||
lv_label_set_text(quickChargeLabel, "Quick charge");
|
||||
lv_obj_set_align(quickChargeLabel, LV_ALIGN_LEFT_MID);
|
||||
|
||||
lv_obj_t* qc_switch = lv_switch_create(qc_container);
|
||||
lv_obj_add_event_cb(qc_switch, onQuickChargeChangedCallback, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_obj_set_align(qc_switch, LV_ALIGN_RIGHT_MID);
|
||||
quickChargeSwitch = qc_switch;
|
||||
|
||||
chargeStateLabel = lv_label_create(wrapper);
|
||||
chargeLevelLabel = lv_label_create(wrapper);
|
||||
batteryVoltageLabel = lv_label_create(wrapper);
|
||||
@@ -186,6 +239,14 @@ public:
|
||||
|
||||
void onHide(AppContext& app) override {
|
||||
update_timer.stop();
|
||||
enableLabel = nullptr;
|
||||
enableSwitch = nullptr;
|
||||
quickChargeLabel = nullptr;
|
||||
quickChargeSwitch = nullptr;
|
||||
chargeStateLabel = nullptr;
|
||||
chargeLevelLabel = nullptr;
|
||||
batteryVoltageLabel = nullptr;
|
||||
currentLabel = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "BouncingBallsScreensaver.h"
|
||||
#include "MatrixRainScreensaver.h"
|
||||
#include "MystifyScreensaver.h"
|
||||
#include "StackChanScreensaver.h"
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/CoreDefines.h>
|
||||
@@ -99,6 +100,9 @@ void DisplayIdleService::activateScreensaver() {
|
||||
case settings::display::ScreensaverType::MatrixRain:
|
||||
screensaver = std::make_unique<MatrixRainScreensaver>();
|
||||
break;
|
||||
case settings::display::ScreensaverType::StackChan:
|
||||
screensaver = std::make_unique<StackChanScreensaver>();
|
||||
break;
|
||||
case settings::display::ScreensaverType::None:
|
||||
default:
|
||||
// Just black screen, no animated screensaver
|
||||
@@ -135,31 +139,31 @@ void DisplayIdleService::tick() {
|
||||
|
||||
uint32_t inactive_ms = 0;
|
||||
|
||||
inactive_ms = lv_display_get_inactive_time(nullptr);
|
||||
inactive_ms = lv_display_get_inactive_time(nullptr);
|
||||
|
||||
// Only update if not stopping (prevents lag on touch)
|
||||
if (displayDimmed && screensaverOverlay && !stopScreensaverRequested.load(std::memory_order_acquire)) {
|
||||
// Check if screensaver should auto-off after 5 minutes
|
||||
if (!backlightOff) {
|
||||
screensaverActiveCounter++;
|
||||
if (screensaverActiveCounter >= SCREENSAVER_AUTO_OFF_TICKS) {
|
||||
// Stop screensaver animation and turn off backlight
|
||||
if (screensaver) {
|
||||
screensaver->stop();
|
||||
screensaver.reset();
|
||||
}
|
||||
auto display = getDisplay();
|
||||
if (display) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
backlightOff = true;
|
||||
} else {
|
||||
updateScreensaver();
|
||||
// Only update if not stopping (prevents lag on touch)
|
||||
if (displayDimmed && screensaverOverlay && !stopScreensaverRequested.load(std::memory_order_acquire)) {
|
||||
// Check if screensaver should auto-off after 5 minutes
|
||||
if (!backlightOff) {
|
||||
screensaverActiveCounter++;
|
||||
if (screensaverActiveCounter >= SCREENSAVER_AUTO_OFF_TICKS) {
|
||||
// Stop screensaver animation and turn off backlight
|
||||
if (screensaver) {
|
||||
screensaver->stop();
|
||||
screensaver.reset();
|
||||
}
|
||||
auto display = getDisplay();
|
||||
if (display) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
backlightOff = true;
|
||||
} else {
|
||||
updateScreensaver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lvgl::unlock();
|
||||
lvgl::unlock();
|
||||
|
||||
// Check stop request early for faster response
|
||||
if (stopScreensaverRequested.load(std::memory_order_acquire)) {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "StackChanScreensaver.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace tt::service::displayidle {
|
||||
|
||||
static lv_obj_t* makeFacePart(lv_obj_t* parent, lv_coord_t w, lv_coord_t h, lv_coord_t offX, lv_coord_t offY, bool circle) {
|
||||
lv_obj_t* obj = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(obj);
|
||||
lv_obj_set_size(obj, w, h);
|
||||
lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
|
||||
lv_obj_set_style_bg_color(obj, lv_color_black(), 0);
|
||||
lv_obj_set_style_radius(obj, circle ? LV_RADIUS_CIRCLE : 0, 0);
|
||||
lv_obj_align(obj, LV_ALIGN_CENTER, offX, offY);
|
||||
return obj;
|
||||
}
|
||||
|
||||
void StackChanScreensaver::start(lv_obj_t* overlay, lv_coord_t screenW, lv_coord_t screenH) {
|
||||
// Scale face to ~12% of the shorter screen dimension, preserving 4:3 aspect ratio
|
||||
lv_coord_t shorter = (screenW < screenH) ? screenW : screenH;
|
||||
logoH_ = shorter / 8;
|
||||
logoW_ = logoH_ * 4 / 3;
|
||||
|
||||
// Face part sizes scaled proportionally to original (64x48 base with 6px eyes, 18x2 mouth)
|
||||
lv_coord_t eyeSize = std::max<lv_coord_t>(2, logoH_ / 8);
|
||||
lv_coord_t eyeOffX = logoW_ / 4;
|
||||
lv_coord_t eyeOffY = -(logoH_ / 10);
|
||||
lv_coord_t mouthW = logoW_ * 18 / 64;
|
||||
lv_coord_t mouthH = std::max<lv_coord_t>(2, logoH_ / 24);
|
||||
lv_coord_t mouthOffY = logoH_ / 10;
|
||||
|
||||
// Speed: ~5% of shorter dimension per second at 50ms tick = 0.25% per tick
|
||||
lv_coord_t speed = std::max<lv_coord_t>(2, shorter / 80);
|
||||
|
||||
logo_ = lv_obj_create(overlay);
|
||||
lv_obj_remove_style_all(logo_);
|
||||
lv_obj_set_size(logo_, logoW_, logoH_);
|
||||
lv_obj_set_style_bg_opa(logo_, LV_OPA_COVER, 0);
|
||||
lv_obj_set_style_bg_color(logo_, lv_color_hex(COLORS[0]), 0);
|
||||
lv_obj_set_style_radius(logo_, 0, 0);
|
||||
lv_obj_clear_flag(logo_, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
leftEye_ = makeFacePart(logo_, eyeSize, eyeSize, -eyeOffX, eyeOffY, true);
|
||||
rightEye_ = makeFacePart(logo_, eyeSize, eyeSize, eyeOffX, eyeOffY, true);
|
||||
mouth_ = makeFacePart(logo_, mouthW, mouthH, 0, mouthOffY, false);
|
||||
|
||||
x_ = (screenW - logoW_) / 2;
|
||||
y_ = (screenH - logoH_) / 2;
|
||||
dx_ = speed;
|
||||
dy_ = speed;
|
||||
colorIndex_ = 0;
|
||||
|
||||
lv_obj_set_pos(logo_, x_, y_);
|
||||
}
|
||||
|
||||
void StackChanScreensaver::stop() {
|
||||
logo_ = nullptr;
|
||||
leftEye_ = nullptr;
|
||||
rightEye_ = nullptr;
|
||||
mouth_ = nullptr;
|
||||
}
|
||||
|
||||
void StackChanScreensaver::update(lv_coord_t screenW, lv_coord_t screenH) {
|
||||
if (!logo_) return;
|
||||
|
||||
x_ += dx_;
|
||||
y_ += dy_;
|
||||
|
||||
bool collided = false;
|
||||
|
||||
if (x_ <= 0) {
|
||||
x_ = 0;
|
||||
dx_ = -dx_;
|
||||
collided = true;
|
||||
} else if (x_ >= screenW - logoW_) {
|
||||
x_ = screenW - logoW_;
|
||||
dx_ = -dx_;
|
||||
collided = true;
|
||||
}
|
||||
|
||||
if (y_ <= 0) {
|
||||
y_ = 0;
|
||||
dy_ = -dy_;
|
||||
collided = true;
|
||||
} else if (y_ >= screenH - logoH_) {
|
||||
y_ = screenH - logoH_;
|
||||
dy_ = -dy_;
|
||||
collided = true;
|
||||
}
|
||||
|
||||
if (collided) {
|
||||
colorIndex_ = (colorIndex_ + 1) % static_cast<int>(COLORS.size());
|
||||
lv_obj_set_style_bg_color(logo_, lv_color_hex(COLORS[colorIndex_]), 0);
|
||||
}
|
||||
|
||||
lv_obj_set_pos(logo_, x_, y_);
|
||||
}
|
||||
|
||||
} // namespace tt::service::displayidle
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "Screensaver.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tt::service::displayidle {
|
||||
|
||||
class StackChanScreensaver final : public Screensaver {
|
||||
public:
|
||||
StackChanScreensaver() = default;
|
||||
~StackChanScreensaver() override = default;
|
||||
StackChanScreensaver(const StackChanScreensaver&) = delete;
|
||||
StackChanScreensaver& operator=(const StackChanScreensaver&) = delete;
|
||||
StackChanScreensaver(StackChanScreensaver&&) = delete;
|
||||
StackChanScreensaver& operator=(StackChanScreensaver&&) = delete;
|
||||
|
||||
void start(lv_obj_t* overlay, lv_coord_t screenW, lv_coord_t screenH) override;
|
||||
void stop() override;
|
||||
void update(lv_coord_t screenW, lv_coord_t screenH) override;
|
||||
|
||||
private:
|
||||
static constexpr std::array<uint32_t, 8> COLORS = {
|
||||
0xffffff, 0xfffa01, 0xff8300, 0x00feff,
|
||||
0xff2600, 0xbe00ff, 0x0026ff, 0xff008b,
|
||||
};
|
||||
static_assert(COLORS.size() > 0);
|
||||
|
||||
lv_obj_t* logo_ = nullptr;
|
||||
lv_obj_t* leftEye_ = nullptr;
|
||||
lv_obj_t* rightEye_ = nullptr;
|
||||
lv_obj_t* mouth_ = nullptr;
|
||||
|
||||
lv_coord_t logoW_ = 0;
|
||||
lv_coord_t logoH_ = 0;
|
||||
lv_coord_t x_ = 0;
|
||||
lv_coord_t y_ = 0;
|
||||
lv_coord_t dx_ = 0;
|
||||
lv_coord_t dy_ = 0;
|
||||
int colorIndex_ = 0;
|
||||
};
|
||||
|
||||
} // namespace tt::service::displayidle
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -76,6 +76,8 @@ static std::string toString(ScreensaverType type) {
|
||||
return "Mystify";
|
||||
case MatrixRain:
|
||||
return "MatrixRain";
|
||||
case StackChan:
|
||||
return "StackChan";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
@@ -94,6 +96,9 @@ static bool fromString(const std::string& str, ScreensaverType& type) {
|
||||
} else if (str == "MatrixRain") {
|
||||
type = ScreensaverType::MatrixRain;
|
||||
return true;
|
||||
} else if (str == "StackChan") {
|
||||
type = ScreensaverType::StackChan;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user