Evironmental Shield API
Envt_Shield_F4_API.cpp@0:9ac219c9a7df, 2014-08-14 (annotated)
- Committer:
- Deepti
- Date:
- Thu Aug 14 11:39:55 2014 +0000
- Revision:
- 0:9ac219c9a7df
- Child:
- 1:d37d15b70bc5
Environmental Shield API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Deepti | 0:9ac219c9a7df | 1 | #include "nucleo-f401re.h" |
Deepti | 0:9ac219c9a7df | 2 | #include "x_nucleo_ike01x1_pressure.h" |
Deepti | 0:9ac219c9a7df | 3 | #include "x_nucleo_ike01x1_uv.h" |
Deepti | 0:9ac219c9a7df | 4 | #include "x_nucleo_ike01x1_hum_temp.h" |
Deepti | 0:9ac219c9a7df | 5 | #include "Envt_Shield_F4_API.h" |
Deepti | 0:9ac219c9a7df | 6 | |
Deepti | 0:9ac219c9a7df | 7 | uint8_t PRESInit=0; |
Deepti | 0:9ac219c9a7df | 8 | uint8_t UVInit=0; |
Deepti | 0:9ac219c9a7df | 9 | uint8_t HumTempInit=0; |
Deepti | 0:9ac219c9a7df | 10 | /*Global variables */ |
Deepti | 0:9ac219c9a7df | 11 | uint8_t HumTempId=0; |
Deepti | 0:9ac219c9a7df | 12 | uint8_t PressID=0; |
Deepti | 0:9ac219c9a7df | 13 | int dec_precision = 2; |
Deepti | 0:9ac219c9a7df | 14 | volatile float UVI_Value; |
Deepti | 0:9ac219c9a7df | 15 | volatile float PRESSURE_Value; |
Deepti | 0:9ac219c9a7df | 16 | volatile float HUMIDITY_Value; |
Deepti | 0:9ac219c9a7df | 17 | volatile float TEMPERATURE_Value; |
Deepti | 0:9ac219c9a7df | 18 | void floatToInt(float in, int32_t *out_int, int32_t *out_dec, int32_t dec_prec); |
Deepti | 0:9ac219c9a7df | 19 | Serial pc(SERIAL_TX, SERIAL_RX); |
Deepti | 0:9ac219c9a7df | 20 | |
Deepti | 0:9ac219c9a7df | 21 | DigitalOut myled(LED1); |
Deepti | 0:9ac219c9a7df | 22 | |
Deepti | 0:9ac219c9a7df | 23 | void Envt_Shield_API:: floatToInt(float in, int32_t *out_int, int32_t *out_dec, int32_t dec_prec) |
Deepti | 0:9ac219c9a7df | 24 | { |
Deepti | 0:9ac219c9a7df | 25 | *out_int = (int32_t)in; |
Deepti | 0:9ac219c9a7df | 26 | in = in - (float)(*out_int); |
Deepti | 0:9ac219c9a7df | 27 | *out_dec = (int32_t)(in*dec_prec); |
Deepti | 0:9ac219c9a7df | 28 | } |
Deepti | 0:9ac219c9a7df | 29 | |
Deepti | 0:9ac219c9a7df | 30 | void Envt_Shield_API:: init() |
Deepti | 0:9ac219c9a7df | 31 | { |
Deepti | 0:9ac219c9a7df | 32 | int mul = 1; |
Deepti | 0:9ac219c9a7df | 33 | for(int i = 0; i < dec_precision; i++) |
Deepti | 0:9ac219c9a7df | 34 | mul = mul*10; |
Deepti | 0:9ac219c9a7df | 35 | |
Deepti | 0:9ac219c9a7df | 36 | if(!BSP_HUM_TEMP_isInitialized()) { |
Deepti | 0:9ac219c9a7df | 37 | BSP_HUM_TEMP_Init(); //This also Inits I2C interface from here. |
Deepti | 0:9ac219c9a7df | 38 | } |
Deepti | 0:9ac219c9a7df | 39 | HumTempId = BSP_HUM_TEMP_ReadID(); |
Deepti | 0:9ac219c9a7df | 40 | if(HumTempId==I_AM_HTS221){ |
Deepti | 0:9ac219c9a7df | 41 | HumTempInit=1; |
Deepti | 0:9ac219c9a7df | 42 | } |
Deepti | 0:9ac219c9a7df | 43 | /*End Temp Sensor Init*/ |
Deepti | 0:9ac219c9a7df | 44 | |
Deepti | 0:9ac219c9a7df | 45 | /*Initialize the pressure sensors*/ |
Deepti | 0:9ac219c9a7df | 46 | if(!BSP_PRESSURE_isInitialized()) { |
Deepti | 0:9ac219c9a7df | 47 | BSP_PRESSURE_Init(); //This also Inits I2C interface from here. |
Deepti | 0:9ac219c9a7df | 48 | PRESInit=1; |
Deepti | 0:9ac219c9a7df | 49 | } |
Deepti | 0:9ac219c9a7df | 50 | PressID = BSP_PRESSURE_ReadID(); |
Deepti | 0:9ac219c9a7df | 51 | |
Deepti | 0:9ac219c9a7df | 52 | int32_t d1, d2, d3, d4; |
Deepti | 0:9ac219c9a7df | 53 | |
Deepti | 0:9ac219c9a7df | 54 | pc.printf("Hello World !\n"); |
Deepti | 0:9ac219c9a7df | 55 | while(1) { |
Deepti | 0:9ac219c9a7df | 56 | wait(1); |
Deepti | 0:9ac219c9a7df | 57 | |
Deepti | 0:9ac219c9a7df | 58 | if(BSP_HUM_TEMP_isInitialized()) |
Deepti | 0:9ac219c9a7df | 59 | { |
Deepti | 0:9ac219c9a7df | 60 | BSP_HUM_TEMP_GetHumidity((float *)&HUMIDITY_Value); |
Deepti | 0:9ac219c9a7df | 61 | BSP_HUM_TEMP_GetTemperature((float *)&TEMPERATURE_Value); |
Deepti | 0:9ac219c9a7df | 62 | |
Deepti | 0:9ac219c9a7df | 63 | floatToInt(HUMIDITY_Value, &d1, &d2, mul); |
Deepti | 0:9ac219c9a7df | 64 | floatToInt(TEMPERATURE_Value, &d3, &d4, mul); |
Deepti | 0:9ac219c9a7df | 65 | pc.printf("H: %d.%02d T: %d.%02d", d1, d2, d3, d4); |
Deepti | 0:9ac219c9a7df | 66 | |
Deepti | 0:9ac219c9a7df | 67 | } |
Deepti | 0:9ac219c9a7df | 68 | |
Deepti | 0:9ac219c9a7df | 69 | if(BSP_PRESSURE_isInitialized()) |
Deepti | 0:9ac219c9a7df | 70 | { |
Deepti | 0:9ac219c9a7df | 71 | BSP_PRESSURE_GetPressure((float *)&PRESSURE_Value); |
Deepti | 0:9ac219c9a7df | 72 | floatToInt(PRESSURE_Value, &d1, &d2, mul); |
Deepti | 0:9ac219c9a7df | 73 | pc.printf(" P: %d.%02d\n", d1, d2); |
Deepti | 0:9ac219c9a7df | 74 | |
Deepti | 0:9ac219c9a7df | 75 | } |
Deepti | 0:9ac219c9a7df | 76 | |
Deepti | 0:9ac219c9a7df | 77 | if(BSP_UV_isInitialized()) |
Deepti | 0:9ac219c9a7df | 78 | { |
Deepti | 0:9ac219c9a7df | 79 | BSP_UV_GetIndex((float *)&UVI_Value); |
Deepti | 0:9ac219c9a7df | 80 | floatToInt(UVI_Value, &d1, &d2, mul); |
Deepti | 0:9ac219c9a7df | 81 | pc.printf("UV: %d.%02d\n", d1, d2); |
Deepti | 0:9ac219c9a7df | 82 | } |
Deepti | 0:9ac219c9a7df | 83 | |
Deepti | 0:9ac219c9a7df | 84 | pc.printf("Done"); |
Deepti | 0:9ac219c9a7df | 85 | myled = !myled; |
Deepti | 0:9ac219c9a7df | 86 | |
Deepti | 0:9ac219c9a7df | 87 | } |
Deepti | 0:9ac219c9a7df | 88 | } |