Ejemplo n.º 1
0
static float pcsensor_get_temperature(usb_dev_handle* lvr_winusb, float *tempc) {
    int ret;
    switch (device_type(lvr_winusb)) {
        case 0:
            ret = get_temperature(lvr_winusb, tempc);
            break;
        case 1:
            control_transfer(lvr_winusb, uTemperatura);
            ret = interrupt_read_temperatura(lvr_winusb, tempc);
            break;
    }
    if (ret < 0) {
        return ret;
    }
    return 0;
}
Ejemplo n.º 2
0
float pcsensor_get_temperature(usb_dev_handle* lvr_winusb){
	float tempc;
	int ret;
	switch(device_type(lvr_winusb)){
	case 0:
		ret = get_temperature(lvr_winusb, &tempc);
		break;
	case 1:
		control_transfer(lvr_winusb, uTemperatura );
		ret = interrupt_read_temperatura(lvr_winusb, &tempc);
		break;
	}
	if(ret < 0){
		return FLT_MIN;
	}
	return tempc;
}
Ejemplo n.º 3
0
int main( int argc, char **argv) {

     usb_dev_handle *lvr_winusb = NULL;
     float tempc;
     float tempc_measure_offset = 0.0;
     int c;
     struct tm *local;
     time_t t;

     while ((c = getopt (argc, argv, "mnfcvhl::s::")) != -1)
     switch (c)
       {
       case 'v':
         debug = 1;
         break;
       case 'c':
         formato=1; //Celsius
         break;
       case 'f':
         formato=2; //Fahrenheit
         break;
       case 's':
         if (!sscanf(optarg,"%f",&tempc_measure_offset)==1) {
           fprintf (stderr, "Error: '%s' is not (float) numeric.\n", optarg);
           exit(EXIT_FAILURE);
         }
         if (tempc_measure_offset > 100000 || tempc_measure_offset < -100000) {
           fprintf (stderr, "Error: please provide a reasonable offset\n");
           exit(EXIT_FAILURE);
         }
       case 'n':
         formato=3;
         break;
       case 'm':
         mrtg=1;
         break;
       case 'l':
         if (optarg!=NULL){
           if (!sscanf(optarg,"%i",&seconds)==1) {
             fprintf (stderr, "Error: '%s' is not numeric.\n", optarg);
             exit(EXIT_FAILURE);
           } else {
              bsalir = 0;
              break;
           }
         } else {
           bsalir = 0;
           seconds = 5;
           break;
         }
       case '?':
       case 'h':
         printf("pcsensor version %s\n",VERSION);
	 printf("      Aviable options:\n");
	 printf("          -h help\n");
	 printf("          -v verbose\n");
	 printf("          -l[n] loop every 'n' seconds, default value is 5s\n");
	 printf("          -s<f> substract 'f' °C (float) from measured temperature\n");
	 printf("          -c output only in Celsius\n");
	 printf("          -f output only in Fahrenheit\n");
	 printf("          -m output for mrtg integration\n");
	 printf("          -n only display value in Celsius for Nagios\n");

	 exit(EXIT_FAILURE);
       default:
         if (isprint (optopt))
           fprintf (stderr, "Unknown option `-%c'.\n", optopt);
         else
           fprintf (stderr,
                    "Unknown option character `\\x%x'.\n",
                    optopt);
         exit(EXIT_FAILURE);
       }

     if (optind < argc) {
        fprintf(stderr, "Non-option ARGV-elements, try -h for help.\n");
        exit(EXIT_FAILURE);
     }

     if ((lvr_winusb = setup_libusb_access()) == NULL) {
         exit(EXIT_FAILURE);
     }

     (void) signal(SIGINT, ex_program);

     ini_control_transfer(lvr_winusb);

     control_transfer(lvr_winusb, uTemperatura );
     interrupt_read(lvr_winusb);

     control_transfer(lvr_winusb, uIni1 );
     interrupt_read(lvr_winusb);

     control_transfer(lvr_winusb, uIni2 );
     interrupt_read(lvr_winusb);
     interrupt_read(lvr_winusb);



     do {
           control_transfer(lvr_winusb, uTemperatura );
           interrupt_read_temperatura(lvr_winusb, &tempc);
           tempc = tempc - tempc_measure_offset;

           t = time(NULL);
           local = localtime(&t);

           if (mrtg) {
              if (formato==2) {
                  printf("%.2f\n", (9.0 / 5.0 * tempc + 32.0));
                  printf("%.2f\n", (9.0 / 5.0 * tempc + 32.0));
              } else {
                  printf("%.2f\n", tempc);
                  printf("%.2f\n", tempc);
              }

              printf("%02d:%02d\n",
                          local->tm_hour,
                          local->tm_min);

              printf("pcsensor\n");
           } else {

            if (formato != 3) {

              printf("%04d/%02d/%02d %02d:%02d:%02d ",
                          local->tm_year +1900,
                          local->tm_mon + 1,
                          local->tm_mday,
                          local->tm_hour,
                          local->tm_min,
                          local->tm_sec);

            }

              if (formato==3) {
                  // for Nagios
                  printf("%.2f\n", tempc);
              }
              else if (formato==2) {
                  printf("Temperature %.2fF\n", (9.0 / 5.0 * tempc + 32.0));
              } else if (formato==1) {
                  printf("Temperature %.2fC\n", tempc);
              } else {
                  printf("Temperature %.2fF %.2fC\n", (9.0 / 5.0 * tempc + 32.0), tempc);
              }
              fflush(stdout);
           }

           if (!bsalir)
              sleep(seconds);
     } while (!bsalir);

     usb_release_interface(lvr_winusb, INTERFACE1);
     usb_release_interface(lvr_winusb, INTERFACE2);

     usb_close(lvr_winusb);

     return 0;
}
Ejemplo n.º 4
0
int main( int argc, char **argv) {
 
     usb_dev_handle *lvr_winusb = NULL;
     float tempc;
     int c;
     struct tm *local;
     time_t t;
     int devicenum = 0;

     while ((c = getopt (argc, argv, "mfcvhn:l::a:")) != -1)
     switch (c)
       {
       case 'v':
         debug = 1;
         break;
       case 'n':
         if (optarg != NULL) {
           if (!sscanf(optarg,"%i",&devicenum)==1) {
             fprintf (stderr, "Error: '%s' is not numeric.\n", optarg);
             exit(EXIT_FAILURE);
           }
         }
         break;
       case 'c':
         formato=1; //Celsius
         break;
       case 'f':
         formato=2; //Fahrenheit
         break;
       case 'm':
         mrtg=1;
         break;
       case 'l':
         if (optarg!=NULL){
           if (!sscanf(optarg,"%i",&seconds)==1) {
             fprintf (stderr, "Error: '%s' is not numeric.\n", optarg);
             exit(EXIT_FAILURE);
           } else {           
              bsalir = 0;
              break;
           }
         } else {
           bsalir = 0;
           seconds = 5;
           break;
         }
       case 'a':
         if (!sscanf(optarg,"%i",&calibration)==1) {
             fprintf (stderr, "Error: '%s' is not numeric.\n", optarg);
             exit(EXIT_FAILURE);
         } else {           
              break;
         }
       case '?':
       case 'h':
         printf("pcsensor version %s\n",VERSION);
	 printf("      Aviable options:\n");
	 printf("          -h help\n");
	 printf("          -v verbose\n");
	 printf("          -n[i] use device number i (0 is the first one found on the bus)\n");
	 printf("          -l[n] loop every 'n' seconds, default value is 5s\n");
	 printf("          -c output only in Celsius\n");
	 printf("          -f output only in Fahrenheit\n");
	 printf("          -a[n] increase or decrease temperature in 'n' degrees for device calibration\n");
	 printf("          -m output for mrtg integration\n");
  
	 exit(EXIT_FAILURE);
       default:
         if (isprint (optopt))
           fprintf (stderr, "Unknown option `-%c'.\n", optopt);
         else
           fprintf (stderr,
                    "Unknown option character `\\x%x'.\n",
                    optopt);
         exit(EXIT_FAILURE);
       }

     if (optind < argc) {
        fprintf(stderr, "Non-option ARGV-elements, try -h for help.\n");
        exit(EXIT_FAILURE);
     }
 
     if ((lvr_winusb = setup_libusb_access(devicenum)) == NULL) {
         exit(EXIT_FAILURE);
     } 

     (void) signal(SIGINT, ex_program);

     ini_control_transfer(lvr_winusb);
      
     control_transfer(lvr_winusb, uTemperatura );
     interrupt_read(lvr_winusb);
 
     control_transfer(lvr_winusb, uIni1 );
     interrupt_read(lvr_winusb);
 
     control_transfer(lvr_winusb, uIni2 );
     interrupt_read(lvr_winusb);
     interrupt_read(lvr_winusb);


 
     do {
           control_transfer(lvr_winusb, uTemperatura );
           interrupt_read_temperatura(lvr_winusb, &tempc);

           t = time(NULL);
           local = localtime(&t);

           if (mrtg) {
              if (formato==2) {
                  printf("%.2f\n", (9.0 / 5.0 * tempc + 32.0));
                  printf("%.2f\n", (9.0 / 5.0 * tempc + 32.0));
              } else {
                  printf("%.2f\n", tempc);
                  printf("%.2f\n", tempc);
              }
              
              printf("%02d:%02d\n", 
                          local->tm_hour,
                          local->tm_min);

              printf("pcsensor\n");
           } else {
              printf("%04d/%02d/%02d %02d:%02d:%02d ", 
                          local->tm_year +1900, 
                          local->tm_mon + 1, 
                          local->tm_mday,
                          local->tm_hour,
                          local->tm_min,
                          local->tm_sec);

              if (formato==2) {
                  printf("Temperature %.2fF\n", (9.0 / 5.0 * tempc + 32.0));
              } else if (formato==1) {
                  printf("Temperature %.2fC\n", tempc);
              } else {
                  printf("Temperature %.2fF %.2fC\n", (9.0 / 5.0 * tempc + 32.0), tempc);
              }
           }
           
           if (!bsalir)
              sleep(seconds);
     } while (!bsalir);
                                       
     usb_release_interface(lvr_winusb, INTERFACE1);
     usb_release_interface(lvr_winusb, INTERFACE2);
     
     usb_close(lvr_winusb); 
      
     return 0; 
}