--- usbrh_main.c- 2011-11-19 05:04:24.000000000 +0900 +++ usbrh_main.c 2011-11-20 05:17:55.000000000 +0900 @@ -20,6 +20,11 @@ * 2008-03-24 0.05 add include for sting.h * */ + +/* + * 2011-11-18 0.05.1 modify for USB-Geiger by kaz@kobe1995 + */ + #include #include #include @@ -27,6 +32,7 @@ #define USBRH_VENDOR 0x1774 #define USBRH_PRODUCT 0x1001 +#define USBGEIGER_PRODUCT 0x1002 // parameter // http://www.sensirion.com/en/pdf/product_information/Data_Sheet_humidity_sensor_SHT1x_SHT7x_E.pdf @@ -134,6 +140,7 @@ { puts("USBRH on Linux 0.05 by Briareos\nusage: usbrh [-vthm1fl]\n" " -v : verbose\n" + " -g : geiger counter\n" " -t : temperature (for MRTG2)\n" " -h : humidity (for MRTG2)\n" " -m : temperature/humidity output(for MRTG2)\n" @@ -149,33 +156,40 @@ char buff[512]; int rc; int iTemperature, iHumidity, opt; +u_int *iCount, *iSecs; double temperature, humidity; unsigned char data[8]; -char flag_v, flag_t, flag_h, flag_d, flag_f, flag_1line, flag_mrtg, flag_l; +char flag_v, flag_t, flag_h, flag_d, flag_f, flag_1line, flag_mrtg, flag_l, flag_g; char tmpDevice[8]; -int DeviceNum; +int DeviceNum, prdct; dev = NULL; dh = NULL; rc = 0; DeviceNum = 1; - flag_f = flag_v = flag_t = flag_h = flag_d = flag_1line = flag_mrtg = flag_l = 0; + flag_f = flag_v = flag_t = flag_h = flag_d = flag_1line = flag_mrtg = flag_l = flag_g = 0; temperature = humidity = 0; memset(buff, 0, sizeof(buff)); memset(data, 0, sizeof(data)); memset(tmpDevice, 0, sizeof(tmpDevice)); + prdct = USBRH_PRODUCT; - while((opt = getopt(argc, argv,"lvth1dmf:?")) != -1){ + while((opt = getopt(argc, argv,"lvgth1dmf:?")) != -1){ switch(opt){ case 'v': flag_v = 1; break; + case 'g': + if(!flag_h && !flag_t) + flag_g = 1; + prdct = USBGEIGER_PRODUCT; + break; case 't': - if(!flag_h) + if(!flag_h && !flag_g) flag_t = 1; break; case 'h': - if(!flag_t) + if(!flag_t && !flag_g) flag_h = 1; break; case 'm': @@ -208,14 +222,14 @@ usb_find_devices(); if(flag_l){ - listdevice(USBRH_VENDOR, USBRH_PRODUCT); + listdevice(USBRH_VENDOR, prdct); return(0); } if(flag_d) usb_set_debug(5); - if((dev = searchdevice(USBRH_VENDOR, USBRH_PRODUCT, DeviceNum)) == (struct usb_device *)NULL){ + if((dev = searchdevice(USBRH_VENDOR, prdct, DeviceNum)) == (struct usb_device *)NULL){ puts("USBRH not found"); return(1); } @@ -273,7 +287,7 @@ sleep(1); // Read data from device - rc = usb_bulk_read(dh, 1, buff, 7, 5000); + rc = usb_bulk_read(dh, 1, buff, 8, 5000); if(flag_d){ if(rc<0){ puts("usb_bulk_read error"); @@ -283,6 +297,8 @@ } } + iCount = &buff[0]; + iSecs = &buff[4]; iTemperature = buff[2]<<8|(buff[3]&0xff); iHumidity = buff[0]<<8|(buff[1]&0xff); if(flag_d){ @@ -310,6 +326,9 @@ if(flag_1line){ printf("Temperature: %.2f C Humidity: %.2f %%\n", temperature, humidity); }else + if(flag_g){ + printf("%u\t%u\n", *iCount, *iSecs); + }else printf("%.2f %.2f\n", temperature, humidity); if((rc = usb_release_interface(dh, dev->config->interface->altsetting->bInterfaceNumber))<0){