iStats 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6913998ec242b341ef22e43871298eb7243cef8
4
- data.tar.gz: 7e0fd04af5cce3fabc6579cf7d63034dc71d7989
3
+ metadata.gz: 01ef0dfa872c16561636ee9ffd55048b59b3bba9
4
+ data.tar.gz: 374f759ee22e0a411c17658ff7474d8bd7b305c1
5
5
  SHA512:
6
- metadata.gz: 39a0743e11c8dd9b5525f3af948d4eb1419df421583bd4a4f6afe241a019ec0c998a09cd62dc10064402c928ac9d578952ebfab9f2800acee27d74ebdf3b8b92
7
- data.tar.gz: 6d7e68b9a86b0435e4d2c2d18030ce443a90dcd6f4915e4d083d714509e63dc4cedf5fd6d00be151c74f2eeec6fdf5fef51fd6e0497537e7b64f319450e5601f
6
+ metadata.gz: 6e50c705d65d13ea355be98fd7666b7df415fb403973ea3bc1243c07d38b347b91130f519bddad0b43bd90587a723b63976732a14734c1281b51f37cf1a61187
7
+ data.tar.gz: ee65277dd9c6aafb455200f912d1f5acd0c7e1dc0631b866d5413fb579c01de3a7e2ea05d121a190465db8c01de9c1a9ee447d0c9d0397c642359db4266a67e7
data/README.md CHANGED
@@ -3,17 +3,16 @@ iStats [![Gem Version](https://badge.fury.io/rb/iStats.svg)](http://badge.fury.i
3
3
 
4
4
  iStats is a command-line tool that allows you to easily grab the CPU temperature, fan speeds and battery information on OS X. If you'd like to see more data available feel free to open an issue.
5
5
 
6
- #### Warning
7
- A [bug in Ruby](https://bugs.ruby-lang.org/issues/9624) and Apple XCode 5.1 onwards (new CLANG version) might make it impossible to install this gem if you are using Ruby from the Xcode command-line tools package. If you are using RVM or homebrew to manage your Ruby installation you should be fine.
8
-
9
- #### Tested on
10
- MacBook Pro 2012<br>
11
- OS X 10.9.2<br>
12
- Ruby: 1.9.3, 2.0.0, 2.1.1<br>
13
-
14
6
  ## Installation
15
7
 
16
8
  $ gem install iStats
9
+
10
+ #### Warning
11
+ **This is now fixed with the release of OS X 10.9.3**<br>
12
+ A [bug in Ruby](https://bugs.ruby-lang.org/issues/9624) and Apple XCode 5.1 onwards (new CLANG version) might make it impossible to install this gem if you are using Ruby from the Xcode command-line tools package. If you see an error when the gem is building the native extension try to use this command to install iStats: <br>
13
+ `sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install iStats`<br>
14
+ If you are using RVM or homebrew to manage your Ruby installation you should be fine.
15
+
17
16
 
18
17
  ## Screenshot
19
18
  #### All Stats
@@ -39,6 +38,8 @@ Ruby: 1.9.3, 2.0.0, 2.1.1<br>
39
38
  istats battery [health] Print battery health
40
39
  istats battery [cycleCount | cc] Print battery cycle count info
41
40
  istats battery [temp | temperature] Print battery temperature
41
+ istats battery [time | remain] Print battery time remaining
42
+ istats battery [charge] Print battery charge
42
43
 
43
44
  for more help see: https://github.com/Chris911/iStats
44
45
  ```
@@ -50,3 +51,8 @@ Ruby: 1.9.3, 2.0.0, 2.1.1<br>
50
51
  3. Commit your changes (`git commit -am 'Add some feature'`)
51
52
  4. Push to the branch (`git push origin my-new-feature`)
52
53
  5. Create new Pull Request
54
+
55
+ #### Tested on
56
+ MacBook Pro 2012<br>
57
+ OS X 10.9.2<br>
58
+ Ruby: 1.9.3, 2.0.0, 2.1.1<br>
@@ -22,6 +22,8 @@
22
22
  #include <ruby.h>
23
23
  #include <CoreFoundation/CoreFoundation.h>
24
24
  #include <IOKit/IOKitLib.h>
25
+ #include <IOKit/ps/IOPSKeys.h>
26
+ #include <IOKit/ps/IOPowerSources.h>
25
27
 
26
28
  #include "smc.h"
27
29
 
@@ -283,6 +285,36 @@ const char* getBatteryHealth() {
283
285
  return batteryHealth;
284
286
  }
285
287
 
288
+ const int hasBattery() {
289
+ CFDictionaryRef powerSourceInformation = powerSourceInfo(0);
290
+ return !(powerSourceInformation == NULL);
291
+ }
292
+
293
+ int getBatteryCharge() {
294
+ CFNumberRef currentCapacity;
295
+ CFNumberRef maximumCapacity;
296
+
297
+ int iCurrentCapacity;
298
+ int iMaximumCapacity;
299
+ int charge;
300
+
301
+ CFDictionaryRef powerSourceInformation;
302
+
303
+ powerSourceInformation = powerSourceInfo(0);
304
+ if (powerSourceInformation == NULL)
305
+ return 0;
306
+
307
+ currentCapacity = CFDictionaryGetValue(powerSourceInformation, CFSTR(kIOPSCurrentCapacityKey));
308
+ maximumCapacity = CFDictionaryGetValue(powerSourceInformation, CFSTR(kIOPSMaxCapacityKey));
309
+
310
+ CFNumberGetValue(currentCapacity, kCFNumberIntType, &iCurrentCapacity);
311
+ CFNumberGetValue(maximumCapacity, kCFNumberIntType, &iMaximumCapacity);
312
+
313
+ charge = (float)iCurrentCapacity / iMaximumCapacity * 100;
314
+
315
+ return charge;
316
+ }
317
+
286
318
  /*
287
319
  RUBY MODULES
288
320
  */
@@ -302,9 +334,12 @@ void Init_osx_stats() {
302
334
  rb_define_method(FAN_STATS, "get_fan_speed", method_get_fan_speed, 1);
303
335
 
304
336
  BATTERY_STATS = rb_define_module("BATTERY_STATS");
337
+ rb_define_method(BATTERY_STATS, "has_battery?", method_has_battery, 0);
305
338
  rb_define_method(BATTERY_STATS, "get_battery_health", method_get_battery_health, 0);
306
339
  rb_define_method(BATTERY_STATS, "get_battery_design_cycle_count", method_get_battery_design_cycle_count, 0);
307
340
  rb_define_method(BATTERY_STATS, "get_battery_temp", method_get_battery_temp, 0);
341
+ rb_define_method(BATTERY_STATS, "get_battery_time_remaining", method_get_battery_time_remaining, 0);
342
+ rb_define_method(BATTERY_STATS, "get_battery_charge", method_get_battery_charge, 0);
308
343
  }
309
344
 
310
345
  VALUE method_get_cpu_temp(VALUE self) {
@@ -332,6 +367,10 @@ VALUE method_get_fan_speed(VALUE self, VALUE num) {
332
367
  return rb_float_new(speed);
333
368
  }
334
369
 
370
+ VALUE method_has_battery(VALUE self) {
371
+ return hasBattery() ? Qtrue : Qfalse;
372
+ }
373
+
335
374
  VALUE method_get_battery_health(VALUE self) {
336
375
  const char* health = getBatteryHealth();
337
376
  return rb_str_new2(health);
@@ -350,6 +389,30 @@ VALUE method_get_battery_temp(VALUE self) {
350
389
  return rb_float_new(temp);
351
390
  }
352
391
 
392
+ VALUE method_get_battery_time_remaining(VALUE self) {
393
+ CFTimeInterval time_remaining;
394
+
395
+ time_remaining = IOPSGetTimeRemainingEstimate();
396
+
397
+ if (time_remaining == kIOPSTimeRemainingUnknown) {
398
+ return rb_str_new2("Calculating");
399
+ } else if (time_remaining == kIOPSTimeRemainingUnlimited) {
400
+ return rb_str_new2("Unlimited");
401
+ } else {
402
+ return INT2NUM(time_remaining);
403
+ }
404
+ }
405
+
406
+ VALUE method_get_battery_charge(VALUE self) {
407
+ int charge = getBatteryCharge();
408
+
409
+ if (charge == 0) {
410
+ return Qnil;
411
+ } else {
412
+ return INT2NUM(charge);
413
+ }
414
+ }
415
+
353
416
  /* Main method used for test */
354
417
  // int main(int argc, char *argv[])
355
418
  // {
@@ -70,24 +70,24 @@ typedef struct {
70
70
  typedef char SMCBytes_t[32];
71
71
 
72
72
  typedef struct {
73
- UInt32 key;
74
- SMCKeyData_vers_t vers;
75
- SMCKeyData_pLimitData_t pLimitData;
76
- SMCKeyData_keyInfo_t keyInfo;
77
- char result;
78
- char status;
79
- char data8;
80
- UInt32 data32;
81
- SMCBytes_t bytes;
73
+ UInt32 key;
74
+ SMCKeyData_vers_t vers;
75
+ SMCKeyData_pLimitData_t pLimitData;
76
+ SMCKeyData_keyInfo_t keyInfo;
77
+ char result;
78
+ char status;
79
+ char data8;
80
+ UInt32 data32;
81
+ SMCBytes_t bytes;
82
82
  } SMCKeyData_t;
83
83
 
84
84
  typedef char UInt32Char_t[5];
85
85
 
86
86
  typedef struct {
87
- UInt32Char_t key;
88
- UInt32 dataSize;
89
- UInt32Char_t dataType;
90
- SMCBytes_t bytes;
87
+ UInt32Char_t key;
88
+ UInt32 dataSize;
89
+ UInt32Char_t dataType;
90
+ SMCBytes_t bytes;
91
91
  } SMCVal_t;
92
92
 
93
93
  // prototypes
@@ -96,6 +96,7 @@ int SMCGetFanNumber(char *key);
96
96
  double SMCGetTemperature(char *key);
97
97
  const char* getBatteryHealth();
98
98
  int getDesignCycleCount();
99
+ int getBatteryCharge();
99
100
  CFTypeRef IOPSCopyPowerSourcesInfo(void);
100
101
  CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob);
101
102
  CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
@@ -105,6 +106,9 @@ void Init_osx_stats();
105
106
  VALUE method_get_cpu_temp(VALUE self);
106
107
  VALUE method_get_fan_speed(VALUE self, VALUE num);
107
108
  VALUE method_get_fan_number(VALUE self);
109
+ VALUE method_has_battery(VALUE self);
108
110
  VALUE method_get_battery_health(VALUE self);
109
111
  VALUE method_get_battery_design_cycle_count(VALUE self);
110
112
  VALUE method_get_battery_temp(VALUE self);
113
+ VALUE method_get_battery_time_remaining(VALUE self);
114
+ VALUE method_get_battery_charge(VALUE self);
@@ -9,6 +9,9 @@ module IStats
9
9
  # Delegate CLI command to function
10
10
  #
11
11
  def delegate(stat)
12
+ # Before we deletage check if there's a battery on system
13
+ return unless validate_battery
14
+
12
15
  case stat
13
16
  when 'all'
14
17
  all
@@ -18,6 +21,10 @@ module IStats
18
21
  battery_health
19
22
  when 'cycle_count', 'cc'
20
23
  cycle_count
24
+ when 'time', 'remain'
25
+ battery_time_remaining
26
+ when 'charge'
27
+ battery_charge
21
28
  else
22
29
  Command.help "Unknown stat for Battery: #{stat}"
23
30
  end
@@ -26,6 +33,8 @@ module IStats
26
33
  # Call all functions (stats)
27
34
  #
28
35
  def all
36
+ return unless validate_battery
37
+
29
38
  battery_health
30
39
  battery_temperature
31
40
  cycle_count
@@ -60,12 +69,39 @@ module IStats
60
69
  puts "Battery health: #{get_battery_health}"
61
70
  end
62
71
 
72
+ def battery_time_remaining
73
+ time = get_battery_time_remaining
74
+
75
+ if time.is_a? Integer
76
+ hours = time / 3600
77
+ minutes = time / 60 - hours * 60
78
+
79
+ time = "%i:%02i" % [hours, minutes]
80
+ end
81
+
82
+ puts "Battery time remaining: #{time}"
83
+ end
84
+
85
+ def battery_charge
86
+ charge = get_battery_charge
87
+ result = charge ? "#{charge}%" : "Unknown"
88
+ puts "Battery charge: #{result}"
89
+ end
90
+
63
91
  # Get the battery design cycle count
64
92
  # Calls a C method from BATTERY_STATS module
65
93
  #
66
94
  def design_cycle_count
67
95
  get_battery_design_cycle_count
68
96
  end
97
+
98
+ # Check if there's a battery on the system
99
+ #
100
+ def validate_battery
101
+ valid = has_battery?
102
+ puts 'No battery on system' unless valid
103
+ valid
104
+ end
69
105
  end
70
106
  end
71
107
  end
@@ -91,8 +91,10 @@ module IStats
91
91
  istats fan [speed] Print fan speed
92
92
  istats battery Print all battery stats
93
93
  istats battery [health] Print battery health
94
+ istats battery [time | remain] Print battery time remaining
94
95
  istats battery [cycleCount | cc] Print battery cycle count info
95
96
  istats battery [temp | temperature] Print battery temperature
97
+ istats battery [charge] Print battery charge
96
98
 
97
99
  for more help see: https://github.com/Chris911/iStats
98
100
  ".gsub(/^ {8}/, '') # strip the first eight spaces of every line
@@ -1,3 +1,3 @@
1
1
  module IStats
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iStats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris911
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sparkr