commit | author | age
|
e30a4c
|
1 |
/********************************************************************************* |
GW |
2 |
* Copyright: (C) 2019 LingYun IoT System Studio |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: hal.c |
|
6 |
* Description: This file is RPi HAL(Hardware Abstract Layer) initial functions |
|
7 |
* |
|
8 |
* Version: 1.0.0(2019年06月24日) |
|
9 |
* Author: Guo Wenxue <guowenxue@gmail.com> |
|
10 |
* ChangeLog: 1, Release initial version on "2019年06月24日 23时46分47秒" |
|
11 |
* |
|
12 |
********************************************************************************/ |
|
13 |
|
|
14 |
#include <stdio.h> |
|
15 |
#include <stdlib.h> |
|
16 |
#include <unistd.h> |
|
17 |
#include <fcntl.h> |
|
18 |
#include <dirent.h> |
|
19 |
#include <string.h> |
|
20 |
#include <time.h> |
|
21 |
#include <errno.h> |
|
22 |
|
|
23 |
#include "logger.h" |
|
24 |
#include "hal.h" |
|
25 |
|
|
26 |
int hal_init(hal_ctx_t *ctx) |
|
27 |
{ |
|
28 |
if(!ctx) |
|
29 |
{ |
|
30 |
log_error("Invalid input arguments\n"); |
|
31 |
return -1; |
|
32 |
} |
|
33 |
|
|
34 |
if( ctx->sht2x_enable ) |
|
35 |
{ |
|
36 |
if( sht2x_init()< 0 ) |
|
37 |
{ |
|
38 |
log_error("R&H sensor SHT2X initialise failure\n"); |
|
39 |
return -2; |
|
40 |
} |
|
41 |
else |
|
42 |
{ |
|
43 |
log_info("R&H sensor SHT2X initialise okay\n"); |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
if( ctx->lux_enable ) |
|
48 |
{ |
|
49 |
if( tsl2561_init() < 0 ) |
|
50 |
{ |
|
51 |
log_error("LUX sensor TSL2561 initialise failure\n"); |
|
52 |
return -2; |
|
53 |
} |
|
54 |
else |
|
55 |
{ |
|
56 |
log_info("LUX sensor TSL2561 initialise okay\n"); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
gpio_init(&ctx->gpio); |
|
61 |
|
|
62 |
return 0; |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
void hal_term(hal_ctx_t *ctx) |
|
67 |
{ |
|
68 |
if(!ctx) |
|
69 |
{ |
|
70 |
log_error("Invalid input arguments\n"); |
|
71 |
return ; |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
if( ctx->sht2x_enable ) |
|
76 |
{ |
|
77 |
sht2x_term(); |
|
78 |
} |
|
79 |
|
|
80 |
if( ctx->lux_enable ) |
|
81 |
{ |
|
82 |
tsl2561_term(); |
|
83 |
} |
|
84 |
|
|
85 |
gpio_term(); |
|
86 |
|
|
87 |
return ; |
|
88 |
} |
|
89 |
|