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 extern float Volt_Reading(int,int,uchar *);
37 extern double Get_Temperature(int portnum,uchar *);
38 extern int owAcquire(int,char *);
39 extern void owRelease(int);
40 extern void output_status(int, char *);
41 extern int key_abort(void);
42 extern SMALLINT FindDevices(int,uchar FamilySN[][8],int,int);
43 extern void msDelay(int);
44
45 #define MAXDEVICES 5
46 #define ONEKBITADD 0x89
47
48
49 // Global necessary for screenio
50 int VERBOSE;
51
52
53 //----------------------------------------------------------------------
54 // This is the Main routine for debit
55 //
main(int argc,char ** argv)56 int main(int argc, char **argv)
57 {
58 char msg[200];
59 int portnum = 0;
60 float Vdd,Vad;
61 double humid,temp;
62 int i;
63 int numbat;
64 uchar famvolt[MAXDEVICES][8];
65
66 // check for required port name
67 if (argc != 2)
68 {
69 sprintf(msg,"1-Wire Net name required on command line!\n"
70 " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
71 "(Linux DS2480),\"1\" (Win32 TMEX)\n");
72 output_status(LV_ALWAYS,msg);
73 return 0;
74 }
75
76 if(!owAcquire(portnum,argv[1]))
77 {
78 output_status(LV_ALWAYS,"Failed to acquire port.\n");
79 return 0;
80 }
81 else
82 {
83
84 do
85 {
86 numbat = FindDevices(portnum,&famvolt[0],SBATTERY_FAM,MAXDEVICES);
87
88 for(i=0;i<numbat;i++)
89 {
90 Vdd = Volt_Reading(portnum,TRUE,&famvolt[0][0]);
91 if(Vdd > 5.8)
92 {
93 Vdd = (float)5.8;
94 }
95 else if(Vdd < 4.0)
96 {
97 Vdd = 4.0;
98 }
99
100 Vad = Volt_Reading(portnum,FALSE,&famvolt[0][0]);
101
102 temp = Get_Temperature(portnum,&famvolt[0][0]);
103
104 humid = (((Vad/Vdd) - 0.16)/0.0062)/(1.0546 - 0.00216 * temp);
105 if(humid > 100)
106 {
107 humid = 100;
108 }
109 else if(humid < 0)
110 {
111 humid = 0;
112 }
113
114 printf("\n");
115 printf("The humidity is: %4.4f\n", humid);
116 printf("Given that the temp was: %2.2f\n", temp);
117 printf("and the volt supply was: %2.2f\n", Vdd);
118 printf("with the volt output was: %2.2f\n", Vad);
119 printf("\n");
120
121 }//for loop
122
123 }while(!key_abort());
124
125 owRelease(portnum);
126 output_status(LV_ALWAYS,"Port released.\n");
127
128 }
129
130 return 1;
131 }
132