#!/bin/bash

hexa(){
	a=10
	b=11
	c=12
	d=13
	e=14
	f=15
	bit0=${1:3:1}
	bit1=${1:2:1}
	bit2=${1:1:1}
	bit3=${1:0:1}
	decimal=$(($bit0+($bit1*16)+($bit2*(16**2))+($bit3*(16**3))))

}
decoup(){
	mot=$1
	MSB=${mot:2:2}
	LSB=${mot:0:2}
	mot=$MSB$LSB

}
temperature(){
	temp=$(echo "scale=2;$decimal*175.72"|bc)
	temp=$(echo "scale=2;$temp/65536"|bc)
	temp=$(echo "scale=2;$temp-46.85"|bc)

}
hygrometrie(){
	RH=$(echo "scale=2;$decimal*125"|bc)
        RH=$(echo "scale=2;$RH/65536"|bc)
        RH=$(echo "scale=2;$RH-6"|bc)

}

tp=$(i2cdump -y -f 1 0x40 w|grep ^e0:)
tp=${tp:18:5}
decoup $tp
hexa $mot
temperature
#----------------------------------------
hygro=$(i2cdump -y -f 1 0x40 w|grep ^e0:)
hygro=${hygro:28:5}
decoup $hygro
hexa $mot
hygrometrie 

echo "la température est de : $temp °C
l'humidité est de : $RH %"


