Skip to content

Commit

Permalink
Merge branch 'release/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
truschival committed May 24, 2021
2 parents 64b9ec7 + 9963664 commit 0c59cd2
Show file tree
Hide file tree
Showing 22 changed files with 118 additions and 114 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/)
# Project Name
MESSAGE( STATUS "Running ${CMAKE_COMMAND} v${CMAKE_VERSION}" )
PROJECT(DigitalRooster
VERSION 1.0.0
VERSION 1.1.0
DESCRIPTION "A digital alarm clock and podcast player"
LANGUAGES CXX C
)
Expand Down
19 changes: 12 additions & 7 deletions include/appconstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ const QString KEY_WIFI_DEV_NAME("net_dev");
*/
const QString RSS_FILE_DIR(QDir::tempPath());

/**
* Default alarm volume
*/
const int DEFAULT_ALARM_VOLUME = 30;

/**
* Minimum percentage of Podcast episode played to be considered 'listened'
*/
Expand All @@ -247,12 +242,17 @@ const std::chrono::milliseconds ALS_SAMPLING_PERIOD(300);
/**
* Default output volume
*/
const int DEFAULT_VOLUME = 30;
const double DEFAULT_VOLUME = 25;

/**
* Default alarm volume
*/
const double DEFAULT_ALARM_VOLUME = 30;

/**
* Default volume for fallback alarm sound
*/
const int DEFAULT_FALLBACK_VOLUME = 50;
const double DEFAULT_FALLBACK_VOLUME = 35;

/**
* Default display brightness
Expand All @@ -271,6 +271,11 @@ const int DEFAULT_ICON_WIDTH = 88;
*/
const int WEATHER_FORECAST_COUNT = 8;

/**
* Step size of volume increment per rotary event
*/
const double VOLUME_INCREMENT = 0.2;

/**
* Where to find icons for weather condition
*/
Expand Down
16 changes: 14 additions & 2 deletions include/brightnesscontrol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class BrightnessControl : public QObject {
Q_OBJECT
Q_PROPERTY(int brightness READ get_brightness NOTIFY brightness_changed)
Q_PROPERTY(int active_brightness READ get_active_brightness WRITE
set_active_brightness)
set_active_brightness NOTIFY active_brightness_changed)
Q_PROPERTY(int standby_brightness READ get_standby_brightness WRITE
set_standby_brightness)
set_standby_brightness NOTIFY standby_brightness_changed)
Q_PROPERTY(bool has_sensor READ has_als_sensor)
Q_PROPERTY(bool feedback READ adaptive_mode WRITE set_adaptive_mode NOTIFY
adaptive_mode_changed)
Expand Down Expand Up @@ -140,6 +140,18 @@ public slots:
*/
void brightness_changed(int perc);

/**
* Change of active brightness setpoint
* @param perc value for dutycycle (0-100%)
*/
void standby_brightness_changed(int perc);

/**
* Change of standby brightness setpoint
* @param perc value for dutycycle (0-100%)
*/
void active_brightness_changed(int perc);

