~aleteoryx/muditaos

0c246dc372e14d100221f0c999a4130dbb7fc1c9 — Mateusz Piesta 3 years ago e7b2495
[BH-1533] Display battery charging state

Battery state during charging is always
displayed even if the state of charge
reached 100%.
Minor refactor of BellBattery class.
Removed unused includes.
M module-db/Interface/AlarmEventRecord.cpp => module-db/Interface/AlarmEventRecord.cpp +0 -3
@@ 39,9 39,6 @@ auto AlarmEventRecord::isValid() const -> bool
AlarmEventRecordInterface::AlarmEventRecordInterface(EventsDB *eventsDB) : eventsDB(eventsDB)
{}

AlarmEventRecordInterface::~AlarmEventRecordInterface()
{}

std::unique_ptr<db::QueryResult> AlarmEventRecordInterface::runQuery(std::shared_ptr<db::Query> query)
{
    if (typeid(*query) == typeid(db::query::alarmEvents::Add)) {

M module-db/Interface/AlarmEventRecord.hpp => module-db/Interface/AlarmEventRecord.hpp +1 -1
@@ 66,7 66,7 @@ class AlarmEventRecordInterface : public db::Interface
{
  public:
    explicit AlarmEventRecordInterface(EventsDB *eventsDB);
    ~AlarmEventRecordInterface();
    virtual ~AlarmEventRecordInterface() noexcept = default;

    std::unique_ptr<db::QueryResult> runQuery(std::shared_ptr<db::Query> query) override;


M products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassic.hpp => products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassic.hpp +0 -6
@@ 39,12 39,6 @@ namespace gui
        SnoozeIconAndTime,
    };

    namespace battery
    {
        constexpr auto chargingLevelHideBot    = 100;
        constexpr auto dischargingLevelShowTop = 20;
    }; // namespace battery

    class HomeScreenLayoutClassic : public BaseHomeScreenLayoutProvider, BellBaseLayout
    {
      public:

M products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutVertical.hpp => products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutVertical.hpp +0 -6
@@ 24,12 24,6 @@ namespace gui
    class Icon;
    class Item;

    namespace battery_vertical
    {
        constexpr auto chargingLevelHideBot    = 100;
        constexpr auto dischargingLevelShowTop = 20;
    }; // namespace battery_vertical

    enum class ScreenMode
    {
        Main,

M products/BellHybrid/apps/common/include/common/widgets/BellBattery.hpp => products/BellHybrid/apps/common/include/common/widgets/BellBattery.hpp +2 -9
@@ 3,7 3,7 @@

#pragma once

#include <EventStore.hpp>
#include <Units.hpp>
#include <gui/widgets/BoxLayout.hpp>
#include <gui/widgets/Image.hpp>
#include <gui/widgets/text/TextFixedSize.hpp>


@@ 13,13 13,7 @@ namespace gui

    namespace battery
    {
        constexpr auto battery_low        = "bell_battery_lvl1";
        constexpr auto battery_critical   = "bell_battery_empty";
        constexpr auto battery_charging   = "bell_battery_charging";
        constexpr auto font_small         = style::window::font::largelight;
        constexpr auto image_h            = 64;
        constexpr auto image_w            = 64U;
        constexpr auto image_left_margin  = 0U;
        constexpr auto image_right_margin = 10U;
        constexpr auto percent_h          = 102U;
        constexpr auto percent_w          = 106U;


@@ 38,9 32,8 @@ namespace gui
    {
      public:
        BellBattery(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h);
        void update(const Store::Battery &batteryContext);
        void update(units::SOC soc, bool isCharging);
        void setBatteryPercentMode(BatteryPercentMode mode);
        std::uint32_t getLevel();

      private:
        BatteryPercentMode batteryPercentMode = BatteryPercentMode::Show;

M products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp => products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp +13 -6
@@ 8,13 8,23 @@
#include "widgets/SnoozeTimer.hpp"

#include <apps-common/actions/AlarmRingingData.hpp>
#include <gui/input/InputEvent.hpp>
#include <gui/widgets/text/TextFixedSize.hpp>
#include <gui/widgets/Style.hpp>
#include <time/time_constants.hpp>
#include <widgets/AlarmSetSpinner.hpp>
#include <widgets/TimeSetFmtSpinner.hpp>

namespace
{
    constexpr auto dischargingLevelShowTop = 20;

    bool isBatteryCharging(const Store::Battery::State state)
    {
        using State = Store::Battery::State;
        return state == State::Charging or state == State::ChargingDone;
    }
} // namespace

namespace gui
{
    HomeScreenLayoutClassic::HomeScreenLayoutClassic(std::string name)


@@ 193,15 203,12 @@ namespace gui

    bool HomeScreenLayoutClassic::isBatteryVisibilityAllowed(const Store::Battery &batteryContext)
    {
        // TODO fix magic values
        return (batteryContext.level < battery::dischargingLevelShowTop) ||
               (batteryContext.state == Store::Battery::State::Charging &&
                batteryContext.level != battery::chargingLevelHideBot);
        return (batteryContext.level < dischargingLevelShowTop) || isBatteryCharging(batteryContext.state);
    }

    void HomeScreenLayoutClassic::setBatteryLevelState(const Store::Battery &batteryContext)
    {
        battery->update(batteryContext);
        battery->update(batteryContext.level, isBatteryCharging(batteryContext.state));
        if (isBatteryVisibilityAllowed(batteryContext)) {
            battery->setVisible(true);
        }

M products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutVertical.cpp => products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutVertical.cpp +13 -7
@@ 7,17 7,25 @@
#include "widgets/DuoHBox.hpp"
#include "widgets/SnoozeTimer.hpp"

#include <common/data/StyleCommon.hpp>
#include <apps-common/actions/AlarmRingingData.hpp>
#include <gui/input/InputEvent.hpp>
#include <gui/widgets/Icon.hpp>
#include <gui/widgets/text/TextFixedSize.hpp>
#include <gui/widgets/Style.hpp>
#include <time/time_constants.hpp>
#include <widgets/AlarmIcon.hpp>
#include <widgets/AlarmSetSpinner.hpp>
#include <widgets/ClockVertical.hpp>

namespace
{
    constexpr auto dischargingLevelShowTop = 20;

    bool isBatteryCharging(const Store::Battery::State state)
    {
        using State = Store::Battery::State;
        return state == State::Charging or state == State::ChargingDone;
    }
} // namespace

namespace gui
{
    HomeScreenLayoutVertical::HomeScreenLayoutVertical(std::string name)


@@ 118,14 126,12 @@ namespace gui

    bool HomeScreenLayoutVertical::isBatteryVisibilityAllowed(const Store::Battery &batteryContext)
    {
        return (batteryContext.level < battery_vertical::dischargingLevelShowTop) ||
               (batteryContext.state == Store::Battery::State::Charging &&
                batteryContext.level != battery_vertical::chargingLevelHideBot);
        return (batteryContext.level < dischargingLevelShowTop) or isBatteryCharging(batteryContext.state);
    }

    void HomeScreenLayoutVertical::setBatteryLevelState(const Store::Battery &batteryContext)
    {
        battery->update(batteryContext);
        battery->update(batteryContext.level, isBatteryCharging(batteryContext.state));
        if (isBatteryVisibilityAllowed(batteryContext)) {
            battery->setVisible(true);
        }

M products/BellHybrid/apps/common/src/widgets/BellBattery.cpp => products/BellHybrid/apps/common/src/widgets/BellBattery.cpp +9 -17
@@ 7,22 7,22 @@

namespace
{
    constexpr auto battery_low      = "bell_battery_lvl1";
    constexpr auto battery_charging = "bell_battery_charging";

    constexpr auto entries = std::array<battery_utils::BatteryLevelEntry, 6>{{{{0, 9}, "bell_battery_empty"},
                                                                              {{10, 19}, "bell_battery_lvl1"},
                                                                              {{20, 39}, "bell_battery_lvl2"},
                                                                              {{40, 69}, "bell_battery_lvl3"},
                                                                              {{70, 95}, "bell_battery_lvl4"},
                                                                              {{96, 100}, "bell_battery_lvl5"}}};

    constexpr auto betteryFullLevel = 100;
    constexpr auto lowBatteryLimit  = 20;
} // namespace

namespace gui
{
    BellBattery::BellBattery(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h) : HBox(parent, x, y, w, h)
    {
        img = new Image(this, battery::battery_low, gui::ImageTypeSpecifier::W_M);
        img = new Image(this, battery_low, gui::ImageTypeSpecifier::W_M);
        img->setAlignment(Alignment(Alignment::Horizontal::Left, Alignment::Vertical::Center));
        img->setMargins(gui::Margins(0, 0, battery::image_right_margin, 0));



@@ 36,18 36,17 @@ namespace gui
        percentText->setVisible(false);
    }

    void BellBattery::update(const Store::Battery &batteryContext)
    void BellBattery::update(const units::SOC soc, const bool isCharging)
    {
        const auto image = battery_utils::getBatteryLevelImage(entries, batteryContext.level);
        const auto image = battery_utils::getBatteryLevelImage(entries, soc);
        if (not image) {
            return;
        }

        const auto level = batteryContext.level;
        percentText->setText(std::to_string(level) + "%");
        percentText->setText(std::to_string(soc) + "%");

        if (batteryContext.state == Store::Battery::State::Charging) {
            img->set(battery::battery_charging, gui::ImageTypeSpecifier::W_M);
        if (isCharging) {
            img->set(battery_charging, gui::ImageTypeSpecifier::W_M);
        }
        else {
            img->set(image->data(), gui::ImageTypeSpecifier::W_M);


@@ 69,11 68,4 @@ namespace gui
            percentText->setVisible(false);
        }
    }

    std::uint32_t BellBattery::getLevel()
    {
        auto percentTextStr  = std::string(percentText->getText().c_str());
        auto batteryLevelStr = percentTextStr.substr(0, percentTextStr.size() - 1);
        return std::stoi(batteryLevelStr);
    }
} // namespace gui