frederic blanc
/
MAX31850_HelloWorld
test MAX31850
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /** 00002 * @brief MAX31850 00003 * @date 02/06/2014 00004 * @author F.BLANC LAAS-CNRS 00005 * 00006 */ 00007 #include "mbed.h" 00008 #include <stdint.h> 00009 #include <string.h> 00010 #include <map> 00011 00012 #include "onewire.h" 00013 #include "shtlib.h" 00014 00015 #define VERSION "TK_2014_06_02" 00016 //OW 00017 uint8_t gSensorIDs[MAXBUS][MAXSENSORS][OW_ROMCODE_SIZE]; 00018 uint8_t nSensors[MAXBUS]; 00019 //file 00020 LocalFileSystem local("local"); 00021 00022 //console 00023 Serial pc(USBTX, USBRX); // tx, rx 00024 char txt[128]; 00025 //LED 00026 DigitalOut led1(LED1); 00027 DigitalOut led2(LED2); 00028 DigitalOut led3(LED3); 00029 DigitalOut led4(LED4); 00030 // SHT 00031 SHT75 sht(p19, p20); 00032 int shtpresent=false; 00033 char sht_temp_code[32],sht_humi_code[32]; 00034 int owpresent=false; 00035 //MAX31850 00036 class Max31850 00037 { 00038 private : 00039 char owID[17]; 00040 uint64_t uint64_owID; 00041 char tkID[5]; 00042 float offset; 00043 00044 public : 00045 Max31850(); 00046 char *Get_owID(); 00047 uint64_t Get_uint64_owID(); 00048 char *Get_tkID(); 00049 float Get_offset(); 00050 00051 void Set_owID(char *idow); 00052 void Set_tkID(char *tk); 00053 void Set_offset(float off); 00054 00055 ~Max31850(); 00056 }; 00057 Max31850::Max31850() 00058 { 00059 00060 } 00061 char * Max31850::Get_owID() 00062 { 00063 return owID; 00064 } 00065 uint64_t Max31850::Get_uint64_owID() 00066 { 00067 return uint64_owID; 00068 } 00069 char * Max31850::Get_tkID() 00070 { 00071 return tkID; 00072 } 00073 float Max31850::Get_offset() 00074 { 00075 return offset; 00076 } 00077 void Max31850::Set_owID(char *idow) 00078 { 00079 for(int i=0; i<17; ++i) 00080 owID[i]=idow[i]; 00081 uint64_owID=uint64_id( (uint8_t *)owID); 00082 } 00083 void Max31850::Set_tkID(char *tk) 00084 { 00085 for(int i=0; i<5; ++i) 00086 tkID[i]=tk[i]; 00087 } 00088 void Max31850::Set_offset(float off) 00089 { 00090 offset=off; 00091 } 00092 00093 Max31850::~Max31850() 00094 { 00095 delete [] owID; 00096 delete [] tkID; 00097 00098 } 00099 00100 map < uint64_t, Max31850 *> mMax31850; 00101 00102 //pc_rx 00103 00104 00105 void pc_rx(void) 00106 { 00107 char c; 00108 00109 c=pc.getc(); 00110 if (owpresent) { 00111 int n; 00112 int num_sensor; 00113 uint64_t uint64_owID; 00114 uint8_t sp[MAX31850_SP_SIZE]; 00115 float temp; 00116 int err; 00117 switch (c) { 00118 case '1': 00119 n=0; 00120 num_sensor=0; 00121 uint64_owID = uint64_id(&gSensorIDs[n][num_sensor][0]); 00122 for (uint8_t i=0 ; i< MAX31850_SP_SIZE; i++ ) 00123 sp[i]=0; 00124 MAX31850_Read_Scratch(gSensorIDs[n][num_sensor],sp,n) ; 00125 err = MAX31850_Temp_TC(sp,&temp); 00126 if(err) { 00127 pc.printf( "-1.0\r "); 00128 } else { 00129 float temp_CJ; 00130 double temp_true; 00131 MAX31850_Temp_CJ(sp,&temp_CJ); 00132 MAX31850_Temp_TRUE(sp,&temp_true); 00133 temp_true=temp_true-mMax31850[uint64_owID]->Get_offset(); 00134 pc.printf( "%f\r",temp_true); 00135 00136 } 00137 MAX31850_Start_meas(gSensorIDs[n][num_sensor],n); 00138 break; 00139 case '2': 00140 n=0; 00141 num_sensor=1; 00142 uint64_owID = uint64_id(&gSensorIDs[n][num_sensor][0]); 00143 for (uint8_t i=0 ; i< MAX31850_SP_SIZE; i++ ) 00144 sp[i]=0; 00145 MAX31850_Read_Scratch(gSensorIDs[n][num_sensor],sp,n) ; 00146 err = MAX31850_Temp_TC(sp,&temp); 00147 if(err) { 00148 pc.printf( "-1.0\r "); 00149 } else { 00150 float temp_CJ; 00151 double temp_true; 00152 MAX31850_Temp_CJ(sp,&temp_CJ); 00153 MAX31850_Temp_TRUE(sp,&temp_true); 00154 temp_true=temp_true-mMax31850[uint64_owID]->Get_offset(); 00155 pc.printf( "%f\r",temp_true); 00156 00157 } 00158 MAX31850_Start_meas(gSensorIDs[n][num_sensor],n); 00159 break; 00160 case '3': 00161 n=0; 00162 num_sensor=2; 00163 uint64_owID = uint64_id(&gSensorIDs[n][num_sensor][0]); 00164 for (uint8_t i=0 ; i< MAX31850_SP_SIZE; i++ ) 00165 sp[i]=0; 00166 MAX31850_Read_Scratch(gSensorIDs[n][num_sensor],sp,n) ; 00167 err = MAX31850_Temp_TC(sp,&temp); 00168 if(err) { 00169 pc.printf( "-1.0\r "); 00170 } else { 00171 float temp_CJ; 00172 double temp_true; 00173 MAX31850_Temp_CJ(sp,&temp_CJ); 00174 MAX31850_Temp_TRUE(sp,&temp_true); 00175 temp_true=temp_true-mMax31850[uint64_owID]->Get_offset(); 00176 pc.printf( "%f\r",temp_true); 00177 00178 } 00179 MAX31850_Start_meas(gSensorIDs[n][num_sensor],n); 00180 break; 00181 } 00182 } 00183 00184 if(c=='*') { 00185 pc.printf("Mbed Temp tk\r"); 00186 } 00187 00188 } 00189 00190 00191 00192 00193 00194 00195 #define DELAISMESURE 1 00196 int delaismesure=DELAISMESURE; 00197 int main(void) 00198 { 00199 uint8_t num_sensor; 00200 //init SHT 00201 shtpresent=sht_init(sht, "0002F7F070DB", sht_temp_code, sht_humi_code); 00202 00203 //init FILEMAX31850 00204 int nbMAX31850; 00205 FILE *fpini = fopen("/local/tk.ini", "r"); 00206 if(fpini == NULL) { 00207 ; 00208 } else { 00209 fscanf(fpini,"%d",&nbMAX31850); 00210 for (int i=0; i<nbMAX31850; ++i) { 00211 uint64_t uint64_owID; 00212 char owID[17]; 00213 char owIDinv[17]; 00214 fscanf(fpini,"%s ",owID); 00215 00216 owIDinv[0]=owID[14]; 00217 owIDinv[1]=owID[15]; 00218 for(int j=2; j<14; ++j) { 00219 owIDinv[j]=owID[j]; 00220 } 00221 owIDinv[14]=owID[0]; 00222 owIDinv[15]=owID[1]; 00223 owIDinv[16]=owID[16]; 00224 uint64_owID = strtoull(owIDinv,NULL,16); 00225 mMax31850[uint64_owID] = new Max31850; 00226 mMax31850[uint64_owID]->Set_owID(owID); 00227 char tkID[5]; 00228 fscanf(fpini,"%s",tkID); 00229 mMax31850[uint64_owID]->Set_tkID(tkID); 00230 float offset; 00231 fscanf(fpini,"%f",&offset); 00232 mMax31850[uint64_owID]->Set_offset(offset); 00233 00234 } 00235 fclose(fpini); 00236 } 00237 //***init OW 00238 00239 for (uint8_t n=0; n<MAXBUS; ++n) { 00240 search_sensors(n,&nSensors[n],gSensorIDs); 00241 owpresent+=nSensors[n]; 00242 if (owpresent) { 00243 for (num_sensor=0; num_sensor<nSensors[n]; ++num_sensor) { 00244 00245 switch (gSensorIDs[n][num_sensor][0]) { 00246 00247 //MAX31850 00248 case MAX31850_ID: 00249 00250 00251 MAX31850_Start_meas(gSensorIDs[n][num_sensor],n); 00252 wait(0.1); 00253 00254 break; 00255 } 00256 } 00257 } 00258 } 00259 00260 00261 while (1) { 00262 if (pc.readable()) 00263 pc_rx(); 00264 } 00265 return 0; 00266 }
Generated on Tue Jul 12 2022 16:41:44 by 1.7.2