KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_sht21.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 National Institute for Subatomic Physics Nikhef
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : shell_sht21.c
11  * Created : 21 jun. 2013
12  * Author : Antonio Orzelli
13  * Modified: Simone Biagi
14  */
15 
16 
17 #include "cfg_board.h"
18 
19 #include <string.h>
20 #include <stdio.h>
21 
22 #include "drv/i2c/sht21.h"
23 
24 const char cmd_sht21_help[] = "SHT21 test: call sht21 no args for more help";
25 
26 bool cmd_sht21_exec(int argc, const char *args[])
27 {
28  int temperature, humidity;
29 
30  //if (argc != 1) return false;
31 
32  if (argc == 0){
33  puts("\nsht21 read temp: read Temperature - hold mode \nsht21 read humi: read Humidity - hold mode \nsht21 trigT: trigger Temperature measurement \nsht21 readT: read Temperature \nsht21 trigRH: trigger Relative Humidity measurement \nsht21 readRH: read Relative Humidity");
34  return true;
35  }
36 
37  if ( (argc == 1) && (strcmp(args[0], "trigT") == 0))
38  {
40  errPrint(true);
41  }
42  else if ( (argc == 1) && (strcmp(args[0], "readT") == 0))
43  {
44  if(sht21ReadTemp(I2C3, SHT21_I2C_ADDR, &temperature))
45  printf("\n\nTemperature: %d.%d C", (temperature/100), (temperature%100));
46  else
47  errPrint(true);
48  }
49  else if ( (argc == 1) && (strcmp(args[0], "trigRH") == 0))
50  {
52  errPrint(true);
53  }
54  else if ( (argc == 1) && (strcmp(args[0], "readRH") == 0))
55  {
56  if(sht21ReadHumid(I2C3, SHT21_I2C_ADDR, &humidity))
57  printf("\n\nHumidity: %d.%d %%", (humidity/10), (humidity%10));
58  else
59  errPrint(true);
60  }
61  else if ( (argc == 2) && (strcmp(args[0], "read") == 0) && (strcmp(args[1], "temp") == 0))
62  {
63  if(sht21Temp(I2C3, SHT21_I2C_ADDR, &temperature))
64  printf("\n\nTemperature: %d.%d C", (temperature/100), (temperature%100));
65  else
66  errPrint(true);
67  }
68  else if ( (argc == 2) && (strcmp(args[0], "read") == 0) && (strcmp(args[1], "humi") == 0))
69  {
70  if(sht21Humi(I2C3, SHT21_I2C_ADDR, &humidity))
71  printf("\n\nHumidity: %d.%d %%", (humidity/10), (humidity%10));
72  else
73  errPrint(true);
74  }
75  else return false;
76 
77  return true;
78 }
79 
bool sht21Humi(I2C_Device *dev, uint8_t addr, int *answer)
Starts and reads the relative humidity from SHT21 at I2C address &#39;addr&#39; (hold master mode); puts the ...
Definition: sht21.c:139
bool sht21Temp(I2C_Device *dev, uint8_t addr, int *answer)
Starts and reads the temperatures from SHT21 at I2C address &#39;addr&#39; (hold master mode); puts the resul...
Definition: sht21.c:76
#define I2C3
Virtual OpenCores I2C.
Definition: dev_soc.h:66
bool sht21ReadTemp(I2C_Device *dev, uint8_t addr, int *answer)
Reads the temperatures from SHT21 at I2C address &#39;addr&#39;; puts the result in answer.
Definition: sht21.c:61
bool sht21ReadHumid(I2C_Device *dev, uint8_t addr, int *answer)
Reads the relative humidity from SHT21 at I2C address &#39;addr&#39;; puts the result in answer.
Definition: sht21.c:124
void errPrint(bool clear)
Prints the last error.
Definition: err.c:79
#define SHT21_I2C_ADDR
SHT21 I2C Address.
Definition: cfg_board.h:43
This driver is to read the SHT21 I2C temperature and humidity sensor.
bool sht21StartTempMeas(I2C_Device *dev, uint8_t addr)
Starts the temperature measurement in the SHT21 module at I2C address &#39;addr&#39;.
Definition: sht21.c:37
bool sht21StartHumidMeas(I2C_Device *dev, uint8_t addr)
Starts the relative humidity measurement in the SHT21 module at I2C address &#39;addr&#39;.
Definition: sht21.c:100
Configures the board-specific peripherals, like I2C, SPI etc...