074e9a1112cde2f4bd54660394d8ade97546c6d3
[fw/sdcc] / device / examples / ds390 / ow390 / gethumd.c
1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
3 // 
4 // Permission is hereby granted, free of charge, to any person obtaining a 
5 // copy of this software and associated documentation files (the "Software"), 
6 // to deal in the Software without restriction, including without limitation 
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 
8 // and/or sell copies of the Software, and to permit persons to whom the 
9 // Software is furnished to do so, subject to the following conditions:
10 // 
11 // The above copyright notice and this permission notice shall be included 
12 // in all copies or substantial portions of the Software.
13 // 
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
16 // MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES 
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
20 // OTHER DEALINGS IN THE SOFTWARE.
21 // 
22 // Except as contained in this notice, the name of Dallas Semiconductor 
23 // shall not be used except as stated in the Dallas Semiconductor 
24 // Branding Policy. 
25 //---------------------------------------------------------------------------
26 //
27 //  getV.c - This utility gets the Volts for pins Vad and Vdd from the DS2438. 
28 //
29 //  Version:   2.00
30 //  History: 
31
32 #include <stdio.h>
33 #include "ownet.h"  
34 #include "ad26.h"
35
36 #define MAXDEVICES 5
37
38 // Global necessary for screenio
39 int VERBOSE;
40
41 // tini hack
42 int argc=2;
43 char *argv[]={__FILE__, "exow"};
44
45 //----------------------------------------------------------------------
46 //  This is the Main routine for debit
47 //
48 int main() //short argc, char **argv)
49 {
50    char msg[200];
51    int portnum = 0;
52    float Vdd,Vad;
53    double humid,temp;
54    int i;
55    int numbat;
56    uchar famvolt[MAXDEVICES][8];
57
58    // check for required port name
59    if (argc != 2)
60    {
61       sprintf(msg,"1-Wire Net name required on command line!\n"
62                   " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
63                   "(Linux DS2480),\"1\" (Win32 TMEX)\n");
64       //output_status(LV_ALWAYS,msg);
65       printf (msg);
66       return 0;
67    }
68
69    if(!owAcquire(portnum,argv[1],msg))
70    {
71       //output_status(LV_ALWAYS,msg);
72       printf (msg);
73       return 0;
74    }
75    else
76    {
77
78       do
79       {
80          numbat = FindDevices(portnum,&famvolt[0],SBATTERY_FAM,MAXDEVICES);
81          if (numbat==0) {
82            printf ("No device found.\n");
83          }
84
85          for(i=0;i<numbat;i++)
86          {
87             Vdd = Volt_Reading(portnum,TRUE,&famvolt[0][0]);
88             Vad = Volt_Reading(portnum,FALSE,&famvolt[0][0]);
89
90             temp = Get_Temperature(portnum,&famvolt[0][0]);
91
92             humid = (((Vad/Vdd) - 0.16)/0.0062)/(1.0546 - 0.00216 * temp);
93                
94             printf("\n");
95             printf("The humidity is:  %4.4f\n", humid);
96             printf("Given that the temp was:   %2.2f\n", temp);
97             printf("and the volt supply was:   %2.2f\n", Vdd);
98             printf("with the volt output was:  %2.2f\n", Vad);
99             printf("\n");
100
101          }//for loop
102   
103       }while(!key_abort());  
104
105       owRelease(portnum,msg);
106       //output_status(LV_ALWAYS,msg);
107       printf (msg);
108    }
109
110    return 1;
111 }