test MAX31850

Dependencies:   OneWireFB mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers shtlib.cpp Source File

shtlib.cpp

00001 #include "shtlib.h"
00002 
00003 int sht_writefile(SHT75 sht,float *ptr_temperature,float *ptr_humidity) {
00004     float humi_f,rh_lin,rh_true;           // working registers for Illustration purposes
00005     int t;                                // temporary store for the temp ticks
00006     int h;                                // temp store for the humidity ticks
00007     sht.readTempTicks(&t);
00008     *ptr_temperature = ((float)(t) * SHT_D2) + SHT_D1;
00009     sht.readHumidityTicks(&h);
00010     humi_f = (float)(h);
00011     rh_lin = SHT_C3 * humi_f * humi_f + SHT_C2 * humi_f + SHT_C1;
00012     rh_true=(((*ptr_temperature/100)-25)*(SHT_T1+SHT_T2*humi_f)+rh_lin);
00013     if (rh_true>100)rh_true=-1;                            //cut if the value is outside
00014     if (rh_true<1)rh_true=-1;                                //the physical possible range
00015     *ptr_humidity = rh_true;
00016     return 0;
00017 }
00018 
00019 
00020 int sht_init(SHT75 sht, const char *hwAddr, char *text_temp, char *text_humi) {
00021     int t;
00022     char shtcode[9];
00023     sht.reset();
00024     if (sht.readTempTicks(&t)==true) {
00025         shtcode[7]=hwAddr[5];
00026         shtcode[6]=hwAddr[4];
00027         shtcode[5]=hwAddr[3];
00028         shtcode[4]=hwAddr[2];
00029         shtcode[3]=hwAddr[1];
00030         shtcode[2]=hwAddr[0];
00031         shtcode[1]=0x00;
00032         shtcode[0]=0x80;    //famille SHT_temp
00033         shtcode[8]=crc8((uint8_t*)&shtcode[0],8);
00034         sprintf(text_temp,"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
00035                 shtcode[0], shtcode[1], shtcode[2],
00036                 shtcode[3], shtcode[4], shtcode[5],
00037                 shtcode[6], shtcode[7], shtcode[8]);
00038         shtcode[0]=0x81;    //famille SHT_humi
00039         shtcode[8]=crc8((uint8_t*)&shtcode[0],8);
00040         sprintf(text_humi,"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
00041                 shtcode[0], shtcode[1], shtcode[2],
00042                 shtcode[3], shtcode[4], shtcode[5],
00043                 shtcode[6], shtcode[7], shtcode[8]);
00044         return true; //sht present
00045     }
00046     return false;//sht absent
00047 }