guowenxue
2022-04-08 8ea65d42abecc9d668fed3db16069e956c09156e
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
/*********************************************************************************
 *      Copyright:  (C) 2019 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  hal.h
 *    Description:  This file is HAL(Hardware Abstract Layer) initial functions
 *                 
 *        Version:  1.0.0(2019年06月24日)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2019年06月24日 23时46分47秒"
 *                 
 ********************************************************************************/
 
#ifndef  _HAL_H_
#define  _HAL_H_
 
#include <gpiod.h>
 
#include "tsl2561.h"
 
#define OFF   0
#define ON    1
 
#define RELAY_ACTVLEVEL     0
#define RELAY_INACTVLEVEL   1
 
/* Three Lights code */
enum
{
    LIGHT1 = 0, 
    LIGHT_HALLWAY = LIGHT1,      /* Hallway light with infrared and lux support */
 
    LIGHT2,
    LIGHT_LVROOM_LEFT = LIGHT2,  /* living room left light control by MQTT */
 
    LIGHT3,
    LIGHT_LVROOM_RIGHT= LIGHT3,  /* living room right light control by MQTT */
 
    LIGHT_MAX = 4,
};
 
 
typedef struct hal_ctx_s
{
    
    int                  infrared_pin;
    float                lux_threshold; 
    
    int                  light_cnt;
    int                  light_pins[LIGHT_MAX]; /* max support lights */
 
    int                  light_intval; /* lights on interval */
} hal_ctx_t;
 
 
/* init hardware */
extern int hal_init(hal_ctx_t *ctx);
 
/* terminal hardware */
extern void hal_term(hal_ctx_t *ctx);
 
/* turn which light on/off */
extern void turn_light(int which, int cmd);
 
/* Return value: 1(HIGH): Sombody detected  0(LOW): Nobody detected */
extern int infrared_detect(void);
 
 
#endif   /* ----- #ifndef _HAL_H_  ----- */