From 931f134eeca5a1cd75993fc4bb0ed299ee1e0ac0 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 24 Oct 2009 06:13:56 +0000 Subject: added the ability to query anything and made two patches based on that to get specific info: cpu temp and fan info svn path=/trunk/externals/apple/; revision=12659 --- cpu_temperature-help.pd | 43 ++++++++++++++++++++++++++++++++ cpu_temperature.pd | 10 ++++++++ fans-help.pd | 60 +++++++++++++++++++++++++++++++++++++++++++++ fans.pd | 48 ++++++++++++++++++++++++++++++++++++ smc-help.pd | 57 +++++++++++++++++++++++-------------------- smc.c | 65 +++++++++++++++++++++++++++++-------------------- 6 files changed, 230 insertions(+), 53 deletions(-) create mode 100644 cpu_temperature-help.pd create mode 100644 cpu_temperature.pd create mode 100644 fans-help.pd create mode 100644 fans.pd diff --git a/cpu_temperature-help.pd b/cpu_temperature-help.pd new file mode 100644 index 0000000..5213558 --- /dev/null +++ b/cpu_temperature-help.pd @@ -0,0 +1,43 @@ +#N canvas 259 213 560 421 10; +#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header cpu_temperature +3 12 0 18 -241536 -1 0; +#X obj 3 189 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlet 15 12 0 13 +-245500 -191407 0; +#N canvas 779 22 494 344 META 0; +#X text 12 25 KEYWORDS control number float store; +#X text 12 45 LICENSE GPL; +#X text 12 65 TEMPLATE template-help.pd v0.1; +#X text 12 85 PLATFORM windows macosx gnulinux; +#X text 12 105 DATATYPE float list; +#X text 12 125 LIBRARY internal; +#X text 12 145 WEBSITE http://crca.ucsd.edu/~msp/; +#X text 12 165 RELEASE_DATE 2007-08-24; +#X text 12 185 RELEASE_VERSION 0.40-test05; +#X text 12 5 GENRE storage; +#X restore 500 373 pd META; +#X obj 3 258 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 15 12 0 +13 -245500 -191407 0; +#X obj 3 338 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15 +12 0 13 -245500 -191407 0; +#X obj 374 6 pddp/pddplink http://wiki.puredata.info/en/apple/cpu_temperature +-text pdpedia: cpu_temperature; +#X obj 104 364 pddp/pddplink http://www.osxbook.com/book/bonus/chapter10/light/ +; +#X text 102 208 bang - output current screen brightness; +#X obj 389 -14 apple/cpu_temperature; +#X msg 146 48 bang; +#X obj 73 73 metro 250; +#X obj 73 54 tgl 15 0 empty empty empty 0 -6 0 10 -204786 -1 -1 0 1 +; +#X text 183 46 output sensor values; +#X obj 72 279 cnv 17 3 20 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 +-162280 0; +#X text 103 276 list - a list with the values of the left and right +sensors; +#X floatatom 146 144 5 0 0 0 - - -; +#X obj 146 101 apple/cpu_temperature; +#X text 15 6 description: query the CPU temperature in Apples; +#X connect 9 0 16 0; +#X connect 10 0 16 0; +#X connect 11 0 10 0; +#X connect 16 0 15 0; diff --git a/cpu_temperature.pd b/cpu_temperature.pd new file mode 100644 index 0000000..413fcbe --- /dev/null +++ b/cpu_temperature.pd @@ -0,0 +1,10 @@ +#N canvas 699 353 450 300 10; +#X obj 114 51 route bang; +#X obj 114 29 inlet; +#X obj 113 173 outlet; +#X obj 114 106 apple/smc TC0D; +#X obj 113 139 route TC0D; +#X connect 0 0 3 0; +#X connect 1 0 0 0; +#X connect 3 0 4 0; +#X connect 4 0 2 0; diff --git a/fans-help.pd b/fans-help.pd new file mode 100644 index 0000000..aaf2856 --- /dev/null +++ b/fans-help.pd @@ -0,0 +1,60 @@ +#N canvas 735 22 560 421 10; +#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header fans 3 12 0 18 +-241536 -1 0; +#X obj 3 189 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlet 15 12 0 13 +-245500 -191407 0; +#N canvas 779 22 494 344 META 0; +#X text 12 25 KEYWORDS control number float store; +#X text 12 45 LICENSE GPL; +#X text 12 65 TEMPLATE template-help.pd v0.1; +#X text 12 85 PLATFORM windows macosx gnulinux; +#X text 12 105 DATATYPE float list; +#X text 12 125 LIBRARY internal; +#X text 12 145 WEBSITE http://crca.ucsd.edu/~msp/; +#X text 12 165 RELEASE_DATE 2007-08-24; +#X text 12 185 RELEASE_VERSION 0.40-test05; +#X text 12 5 GENRE storage; +#X restore 500 373 pd META; +#X obj 3 262 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 15 12 0 +13 -245500 -191407 0; +#X obj 3 338 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15 +12 0 13 -245500 -191407 0; +#X obj 470 6 pddp/pddplink http://wiki.puredata.info/en/apple/fans +-text pdpedia: fans; +#X msg 146 48 bang; +#X obj 73 73 metro 250; +#X obj 73 54 tgl 15 0 empty empty empty 0 -6 0 10 -204786 -1 -1 0 1 +; +#X text 183 46 output sensor values; +#X obj 72 283 cnv 17 3 20 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 +-162280 0; +#X obj 146 101 apple/fans; +#X text 15 6 description: query the system fans in Apples; +#X text 94 201 bang - output all data about all fans; +#X obj 485 -14 apple/fans; +#X floatatom 146 153 5 0 0 0 - - -; +#X floatatom 180 153 5 0 0 0 - - -; +#X floatatom 215 153 5 0 0 0 - - -; +#X obj 173 75 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 -1 +-1 0; +#X text 302 73 choose a specific fan; +#X text 94 221 float - output all data about a specific fan; +#X obj 146 131 route F0Ac F0Mn F0Mx F0Sf F0Tg; +#X floatatom 252 153 5 0 0 0 - - -; +#X floatatom 287 153 5 0 0 0 - - -; +#X obj 72 309 cnv 17 3 20 empty \$0-pddp.cnv.let.1 1 5 9 0 16 -228856 +-162280 0; +#X text 103 280 messages with the values of the various data; +#X text 104 306 messages with status information; +#X text 94 241 symbol - output a specific data about a specific fan +; +#X connect 6 0 11 0; +#X connect 7 0 11 0; +#X connect 8 0 7 0; +#X connect 11 0 21 0; +#X connect 18 0 11 0; +#X connect 21 0 15 0; +#X connect 21 1 16 0; +#X connect 21 2 17 0; +#X connect 21 3 22 0; +#X connect 21 4 23 0; diff --git a/fans.pd b/fans.pd new file mode 100644 index 0000000..a66215b --- /dev/null +++ b/fans.pd @@ -0,0 +1,48 @@ +#N canvas 421 265 450 300 10; +#X obj 164 29 inlet; +#X obj 146 263 outlet; +#X obj 197 263 outlet; +#X obj 26 112 route FNum; +#X msg 116 119 F\$1Ac; +#X msg 157 119 F\$1Mn; +#X msg 200 119 F\$1Mx; +#X msg 241 119 F\$1Sf; +#X msg 283 119 F\$1Tg; +#X obj 146 229 apple/smc; +#X obj 338 120 symbol FNum; +#N canvas 0 22 450 300 gen 0; +#X obj 92 9 inlet; +#X obj 93 270 outlet; +#X obj 93 136 until; +#X obj 93 172 float; +#X obj 134 172 + 1; +#X msg 180 123 0; +#X obj 92 74 trigger anything bang; +#X connect 0 0 6 0; +#X connect 2 0 3 0; +#X connect 3 0 4 0; +#X connect 3 0 1 0; +#X connect 4 0 3 1; +#X connect 5 0 3 1; +#X connect 6 0 2 0; +#X connect 6 1 5 0; +#X restore 26 133 pd gen fnums; +#X obj 164 51 route float bang; +#X connect 0 0 12 0; +#X connect 3 0 11 0; +#X connect 4 0 9 0; +#X connect 5 0 9 0; +#X connect 6 0 9 0; +#X connect 7 0 9 0; +#X connect 8 0 9 0; +#X connect 9 0 1 0; +#X connect 9 0 3 0; +#X connect 9 1 2 0; +#X connect 10 0 9 0; +#X connect 11 0 12 0; +#X connect 12 0 4 0; +#X connect 12 0 5 0; +#X connect 12 0 6 0; +#X connect 12 0 7 0; +#X connect 12 0 8 0; +#X connect 12 1 10 0; diff --git a/smc-help.pd b/smc-help.pd index 8e34c16..045174e 100644 --- a/smc-help.pd +++ b/smc-help.pd @@ -1,6 +1,4 @@ -#N canvas 139 41 559 441 10; -#X obj 4 398 cnv 15 550 20 empty \$0-pddp.cnv.footer empty 20 12 0 -14 -228856 -66577 0; +#N canvas 168 22 559 441 10; #X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header smc 3 12 0 18 -204280 -1 0; #X obj 3 189 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlet 15 12 0 13 @@ -17,22 +15,15 @@ #X text 12 165 RELEASE_DATE 2007-08-24; #X text 12 185 RELEASE_VERSION 0.40-test05; #X restore 504 400 pd META; -#X obj 3 258 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 15 12 0 +#X obj 3 262 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 15 12 0 13 -228856 -1 0; -#X obj 3 338 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15 +#X obj 3 341 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15 12 0 13 -228856 -1 0; -#X text 102 208 BANG - output current screen brightness; #X msg 146 48 bang; -#X text 183 46 output sensor values; -#X text 102 227 "info" - outputs info about the sensor on the right -outlet; -#X obj 72 305 cnv 17 3 20 empty \$0-pddp.cnv.let.1 1 5 9 0 16 -228856 +#X obj 72 312 cnv 17 3 20 empty \$0-pddp.cnv.let.1 1 5 9 0 16 -228856 -162280 0; -#X obj 72 279 cnv 17 3 20 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 +#X obj 72 286 cnv 17 3 20 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 -162280 0; -#X text 103 276 LIST - a list with the values of the left and right -sensors; -#X text 103 306 selector series with info about the sensor; #X obj 489 -14 apple/smc; #X obj 146 111 apple/smc; #X obj 197 134 pddp/print; @@ -41,19 +32,33 @@ pdpedia: apple/smc; #X text 15 6 description: interface to Apple System Management Controller ; #X obj 69 163 pddp/print; -#X obj 105 360 pddp/pddplink http://en.wikipedia.org/wiki/System_Management_Controller +#X obj 78 363 pddp/pddplink http://en.wikipedia.org/wiki/System_Management_Controller ; #X obj 143 142 print; #X msg 158 70 keys; -#X text 196 71 output a list of all available keys in the right outlet -; -#X msg 53 64 symbol TC0D; +#X msg 53 57 symbol TC0D; #X msg 167 90 info; -#X text 203 89 output all status info; -#X connect 7 0 15 0; -#X connect 15 0 19 0; -#X connect 15 0 21 0; -#X connect 15 1 16 0; -#X connect 22 0 15 0; -#X connect 24 0 15 0; -#X connect 25 0 15 0; +#X obj 195 377 pddp/pddplink http://discussions.apple.com/thread.jspa?threadID=734247 +-text Apple Forum: Mac Pro Tempurature question; +#X text 77 377 for a list of keys:; +#X msg 55 89 TC0D; +#X text 103 283 a message with the key symbol and its value; +#X text 103 313 messages with meta info; +#X text 102 208 BANG - output the value of the current key; +#X text 102 225 info - outputs info about the sensor on the right outlet +; +#X text 102 241 keys - output all available keys in the right outlet +; +#X text 16 34 get data:; +#X msg 216 70 FNum; +#X msg 279 73 F2Ac; +#X connect 5 0 9 0; +#X connect 9 0 13 0; +#X connect 9 0 15 0; +#X connect 9 1 10 0; +#X connect 16 0 9 0; +#X connect 17 0 9 0; +#X connect 18 0 9 0; +#X connect 21 0 9 0; +#X connect 28 0 9 0; +#X connect 29 0 9 0; diff --git a/smc.c b/smc.c index d5acf7a..dde7dd3 100644 --- a/smc.c +++ b/smc.c @@ -288,7 +288,6 @@ int SMCGetFanRpm(char *key) * IMPLEMENTATION */ - static void smc_symbol(t_smc* x, t_symbol* key) { DEBUG(post("smc_symbol");); @@ -306,26 +305,25 @@ static void smc_symbol(t_smc* x, t_symbol* key) // convert sp78 value to temperature int intValue = (val.bytes[0] * 256 + val.bytes[1]) >> 2; SETFLOAT(&output_atom, intValue / 64.0); + outlet_anything(x->data_outlet, key, 1, &output_atom); + } else if ((strcmp(val.dataType, DATATYPE_UINT8) == 0) || + (strcmp(val.dataType, DATATYPE_UINT16) == 0) || + (strcmp(val.dataType, DATATYPE_UINT32) == 0)) { + SETFLOAT(&output_atom, _strtoul(val.bytes, val.dataSize, 10)); + outlet_anything(x->data_outlet, gensym(val.key), 1, &output_atom); + } else if (strcmp(val.dataType, DATATYPE_FPE2) == 0) { + SETFLOAT(&output_atom, _strtof(val.bytes, val.dataSize, 2)); + outlet_anything(x->data_outlet, gensym(val.key), 1, &output_atom); + } else { + UInt32 i; + t_atom output_list[val.dataSize]; + for (i = 0; i < val.dataSize; i++) + SETFLOAT(&output_atom + i, (unsigned char) val.bytes[i]); + outlet_anything(x->data_outlet, gensym(val.key), + val.dataSize, output_list); } - outlet_anything(x->data_outlet, key, 1, &output_atom); - } -/* - if ((strcmp(val.dataType, DATATYPE_UINT8) == 0) || - (strcmp(val.dataType, DATATYPE_UINT16) == 0) || - (strcmp(val.dataType, DATATYPE_UINT32) == 0)) { - SETFLOAT(&output_atom, _strtoul(val.bytes, val.dataSize, 10)); - outlet_anything(x->status_outlet, gensym("sensor"), 1, &output_atom); - } else if (strcmp(val.dataType, DATATYPE_FPE2) == 0) { - SETFLOAT(&output_atom, _strtof(val.bytes, val.dataSize, 2)); - outlet_anything(x->status_outlet, gensym("sensor"), 1, &output_atom); - } else { - t_atom output_list[val.dataSize]; - for (i = 0; i < val.dataSize; i++) - SETFLOAT(&output_atom + i, (unsigned char) val.bytes[i]); - outlet_anything(x->status_outlet, gensym("sensor"), - val.dataSize, &output_list); } -*/ + } SMCClose(); } @@ -377,13 +375,24 @@ static void smc_info(t_smc* x) smc_keys(x); } -static void *smc_new(void) +static void smc_anything(t_smc* x, t_symbol *s, int argc, t_atom *argv) +{ + DEBUG(post("smc_anything %d", argc);); + if(argc == 0) { + x->key = s; + if(x->key != &s_) smc_bang(x); + } else if(argc == 1) { + atom_getfloatarg(0, argc, argv); + } +} + +static void *smc_new(t_symbol* s) { DEBUG(post("smc_new");); t_smc *x = (t_smc *)pd_new(smc_class); - x->key = &s_; - x->data_outlet = outlet_new(&x->x_obj, &s_list); + x->key = s; + x->data_outlet = outlet_new(&x->x_obj, &s_anything); x->status_outlet = outlet_new(&x->x_obj, &s_anything); return (x); @@ -392,14 +401,16 @@ static void *smc_new(void) void smc_setup(void) { smc_class = class_new(gensym("smc"), - (t_newmethod)smc_new, - NULL, - sizeof(t_smc), - CLASS_DEFAULT, - 0); + (t_newmethod)smc_new, + NULL, + sizeof(t_smc), + CLASS_DEFAULT, + A_DEFSYMBOL, + 0); /* add inlet datatype methods */ class_addbang(smc_class,(t_method) smc_bang); class_addsymbol(smc_class,(t_method) smc_symbol); class_addmethod(smc_class,(t_method) smc_info, gensym("info"), 0); class_addmethod(smc_class,(t_method) smc_keys, gensym("keys"), 0); + class_addanything(smc_class,(t_method) smc_anything); } -- cgit v1.2.1