Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
Fixed linting, updated comment and changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Feb 12, 2022
1 parent e7f9b6d commit 260a43e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0] - 2022-02-12

### Added
- Support for the _Battery1_ interface. _(Thanks ptenbrock!)_

## [0.1.1] - 2021-12-28

### Added
Expand Down
7 changes: 3 additions & 4 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ std::shared_ptr<SimpleDBus::Proxy> Device::path_create(const std::string& path)
std::shared_ptr<SimpleDBus::Interface> Device::interfaces_create(const std::string& interface_name) {
if (interface_name == "org.bluez.Device1") {
return std::static_pointer_cast<SimpleDBus::Interface>(std::make_shared<Device1>(_conn, _path));
}
else if (interface_name == "org.bluez.Battery1") {
} else if (interface_name == "org.bluez.Battery1") {
return std::static_pointer_cast<SimpleDBus::Interface>(std::make_shared<Battery1>(_conn, _path));
}

Expand Down Expand Up @@ -84,8 +83,8 @@ uint8_t Device::read_battery_percentage() { return battery1()->Percentage(); }

void Device::set_on_battery_percentage_changed(std::function<void(uint8_t new_value)> callback) {
battery1()->OnPercentageChanged.load([this, callback]() { callback(battery1()->Percentage()); });
// property_changed signal for percentage only occurs when the value actually changes
// -> notify callback at least once (on register), as this might not happen for a long time otherwise
// As the `property_changed` callback only occurs when the property is changed, we need to manually
// call the callback once to make sure the callback is called with the current value.
battery1()->OnPercentageChanged();
}

Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/Battery1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ using namespace SimpleBluez;
Battery1::Battery1(std::shared_ptr<SimpleDBus::Connection> conn, std::string path)
: SimpleDBus::Interface(conn, "org.bluez", path, "org.bluez.Battery1") {}

Battery1::~Battery1() {
OnPercentageChanged.unload();
}
Battery1::~Battery1() { OnPercentageChanged.unload(); }

uint8_t Battery1::Percentage() {
std::scoped_lock lock(_property_update_mutex);
Expand Down

0 comments on commit 260a43e

Please sign in to comment.