TP CAN DII4A

Dependencies:   mbed-rtos mbed

Committer:
yoshiz37
Date:
Sat Jun 03 19:05:11 2017 +0000
Revision:
0:f7a3b8c3f8ce
TP CAN DII4A

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yoshiz37 0:f7a3b8c3f8ce 1 #include "tHIH6130.h"
yoshiz37 0:f7a3b8c3f8ce 2
yoshiz37 0:f7a3b8c3f8ce 3 tHIH6130::tHIH6130(unsigned char aAdrHIH,I2C* apI2c)
yoshiz37 0:f7a3b8c3f8ce 4 {
yoshiz37 0:f7a3b8c3f8ce 5 pI2c = apI2c;
yoshiz37 0:f7a3b8c3f8ce 6 WrAdr = ((aAdrHIH)<<1) & 0xFE ;
yoshiz37 0:f7a3b8c3f8ce 7 RdAdr = WrAdr | 0x01;
yoshiz37 0:f7a3b8c3f8ce 8
yoshiz37 0:f7a3b8c3f8ce 9
yoshiz37 0:f7a3b8c3f8ce 10 }
yoshiz37 0:f7a3b8c3f8ce 11
yoshiz37 0:f7a3b8c3f8ce 12
yoshiz37 0:f7a3b8c3f8ce 13 float tHIH6130::getTemp(void)
yoshiz37 0:f7a3b8c3f8ce 14 {
yoshiz37 0:f7a3b8c3f8ce 15 return Temp;
yoshiz37 0:f7a3b8c3f8ce 16 }
yoshiz37 0:f7a3b8c3f8ce 17
yoshiz37 0:f7a3b8c3f8ce 18
yoshiz37 0:f7a3b8c3f8ce 19
yoshiz37 0:f7a3b8c3f8ce 20 float tHIH6130::getHumi(void)
yoshiz37 0:f7a3b8c3f8ce 21 {
yoshiz37 0:f7a3b8c3f8ce 22 return Humi;
yoshiz37 0:f7a3b8c3f8ce 23 }
yoshiz37 0:f7a3b8c3f8ce 24
yoshiz37 0:f7a3b8c3f8ce 25 int tHIH6130::StartMesure(void)
yoshiz37 0:f7a3b8c3f8ce 26 {
yoshiz37 0:f7a3b8c3f8ce 27 int Res;
yoshiz37 0:f7a3b8c3f8ce 28 pI2c->start();
yoshiz37 0:f7a3b8c3f8ce 29 Res = pI2c->write(WrAdr);
yoshiz37 0:f7a3b8c3f8ce 30 pI2c->stop();
yoshiz37 0:f7a3b8c3f8ce 31
yoshiz37 0:f7a3b8c3f8ce 32 return Res;
yoshiz37 0:f7a3b8c3f8ce 33 }
yoshiz37 0:f7a3b8c3f8ce 34
yoshiz37 0:f7a3b8c3f8ce 35 int tHIH6130::UpdateData(void)
yoshiz37 0:f7a3b8c3f8ce 36 {
yoshiz37 0:f7a3b8c3f8ce 37 int Res;
yoshiz37 0:f7a3b8c3f8ce 38 unsigned char Data[4];
yoshiz37 0:f7a3b8c3f8ce 39 unsigned int Tmp;
yoshiz37 0:f7a3b8c3f8ce 40
yoshiz37 0:f7a3b8c3f8ce 41 Res = pI2c->read(RdAdr,(char*)Data,4);
yoshiz37 0:f7a3b8c3f8ce 42
yoshiz37 0:f7a3b8c3f8ce 43 // MAJ Humidité
yoshiz37 0:f7a3b8c3f8ce 44 Tmp = Data[0] & 0x3F;
yoshiz37 0:f7a3b8c3f8ce 45 Tmp <<= 8;
yoshiz37 0:f7a3b8c3f8ce 46 Tmp += Data[1];
yoshiz37 0:f7a3b8c3f8ce 47
yoshiz37 0:f7a3b8c3f8ce 48 Humi = ((float)Tmp / (float)16383)*float(100);
yoshiz37 0:f7a3b8c3f8ce 49
yoshiz37 0:f7a3b8c3f8ce 50
yoshiz37 0:f7a3b8c3f8ce 51 // MAJ Température
yoshiz37 0:f7a3b8c3f8ce 52 Tmp = Data[2];
yoshiz37 0:f7a3b8c3f8ce 53 Tmp <<= 8;
yoshiz37 0:f7a3b8c3f8ce 54 Tmp += (Data[3] & 0xFC);
yoshiz37 0:f7a3b8c3f8ce 55 Tmp >>=2;
yoshiz37 0:f7a3b8c3f8ce 56
yoshiz37 0:f7a3b8c3f8ce 57 Temp = ((float)Tmp / (float)16383)*(float)165;
yoshiz37 0:f7a3b8c3f8ce 58 Temp -= 40;
yoshiz37 0:f7a3b8c3f8ce 59
yoshiz37 0:f7a3b8c3f8ce 60 return Res;
yoshiz37 0:f7a3b8c3f8ce 61 }
yoshiz37 0:f7a3b8c3f8ce 62
yoshiz37 0:f7a3b8c3f8ce 63
yoshiz37 0:f7a3b8c3f8ce 64
yoshiz37 0:f7a3b8c3f8ce 65
yoshiz37 0:f7a3b8c3f8ce 66