guowenxue
2019-05-17 1abf6c4b401af1c20d62fe9c2f5e73ce84d14b22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*********************************************************************************
 *      Copyright:  (C) 2019 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  main.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(29/01/19)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "29/01/19 15:34:41"
 *                 
 ********************************************************************************/
#include <stdio.h>
#include <time.h>
#include <unistd.h>
 
#include "led.h"
#include "ds18b20.h"
#include "sht20.h"
 
int hal_init(void);
 
/********************************************************************************
 *  Description:
 *   Input Args:
 *  Output Args:
 * Return Value:
 ********************************************************************************/
int main (int argc, char **argv)
{
    float              temp;
    float              rh;
 
    if( hal_init() < 0 )
    {
        printf("Initialise hardware failure\n");
        return -1;
    }
    
    while(1)
    {
        turn_led(LED_R, ON);
        sleep(1);
        turn_led(LED_R, OFF);
        sleep(1);
 
        turn_led(LED_G, ON);
        sleep(1);
        turn_led(LED_G, OFF);
        sleep(1);
 
        turn_led(LED_B, ON);
        sleep(1);
        turn_led(LED_B, OFF);
        sleep(1);
 
        if(sht2x_get_temp_humidity(&temp, &rh) < 0)
        {
            printf("SHT2X get temperature and relative humidity failure\n");
        }
        else
        {
            printf("SHT2X Temperature=%lfC, Relative humidity=%lf%% \n", temp, rh);
        }
 
 
        if( ds18b20_get_temperature(&temp) < 0)
        {
            printf("DS18B20 get temperature failure\n");
        }
        else
        {
            printf("DS18B20 get temperature=%lf ℃ \n", temp);
        }
    }
 
    return 0;
} /* ----- End of main() ----- */
 
 
int hal_init(void)
{
    init_led();
 
    if( sht2x_init() < 0 )
    {
        printf("Initialise SHT20 failure\n");
        return -2;
    }
 
    return 0;
}