Skip to content

Commit

Permalink
Fixing energy and time calculations for Mac OS (closing #8, #11 and #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
svartalf committed Feb 27, 2019
1 parent 852aa24 commit 8ad3106
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 140 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ before_install:
- cargo install --force cross
- rustup component add clippy

script:
- cross build --target=${TARGET} --release
- cross clippy --release -- -D warnings
script: ci/script.sh

notifications:
email:
Expand Down
13 changes: 0 additions & 13 deletions CHANGELOG.md

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Latest Version](https://img.shields.io/crates/v/battery.svg)](https://crates.io/crates/battery)
[![Latest Version](https://docs.rs/battery/badge.svg)](https://docs.rs/battery)
[![Build Status](https://travis-ci.org/svartalf/rust-battery.svg?branch=master)](https://travis-ci.org/svartalf/rust-battery)
[![dependency status](https://deps.rs/crate/battery/0.6.0/status.svg)](https://deps.rs/crate/battery/0.6.0)
[![dependency status](https://deps.rs/crate/battery/0.6.1/status.svg)](https://deps.rs/crate/battery/0.6.1)
![Apache 2.0 OR MIT licensed](https://img.shields.io/badge/license-Apache2.0%2FMIT-blue.svg)

Rust crate providing cross-platform information about batteries.
Expand Down
4 changes: 2 additions & 2 deletions battery-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "battery-cli"
version = "0.1.1"
version = "0.1.2"
authors = ["svartalf <self@svartalf.info>"]
edition = "2018"
description = "CLI tool for batteries reports"
Expand All @@ -25,7 +25,7 @@ test = false
cfg-if = "0.1"

[target.'cfg(not(windows))'.dependencies]
battery = { path = "../battery" }
battery = "0.6.1"
humantime = "1.2.0"
tui = "0.4.0"
termion = "1.5.1"
Expand Down
2 changes: 1 addition & 1 deletion battery-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Latest Version](https://img.shields.io/crates/v/battery-cli.svg)](https://crates.io/crates/battery-cli)
[![Latest Version](https://docs.rs/battery-cli/badge.svg)](https://docs.rs/battery-cli)
[![Build Status](https://travis-ci.org/svartalf/rust-battery.svg?branch=master)](https://travis-ci.org/svartalf/rust-battery)
[![dependency status](https://deps.rs/crate/battery-cli/0.1.0/status.svg)](https://deps.rs/crate/battery-cli/0.1.0)
[![dependency status](https://deps.rs/crate/battery-cli/0.1.2/status.svg)](https://deps.rs/crate/battery-cli/0.1.2)
![Apache 2.0 OR MIT licensed](https://img.shields.io/badge/license-Apache2.0%2FMIT-blue.svg)

`battery-cli` is a Proof-Of-Concept binary crate, that provides terminal user interface
Expand Down
17 changes: 11 additions & 6 deletions battery-cli/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use tui::layout::*;
use tui::style::*;
use tui::widgets::*;

use battery::Battery;
use battery::{Battery, State};

use crate::ui::app::BatteryStats;
use crate::ui::util::event::{Event, Events};
Expand Down Expand Up @@ -208,7 +208,7 @@ fn draw_common_information<B>(f: &mut Frame<B>, area: Rect, battery: &Battery) w
Table::new(header.iter(), rows)
.header_style(Style::default().fg(Color::DarkGray))
.block(block)
.widths(&[15, 20])
.widths(&[17, 17])
.render(f, area);
}

Expand All @@ -222,8 +222,13 @@ fn draw_energy_information<B>(f: &mut Frame<B>, area: Rect, battery: &Battery) w
let current = &format!("{:.2} Wh", battery.energy() as f32 / 1000.0);
let last_full = &format!("{:.2} Wh", battery.energy_full() as f32 / 1000.0);
let full_design = &format!("{:.2} Wh", battery.energy_full_design() as f32 / 1000.0);
let consumption_label = match battery.state() {
State::Charging => "Charging with",
State::Discharging => "Discharging with",
_ => "Consumption",
};
let items = vec![
vec!["Consumption", consumption],
vec![consumption_label, consumption],
vec!["Voltage", voltage],
vec!["Capacity", capacity],
vec!["Current", current],
Expand All @@ -239,7 +244,7 @@ fn draw_energy_information<B>(f: &mut Frame<B>, area: Rect, battery: &Battery) w
Table::new(header.iter(), rows)
.header_style(Style::default().fg(Color::DarkGray))
.block(block)
.widths(&[15, 20])
.widths(&[17, 17])
.render(f, area);
}

Expand Down Expand Up @@ -269,7 +274,7 @@ fn draw_time_information<B>(f: &mut Frame<B>, area: Rect, battery: &Battery) whe
Table::new(header.iter(), rows)
.header_style(Style::default().fg(Color::DarkGray))
.block(block)
.widths(&[15, 20])
.widths(&[17, 17])
.render(f, area);
}

Expand All @@ -293,6 +298,6 @@ fn draw_env_information<B>(f: &mut Frame<B>, area: Rect, battery: &Battery) wher
Table::new(header.iter(), rows)
.header_style(Style::default().fg(Color::DarkGray))
.block(block)
.widths(&[15, 20])
.widths(&[17, 17])
.render(f, area);
}
4 changes: 2 additions & 2 deletions battery-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "battery-ffi"
version = "0.1.3"
version = "0.1.4"
authors = ["svartalf <self@svartalf.info>"]
edition = "2018"
description = "FFI bindings for battery crate"
Expand All @@ -22,7 +22,7 @@ crate-type = ["cdylib"]
default = ["cbindgen"]

[dependencies]
battery = { path = "../battery" }
battery = "0.6.1"
libc = "0.2.48"

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion battery-ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Latest Version](https://img.shields.io/crates/v/battery-ffi.svg)](https://crates.io/crates/battery-ffi)
[![Latest Version](https://docs.rs/battery-ffi/badge.svg)](https://docs.rs/battery-ffi)
[![Build Status](https://travis-ci.org/svartalf/rust-battery.svg?branch=master)](https://travis-ci.org/svartalf/rust-battery)
[![dependency status](https://deps.rs/crate/battery-ffi/0.1.2/status.svg)](https://deps.rs/crate/battery-ffi/0.1.2)
[![dependency status](https://deps.rs/crate/battery-ffi/0.1.4/status.svg)](https://deps.rs/crate/battery-ffi/0.1.4)
![Apache 2.0 OR MIT licensed](https://img.shields.io/badge/license-Apache2.0%2FMIT-blue.svg)

This is a FFI bindings for [battery](https://github.com/svartalf/rust-battery/tree/master/battery)
Expand Down
14 changes: 14 additions & 0 deletions battery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

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.6.1] - 2019-02-27
### Fixed
- Fix energy and remaining time calculations for MacOS [#8](https://github.com/svartalf/rust-battery/issues/8), [#11](https://github.com/svartalf/rust-battery/pull/11)
- Fix multiplication overflow while calculating battery percentage in Mac OS by [@mindriot101](https://github.com/mindriot101) [#10](https://github.com/svartalf/rust-battery/pull/10)
- Fix wrong units for consumption graph in `battery-cli`, should be `W` instead of `Wh` [#9](https://github.com/svartalf/rust-battery/issues/9)
- Fix non-uniform path import that was breaking compilation for Rust<1.32 [#6](https://github.com/svartalf/rust-battery/issues/6)
- Fix `time_to_empty` and `time_to_full` calculations for Linux when charger is unplugged but driver still reports zero `energy_rate` by [@kerhong](https://github.com/kerhong) [#5](https://github.com/svartalf/rust-battery/pull/5)
5 changes: 2 additions & 3 deletions battery/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[package]
name = "battery"
version = "0.6.0"
version = "0.6.1"
authors = ["svartalf <self@svartalf.info>"]
edition = "2018"
description = "Cross-platform information about batteries"
repository = "https://github.com/svartalf/rust-battery"
readme = "README.md"
categories = ["os"]
keywords = ["battery", "linux", "macos", "windows", "freebsd", "dragonflybsd"]
keywords = ["battery", "linux", "macos", "windows", "freebsd"]
license = "Apache-2.0 OR MIT"
build = "build.rs"

[badges]
travis-ci = { repository = "svartalf/rust-battery", branch = "master" }
Expand Down
Loading

0 comments on commit 8ad3106

Please sign in to comment.