private:
/**
* configuration and data handler
Expand Down
10 changes: 5 additions & 5 deletions include/configuration_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ConfigurationManager : public QObject,
set_standby_brightness)
Q_PROPERTY(int activebrightness READ get_active_brightness WRITE
set_active_brightness)
Q_PROPERTY(int defaultvolume READ get_volume WRITE set_volume)
Q_PROPERTY(double defaultvolume READ get_volume WRITE set_volume)

public:
/**
Expand Down Expand Up @@ -87,7 +87,7 @@ class ConfigurationManager : public QObject,
* current linear volume
* @return volume 0..100
*/
int get_volume() const {
double get_volume() const {
return do_get_volume();
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public slots:
* volume settings changed -> store
* @param vol new volume settings (0..100)
*/
void set_volume(int vol);
void set_volume(double vol);

/**
* user changed standby brightness
Expand Down Expand Up @@ -263,7 +263,7 @@ public slots:
/**
* Linear Volume in percent (stored in config file)
*/
int volume;
double volume;

/**
* display brightness (0..100%) in standby mode
Expand Down Expand Up @@ -395,7 +395,7 @@ public slots:
/**
* Private virtual interface for volume settings
*/
virtual int do_get_volume() const {
virtual double do_get_volume() const {
return volume;
};

Expand Down
16 changes: 8 additions & 8 deletions include/mediaplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MediaPlayer : public QObject {
Q_PROPERTY(qint64 position READ get_position NOTIFY position_changed)
Q_PROPERTY(qint64 duration READ get_duration NOTIFY duration_changed)
Q_PROPERTY(
int volume READ get_volume WRITE set_volume NOTIFY volume_changed)
double volume READ get_volume WRITE set_volume NOTIFY volume_changed)
Q_PROPERTY(bool muted READ muted WRITE set_muted NOTIFY muted_changed)
Q_PROPERTY(bool seekable READ seekable NOTIFY seekable_changed)
Q_PROPERTY(QMediaPlayer::MediaStatus mediaStatus READ media_status NOTIFY
Expand All @@ -42,7 +42,7 @@ class MediaPlayer : public QObject {
virtual ~MediaPlayer() = default;

bool muted() const;
int get_volume() const;
double get_volume() const;
void set_muted(bool muted);

bool seekable() const;
Expand All @@ -68,12 +68,12 @@ public slots:
* Set linear volume value to
* @param volume 0..100%
*/
void set_volume(int volume);
void set_volume(double volume);
/**
* increment/decrement linear volume by increment percent
* @param increment percentage to change volume
*/
void increment_volume(int increment);
void increment_volume(double increment);

void pause();
void play();
Expand All @@ -86,7 +86,7 @@ public slots:
* volume has changed
* @param volume linear volume value 0..100 %
*/
void volume_changed(int volume);
void volume_changed(double volume);

void muted_changed(bool muted);
void seekable_changed(bool seekable);
Expand All @@ -103,7 +103,7 @@ public slots:
*/
virtual bool is_seekable() const = 0;
virtual bool is_muted() const = 0;
virtual int do_get_volume() const = 0;
virtual double do_get_volume() const = 0;
virtual qint64 do_get_duration() const = 0;
virtual qint64 do_get_position() const = 0;
virtual QMediaPlayer::MediaStatus do_media_status() const = 0;
Expand All @@ -114,8 +114,8 @@ public slots:
virtual void do_set_playlist(QMediaPlaylist* playlist) = 0;
virtual void do_set_position(qint64 position) = 0;
virtual void do_set_muted(bool muted) = 0;
virtual void do_set_volume(int volume) = 0;
virtual void do_increment_volume(int increment) = 0;
virtual void do_set_volume(double volume) = 0;
virtual void do_increment_volume(double increment) = 0;
virtual void do_seek(qint64 incr) = 0;
virtual void do_pause() = 0;
virtual void do_play() = 0;
Expand Down
8 changes: 4 additions & 4 deletions include/mediaplayerproxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MediaPlayerProxy : public MediaPlayer {
private:
virtual bool is_seekable() const override;
virtual bool is_muted() const override;
virtual int do_get_volume() const override;
virtual double do_get_volume() const override;
virtual qint64 do_get_duration() const override;
virtual qint64 do_get_position() const override;
virtual QMediaPlayer::MediaStatus do_media_status() const override;
Expand All @@ -60,8 +60,8 @@ class MediaPlayerProxy : public MediaPlayer {
virtual void do_set_playlist(QMediaPlaylist* playlist) override;
virtual void do_set_position(qint64 position) override;
virtual void do_set_muted(bool muted) override;
virtual void do_set_volume(int volume) override;
virtual void do_increment_volume(int increment) override;
virtual void do_set_volume(double volume) override;
virtual void do_increment_volume(double increment) override;
virtual void do_seek(qint64 incr) override;
virtual void do_pause() override;
virtual void do_play() override;
Expand All @@ -77,7 +77,7 @@ class MediaPlayerProxy : public MediaPlayer {
* Linear volume 0..100%
* Initialized because increment/decrement has to work with some value
*/
int linear_volume = 0;
double linear_volume = 0;

/**
* The actual player implementation
Expand Down
7 changes: 0 additions & 7 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ QUrl valid_url_from_string(const QString& urlstr);
*/
QUuid valid_uuid_from_String(const QString& uuidstr);

/**
* Simple check if value is in range 0-100 used for positive
* Integer range like volume percentage, brightness percentage....
* @param value to check
* @return value>=0 && value <=100
*/
bool value_in_0_100(int value);

} // namespace DigitalRooster
#endif /* INCLUDE_UTIL_HPP_ */
2 changes: 1 addition & 1 deletion include/volume_button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public slots:
/**
* volume was incremented/decremented by increment
*/
void volume_incremented(int increment);
void volume_incremented(double increment);
/**
* Push button was/is pressed
*/
Expand Down
2 changes: 1 addition & 1 deletion include/weather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class WeatherStatus : public QObject {
class Weather : public QObject {
Q_OBJECT
Q_PROPERTY(QString city READ get_city NOTIFY city_updated)
Q_PROPERTY(float temp READ get_temperature NOTIFY temperature_changed)
Q_PROPERTY(double temp READ get_temperature NOTIFY temperature_changed)
Q_PROPERTY(QUrl weatherIcon READ get_weather_icon_url NOTIFY icon_changed)
public:
/**
Expand Down
3 changes: 3 additions & 0 deletions libsrc/brightnesscontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ void BrightnessControl::als_value_changed(Hal::AlsValue brightness) {

/*****************************************************************************/
void BrightnessControl::set_active_brightness(int brightness) {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
cm.set_active_brightness(brightness);
emit active_brightness_changed(brightness);
if (!adaptive_mode()) {
update_backlight();
}
Expand All @@ -135,6 +137,7 @@ void BrightnessControl::set_active_brightness(int brightness) {
void BrightnessControl::set_standby_brightness(int brightness) {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
cm.set_standby_brightness(brightness);
emit standby_brightness_changed(brightness);
if (!adaptive_mode()) {
update_backlight();
}
Expand Down
26 changes: 7 additions & 19 deletions libsrc/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void ConfigurationManager::parse_json(const QByteArray& json) {

enable_backlight_control(appconfig[KEY_BACKLIGHT_CONTROL].toBool(true));

set_volume(appconfig[KEY_VOLUME].toInt(DEFAULT_VOLUME));
set_volume(appconfig[KEY_VOLUME].toDouble(DEFAULT_VOLUME));

set_sleep_timeout(std::chrono::minutes(
appconfig[KEY_SLEEP_TIMEOUT].toInt(DEFAULT_SLEEP_TIMEOUT.count())));
Expand Down Expand Up @@ -298,35 +298,23 @@ void ConfigurationManager::fileChanged(const QString& path) {
}

/*****************************************************************************/
void ConfigurationManager::set_volume(int vol) {
void ConfigurationManager::set_volume(double vol) {
qCDebug(CLASS_LC) << Q_FUNC_INFO << vol;
if (value_in_0_100(vol)) {
this->volume = vol;
dirty = true;
} else {
qCWarning(CLASS_LC) << "invalid volume value: " << vol;
}
this->volume = std::clamp(vol, 0.0, 100.0);
dirty = true;
}

/*****************************************************************************/
void ConfigurationManager::set_standby_brightness(int brightness) {
qCDebug(CLASS_LC) << Q_FUNC_INFO << brightness;
if (value_in_0_100(brightness)) {
this->brightness_sb = brightness;
dirty = true;
} else {
qCWarning(CLASS_LC) << "invalid brightness value: " << brightness;
}
this->brightness_sb = std::clamp(brightness, 0, 100);
dirty = true;
}

/*****************************************************************************/
void ConfigurationManager::set_active_brightness(int brightness) {
qCDebug(CLASS_LC) << Q_FUNC_INFO << brightness;
if (value_in_0_100(brightness)) {
do_set_brightness_act(brightness);
} else {
qCWarning(CLASS_LC) << "invalid brightness value: " << brightness;
}
do_set_brightness_act(std::clamp(brightness, 0, 100));
}

/*****************************************************************************/
Expand Down
12 changes: 4 additions & 8 deletions libsrc/mediaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool MediaPlayer::muted() const {
}

/*****************************************************************************/
int MediaPlayer::get_volume() const {
double MediaPlayer::get_volume() const {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
return do_get_volume();
}
Expand All @@ -32,17 +32,13 @@ void MediaPlayer::set_muted(bool muted) {
}

/*****************************************************************************/
void MediaPlayer::set_volume(int volume) {
void MediaPlayer::set_volume(double volume) {
qCDebug(CLASS_LC) << Q_FUNC_INFO << volume;
if (!value_in_0_100(volume)) {
qCWarning(CLASS_LC) << "invalid volume (must be 0..100%)";
return;
}
return do_set_volume(volume);
return do_set_volume(std::clamp(volume, 0.0, 100.0));
}

/*****************************************************************************/
void MediaPlayer::increment_volume(int increment) {
void MediaPlayer::increment_volume(double increment) {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
return do_increment_volume(increment);
}
Expand Down
7 changes: 3 additions & 4 deletions libsrc/mediaplayerproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ bool MediaPlayerProxy::is_muted() const {
}

/*****************************************************************************/
int MediaPlayerProxy::do_get_volume() const {
double MediaPlayerProxy::do_get_volume() const {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
return linear_volume;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ QMediaPlayer::State MediaPlayerProxy::do_playback_state() const {
}

/*****************************************************************************/
void MediaPlayerProxy::do_set_volume(int volume) {
void MediaPlayerProxy::do_set_volume(double volume) {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
linear_volume = volume;
emit volume_changed(volume);
Expand All @@ -223,9 +223,8 @@ void MediaPlayerProxy::do_set_volume(int volume) {
}

/*****************************************************************************/
void MediaPlayerProxy::do_increment_volume(int increment) {
void MediaPlayerProxy::do_increment_volume(double increment) {
qCDebug(CLASS_LC) << Q_FUNC_INFO << increment;
qCDebug(CLASS_LC) << " current volume" << linear_volume;
set_volume(linear_volume + increment);
}

Expand Down
5 changes: 0 additions & 5 deletions libsrc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,5 @@ QUuid valid_uuid_from_String(const QString& uuidstr) {
return id;
}

/*****************************************************************************/
bool value_in_0_100(int value) {
return (value >= 0 && value <= 100);
}

/*****************************************************************************/
} // namespace DigitalRooster
Loading

0 comments on commit 0c59cd2

Please sign in to comment.