KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dpbasic.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : dpbasic.c
11  * Created : 21 mrt. 2013
12  * Author : Vincent van Beveren
13  */
14 
15 #include "drv/i2c/dpbasic.h"
16 
17 
18 #define _DPB_DATA_LEN 4
19 #define _DPB_VAL_MAX 0x7FFF
20 
21 bool dpbRead(I2C_Device * dev, i2cAddr addr, DpbData * data)
22 {
23  uint8_t temp[_DPB_DATA_LEN];
24  int t;
25 
26  if (!i2cRead(dev, addr, temp, _DPB_DATA_LEN)) return errRebase("DpBasic");
27 
28  if ((temp[0] & 0x80) || (temp[2] & 0x80)) {
29  errSet(ERROR(E_DPB_INVALID));
30  return errRebase("DpBasic");
31  }
32 
33  t = (temp[0] << 8) | temp[1];
34  data->humid = ( t * DPB_MAN_HUMID_RH ) / _DPB_VAL_MAX;
35 
36  t = (temp[2] << 8) | temp[3];
37  data->temp = ( t * ( DPB_MAX_TEMP_C - DPB_MIN_TEMP_C ) ) / _DPB_VAL_MAX +
39 
40  return true;
41 }
#define DPB_MAN_HUMID_RH
Max value in DpbData.humid, in percent RH.
Definition: dpbasic.h:56
#define DPB_MAX_TEMP_C
Max value in DpbData.temp, in tenth of degrees.
Definition: dpbasic.h:53
Structure defines data from the DigiPicco sensor.
Definition: dpbasic.h:66
Structure defines OpenCores I2C Device.
Definition: dev_i2c.h:55
int16_t temp
temperature in degrees celcuis times 10.
Definition: dpbasic.h:68
This driver is to read the DigiPicco I2C sensor.
uint8_t i2cAddr
I2C address type.
Definition: i2c.h:93
bool dpbRead(I2C_Device *dev, i2cAddr addr, DpbData *data)
Read the DigiPicco I2C Basic temperature and humidity control device.
Definition: dpbasic.c:21
int8_t humid
humidity in percent (0-100).
Definition: dpbasic.h:69
bool i2cRead(I2C_Device *dev, i2cAddr addr, uint8_t *bytes, int len)
Reads from the I2C device.
Definition: i2c.c:161
static bool errRebase(const char *name)
Rebases the cause of the error message.
Definition: err.h:104
#define DPB_MIN_TEMP_C
Min value in DpbData.temp, in tenth of degrees.
Definition: dpbasic.h:52
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).