Hardware Reference
In-Depth Information
128 if ( argc > 3 )
129 f = atof(argv[3]);
130 if ( argc > 1 ) {
131 if ( n > m || n < 1 || m < 1 || f < 586.0 || f > 19200000.0 ) {
132 fprintf(stderr,"Value error: N=%d, M=%d, F=%.1f \n",n,m,f);
133 return 1;
134 }
135 }
136
137 gpio_init();
138
139 if ( argc > 1 ) {
140 /* Run PWM mode */
141 pwm = pwm_open(22,1000.0); /* GPIO 22 (GEN3) */
142 pwm_ratio(pwm,n,m) ; / * n% , Start it */
143
144 printf("PWM set for %d/%d, frequency %.1f "
" (for 60 seconds)\n",n,m,f);
145
146 sleep(60);
147
148 printf("Closing PWM..\n");
149 pwm_close(pwm);
150 } else {
151 /* Run CPU Meter */
152 puts("CPU Meter Mode: ");
153
154 pwm = pwm_open(22,500.0); /* GPIO 22 (GEN3) */
155 pwm_ratio(pwm,1,100); / * Start at 1% */
156
157 for (;;) {
158 pipe = popen("ps -eo pcpu | sed 1d","r");
159 for ( total = 0.0 ; fgets(buf,sizeof buf,pipe); ) {
160 sscanf(buf,"%f ",&pct);
161 total += pct;
162 }
163 pclose(pipe);
164
165 pwm_ratio(pwm,total,100);
166
167 printf("\r%.1f%% ",total);
168 fflush (stdout) ;
169
 
Search WWH ::




Custom Search