2 /*************************************************************************/
3 /* piece of code and pixmaps from */
5 /* wmspeedfreq ( Tom Kistner ) */
6 /* wmppp ( Martijn Pieterse, Antoine Nulle ) */
7 /* wmapkill (S.Rozange */
9 /* This program is free software; you can redistribute it and/or modify */
10 /* it under the terms of the GNU General Public License as published by */
11 /* the Free Software Foundation; either version 2, or (at your option) */
12 /* any later version. */
14 /* This program is distributed in the hope that it will be useful, */
15 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17 /* GNU General Public License for more details. */
19 /* You should have received a copy of the GNU General Public License */
20 /* along with this program (see the file COPYING); if not, write to the */
21 /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
22 /* Boston, MA 02111-1307, USA */
24 /* you need libcpufreq for the libarary */
25 /* and libcpufreq-dev for cpufreq.h */
28 /*************************************************************************/
38 #include "../wmgeneral/wmgeneral.h"
39 #include "wmcpufreq_master_1.xpm"
40 #include "wmcpufreq_master_2.xpm"
41 #include "wmcpufreq_master_3.xpm"
42 #include "wmcpufreq_mask_1.xbm"
43 #include "wmcpufreq_mask_2.xbm"
44 #include "wmcpufreq_mask_3.xbm"
46 #define DELAY 200000000 /*nano second */
47 #define WMCPUFREQ_VERSION "VERSION 3.0 2009/05/14 \n"
50 pid_t execCommand(char *);
51 void show_mhz(unsigned long*,int);
52 void show_governor(char* );
53 void show_driver(char *);
56 static unsigned char *wm_bits;
57 struct cpufreq_policy *policy;
59 unsigned long min,max,f_min,f_max;
60 int main(int argc, char *argv[])
62 struct timespec ts,ts1;
64 unsigned long freq[8];
72 for(i=0;i<MAX_CPU;i++)
76 for (i=1; i<=argc; i++)
78 if (!strcmp(argv[i], "-v"))
80 printf(WMCPUFREQ_VERSION);
83 if (!strcmp(argv[i], "-exe"))
85 if(strlen(argv[i+1]) < LN_PATH )
86 strcpy(prg,argv[i+1]);
91 /* get driver name (guess all cpu have the same driver) */
92 ptr=cpufreq_get_driver(cpu);
95 printf("no driver found \n");
99 cpufreq_put_driver(ptr);
100 /* get number of cpu (0=cpu0, 1=cpu1 ...) */
102 if( cpufreq_cpu_exists(ncpu) ==0)
106 wm_xpm=wmcpufreq_master_3;
107 wm_bits=wmcpufreq_mask_3_bits;
109 else if (cpufreq_cpu_exists(ncpu-1) ==0)
112 wm_xpm=wmcpufreq_master_3;
113 wm_bits=wmcpufreq_mask_3_bits;
116 else if (cpufreq_cpu_exists(ncpu-2) ==0)
119 wm_xpm=wmcpufreq_master_xpm_2;
120 wm_bits=wmcpufreq_mask_bits_2;
126 wm_xpm=wmcpufreq_master_xpm_1;
127 wm_bits=wmcpufreq_mask_bits_1;
130 /* guess every cpu has the same limits */
131 if(cpufreq_get_hardware_limits(cpu, &f_min, &f_max))
133 printf("can't determine hardware limits \n");
136 openXwindow(argc,argv,
139 wmcpufreq_mask_width,
140 wmcpufreq_mask_height);
143 /* Process any pending X events */
144 while(XPending(display))
146 XNextEvent(display, &event);
163 freq[i]=cpufreq_get_freq_kernel(i);
164 policy=cpufreq_get_policy(cpu);
165 strcpy(gov,policy->governor);
168 cpufreq_put_policy(policy);
178 void show_driver( char *pt)
185 copyXPMArea(6+(6*c),64,6,9, 7+(6*i), 34);
190 void show_governor(char *ptr)
197 copyXPMArea(6+(6*c),78,6,9, 7+(6*i), 49);
202 void show_mhz(unsigned long *kHz,int nu)
204 int i,j,delta=0,ddelta=0,odelta=0;
209 snprintf(buffer, 5, "%4ld", (kHz[0] / 1000));
212 if (buffer[i] == ' ')
215 copyXPMArea(75, 93, 6, 9, 7+(7*i), 7);
219 /* a standard digit */
220 copyXPMArea(((buffer[i]-48)*7)+5,93, 6, 9, 7+(7*i), 7);
222 /* update speed bar */
223 copyXPMArea(65, 18, 49, 9, 7, 18);
227 copyXPMArea(65, 40, ((kHz[0] - f_min) / ((f_max - f_min) / 49)), 9, 7, 18);
234 snprintf(buffer, 5, "%4ld", (kHz[j] / 1000));
238 if (buffer[i] == ' ')
241 copyXPMArea(75, 93, 6, 9, 7+(7*i), 7+delta);
245 /* a standard digit */
246 copyXPMArea(((buffer[i]-48)*7)+5, 93, 6, 9, 7+(7*i), 7+delta);
249 /* update speed bar */
250 copyXPMArea(65, 18, 49, 4, 7, 18+delta);
251 copyXPMArea(65, 40, ((kHz[j] - f_min) / ((f_max - f_min) / 24)), 34, 7, 18+delta);
264 snprintf(buffer, 5, "%4ld", (kHz[j] / 1000));
268 if (buffer[i] == ' ')
271 copyXPMArea(126,6+odelta*j ,6,7, 6+(6*i),5+ddelta*j);
275 /* a standard digit */
276 copyXPMArea(((buffer[i]-48)*6)+66,6+odelta*j, 6,7, 6+(6*i), 5+ddelta*j);
280 copyXPMArea(31,67,24,7,34,5+ddelta*j);
281 /* update spped bar */
282 if( !(nu==2 && j==3) ) /* 3 cpu 4 bar nul */
283 copyXPMArea(6,67 , ((kHz[j] - f_min) / ((f_max - f_min) / 24)),7, 34,5+ddelta*j);