コード例 #1
0
ファイル: gethumd.c プロジェクト: fdaggiano74/sparrow-hawk
//----------------------------------------------------------------------
//  This is the Main routine for debit
//
int main(short argc, char **argv)
{
   char msg[200];
   int portnum = 0;
   float Vdd,Vad;
   double humid,temp;
   int i;
   int numbat,cnt=0;
   uchar famvolt[MAXDEVICES][8];

   // check for required port name
   if (argc != 2)
   {
      sprintf(msg,"1-Wire Net name required on command line!\n"
                  " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
                  "(Linux DS2480),\"{1,5}\" (Win32 TMEX)\n");
      printf("%s",msg);
      return 0;
   }

   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      printf("Failed to acquire port.\n");
      return 0;
   }
   else
   {

      do
      {
         numbat = FindDevices(portnum,&famvolt[0],SBATTERY_FAM,MAXDEVICES);

         if(numbat == 0)
         {
            if(cnt > 1000)
            {
               cnt = 0;
               printf("No humidity buttons found.\n");
            }
            else
            {
               cnt++;
            }
         }
         else
         {
            for(i=0;i<numbat;i++)
            {
               Vdd = ReadAtoD(portnum,TRUE,&famvolt[0][0]);
               if(Vdd > 5.8)
               {
                  Vdd = (float)5.8;
               }
               else if(Vdd < 4.0)
               {
                  Vdd = (float) 4.0;
               }

               Vad = ReadAtoD(portnum,FALSE,&famvolt[0][0]);

               temp = Get_Temperature(portnum,&famvolt[0][0]);

               humid = (((Vad/Vdd) - 0.16)/0.0062)/(1.0546 - 0.00216 * temp);
               if(humid > 100)
               {
                  humid = 100;
               }
               else if(humid < 0)
               {
                  humid = 0;
               }

               printf("\n");
               printf("The humidity is:  %4.4f\n", humid);
               printf("Given that the temp was:   %2.2f\n", temp);
               printf("and the volt supply was:   %2.2f\n", Vdd);
               printf("with the volt output was:  %2.2f\n", Vad);
               printf("\n");

            }//for loop
         }

      }while(!key_abort());

      owRelease(portnum);
      printf("Port released.\n");

   }

   return 1;
}
コード例 #2
0
ファイル: Xinu_main.c プロジェクト: 9MMMinor/avrXinu-V7
	//--------------------------------------------------------------------------
	// TEST BUILD MAIN
	//
	int main(void)
	{
		int rslt,i,cnt;
		double temp;
		char buf[12];
		
		
		// find ALL devices
		printf("\nFIND ALL\n");
		cnt = 0;
		rslt = OWFirst();
		while (rslt)	{
			// print device found
			for (i = 7; i >= 0; i--)
				printf("%02X", ROM_NO[i]);
			printf("  %d\n",++cnt);
			
			rslt = OWNext();
		}
		
		// find only 0x10
		printf("\nFIND ONLY 0x10\n");
		cnt = 0;
		OWTargetSetup(0x10);
		while (OWNext())	{
			// check for incorrect type
			if (ROM_NO[0] != 0x10)
				break;
			
			// print device found
			for (i = 7; i >= 0; i--)
				printf("%02X", ROM_NO[i]);
			printf("  %d\n",++cnt);
		}
		if (cnt == 1)	{
			DS1820_startConversion();
			uint8_t spdata[10];
			sleep10(7);
			DS1820_readScratchPad(spdata);
			temp = DS1820_getTemperature(spdata);
			temp = temp*9.0/5.0 +32.0;
			printf("TEMP(F) = %s\n\n",dtostrf(temp,7,2,(char *)buf));
		}
		
		// find all but 0x04, 0x1A, 0x23, and 0x01
		printf("\nFIND ALL EXCEPT 0x10, 0x04, 0x0A, 0x1A, 0x23, 0x01\n");
		cnt = 0;
		rslt = OWFirst();
		while (rslt)	{
			// check for incorrect type
			if ((ROM_NO[0] == 0x04) || (ROM_NO[0] == 0x1A) ||
				(ROM_NO[0] == 0x01) || (ROM_NO[0] == 0x23) ||
				(ROM_NO[0] == 0x0A) || (ROM_NO[0] == 0x10))
				OWFamilySkipSetup();
			else	{
				// print device found
				for (i = 7; i >= 0; i--)
					printf("%02X", ROM_NO[i]);
				printf("  %d\n",++cnt);
			}
			
			rslt = OWNext();
		}
		////////////////////////////////////////////////////////////////////////////////////////////////
		// find ALL DS2438
		double voltage = 0.0;
		int myDS2438 = 0;
		uint8_t DS2438deviceNumber[8];
		double bigT = -1.;
		int micro10voltage = 0;
		
		printf("\nFind all DS2438; Read Temperature and Voltage\n");
		for (rslt=OWFirstType(0x26); rslt; rslt=OWNextType(0x26))	{
			// print device found
			for (i = 7; i >= 0; i--)
				printf("%02X", ROM_NO[i]);
			printf("\n");
			
			// Save the first ROM
			if (myDS2438 == 0)	{
				myDS2438++;
				for (i = 0; i < 8; i++)	{
					DS2438deviceNumber[i] = ROM_NO[i];
				}
			}
			
			if (myDS2438 > 0)	{
				// (default) Read Vdd
				SetupAtoD(0x0F, DS2438deviceNumber);
				
				bigT = Get_Temperature(DS2438deviceNumber);
				printf("TEMP = %s\n\n",dtostrf(bigT,7,3,(char *)buf));
				
				voltage = ReadAtoD(DS2438deviceNumber);
				printf("VDD = %s\n",dtostrf(voltage,6,2,(char *)buf));
			}
			if (myDS2438 > 0)	{
				// (default) Read Vad
				SetupAtoD(0x07, DS2438deviceNumber);
				voltage = ReadAtoD(DS2438deviceNumber);
				micro10voltage = getDS2438Voltage(DS2438deviceNumber);
				printf("VAD = %s\n",dtostrf(voltage,6,2,(char *)buf));
				printf("Micro V = %d\n", micro10voltage);
			}
		}
		
		sleep(1);
	return 0 ;
	}