RedInfoBat read current battery capacity



Only works on newer portable Mac models running OS X (10.4 or newer).


see also: RedInfoLmu RedInfoSms


*kr(trig)

returns battery capacity in percent.

-1 if battery no installed.

trig asks for a new reading.  the maximum reading rate internally is 2Hz.

note: there is only one reading function internally.  a trigger will cause global reading for all ugens.

it makes little sense to have this ugen running in multiple synths.  use busses.



//--

s.boot;

{RedInfoBat.kr(Impulse.kr(0.1)).poll}.play; //update every 10 second



//idea: use as master tuning



//--gui test

(

s.waitForBoot{

var w= Window("RedInfoBat test", Rect(100, 200, 300, 120));

var c= [0, 1, 'lin', 0, 0].asSpec;

var b= EZSlider(w, Rect(0, 10, 280, 20), "battery", c);

w.view.background= Color.red(0.75);

w.front;

SynthDef(\batterycapacity, {|rate= 0.1| //update rate

var trig= Impulse.kr(rate);

SendReply.kr(trig, 'b', RedInfoBat.kr(trig));

}).play(s);

OSCresponder(s.addr, 'b', {|t, resp, m|

{

b.value= m[3];

}.defer;

}).add;

}

)