Skip to content

Commit

Permalink
Implement scheduled "Display on Lift Wrist"
Browse files Browse the repository at this point in the history
Fixes #100

AmazfishConfig files re-saved with unix line-endings
  • Loading branch information
piggz committed Jan 1, 2024
1 parent e9805b6 commit 48c345b
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 262 deletions.
18 changes: 14 additions & 4 deletions daemon/src/services/mibandservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,21 @@ void MiBandService::setAlertFitnessGoal()

void MiBandService::setEnableDisplayOnLiftWrist()
{
auto value = AmazfishConfig::instance()->profileDisplayOnLiftWrist()
? COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST
: COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST;
QByteArray cmd;

writeValue(UUID_CHARACTERISTIC_MIBAND_CONFIGURATION, UCHARARR_TO_BYTEARRAY(value));
if (AmazfishConfig::instance()->profileDisplayOnLiftWrist() == AmazfishConfig::DisplayLiftWristOff) {
cmd = UCHARARR_TO_BYTEARRAY(COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST);
} else if (AmazfishConfig::instance()->profileDisplayOnLiftWrist() == AmazfishConfig::DisplayLiftWristOn) {
cmd = UCHARARR_TO_BYTEARRAY(COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST);
} else {
cmd = UCHARARR_TO_BYTEARRAY(COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST);
cmd[4] = AmazfishConfig::instance()->profileWristScheduleStart().time().hour();
cmd[5] = AmazfishConfig::instance()->profileWristScheduleStart().time().minute();
cmd[6] = AmazfishConfig::instance()->profileWristScheduleEnd().time().hour();
cmd[7] = AmazfishConfig::instance()->profileWristScheduleEnd().time().minute();
}

writeValue(UUID_CHARACTERISTIC_MIBAND_CONFIGURATION, cmd);
}

void MiBandService::setDisplayItems()
Expand Down
134 changes: 67 additions & 67 deletions lib/src/amazfishconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
#include "amazfishconfig.h"

#include <QCoreApplication>

#ifdef MER_EDITION_SAILFISH
#include <MDConfGroup>
#endif

#include <functional>


AmazfishConfig::AmazfishConfig(QObject *parent)
: QObject(parent)
#ifdef MER_EDITION_SAILFISH
, m_group(new MDConfGroup(QStringLiteral("/uk/co/piggz/amazfish"), this))
#endif
{

}

AmazfishConfig *AmazfishConfig::instance()
{
static AmazfishConfig *inst = nullptr;
if (!inst) {
inst = new AmazfishConfig(qApp);
}
return inst;
}

QVariant AmazfishConfig::value(const QString &key, const QVariant &def) const
{
#ifdef MER_EDITION_SAILFISH
return m_group->value(key, def);
#else
QSettings settings;
return settings.value(key, def);
#endif
}

void AmazfishConfig::setValue(const QString &key, const QVariant &value)
{
#ifdef MER_EDITION_SAILFISH
m_group->setValue(key, value);
#else
QSettings settings;
settings.setValue(key, value);
#endif
}

void AmazfishConfig::setValue(const QString &key, const QVariant &value, signal_ptr signal)
{
#ifdef MER_EDITION_SAILFISH
auto prev = m_group->value(key);
#else
QSettings settings;
auto prev = settings.value(key);
#endif

if (value != prev) {
#ifdef MER_EDITION_SAILFISH
m_group->setValue(key, value);
#else
settings.setValue(key, value);
#endif
emit std::bind(signal, this)();
}
}
#include "amazfishconfig.h"

#include <QCoreApplication>

#ifdef MER_EDITION_SAILFISH
#include <MDConfGroup>
#endif

#include <functional>


AmazfishConfig::AmazfishConfig(QObject *parent)
: QObject(parent)
#ifdef MER_EDITION_SAILFISH
, m_group(new MDConfGroup(QStringLiteral("/uk/co/piggz/amazfish"), this))
#endif
{

}

AmazfishConfig *AmazfishConfig::instance()
{
static AmazfishConfig *inst = nullptr;
if (!inst) {
inst = new AmazfishConfig(qApp);
}
return inst;
}

QVariant AmazfishConfig::value(const QString &key, const QVariant &def) const
{
#ifdef MER_EDITION_SAILFISH
return m_group->value(key, def);
#else
QSettings settings;
return settings.value(key, def);
#endif
}

void AmazfishConfig::setValue(const QString &key, const QVariant &value)
{
#ifdef MER_EDITION_SAILFISH
m_group->setValue(key, value);
#else
QSettings settings;
settings.setValue(key, value);
#endif
}

void AmazfishConfig::setValue(const QString &key, const QVariant &value, signal_ptr signal)
{
#ifdef MER_EDITION_SAILFISH
auto prev = m_group->value(key);
#else
QSettings settings;
auto prev = settings.value(key);
#endif

if (value != prev) {
#ifdef MER_EDITION_SAILFISH
m_group->setValue(key, value);
#else
settings.setValue(key, value);
#endif
emit std::bind(signal, this)();
}
}
Loading

0 comments on commit 48c345b

Please sign in to comment.