commit | author | age
|
d6b4a7
|
1 |
/********************************************************************************* |
G |
2 |
* Copyright: (C) 2021 LingYun IoT System Studio |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: relay.c |
|
6 |
* Description: This file is used to control Relay |
|
7 |
* |
|
8 |
* |
|
9 |
* Pin connection: |
|
10 |
* Relay Module Raspberry Pi Board |
|
11 |
* VCC <-----> 5V |
|
12 |
* I <-----> #Pin16(BCM GPIO23) |
|
13 |
* GND <-----> GND |
|
14 |
* |
|
15 |
* System install: |
|
16 |
* sudo apt install -y libgpiod-dev gpiod |
|
17 |
* |
|
18 |
* |
|
19 |
********************************************************************************/ |
|
20 |
|
|
21 |
#ifndef _RELAY_H_ |
|
22 |
#define _RELAY_H_ |
|
23 |
|
|
24 |
#define ON 1 |
|
25 |
#define OFF 0 |
|
26 |
|
|
27 |
/* relay code */ |
|
28 |
enum |
|
29 |
{ |
|
30 |
RELAY1 = 0, |
|
31 |
RELAY_CNT, |
|
32 |
}; |
|
33 |
|
|
34 |
/* Relay hardware information */ |
|
35 |
typedef struct relay_info_s |
|
36 |
{ |
|
37 |
const char *name; /* Relay name */ |
|
38 |
int gpio; /* Relay BCM pin number */ |
|
39 |
int active;/* Relay active GPIO level: 0->low 1->high */ |
|
40 |
struct gpiod_line *line; /* libgpiod line */ |
|
41 |
} relay_info_t; |
|
42 |
|
|
43 |
/* Relay API context */ |
|
44 |
typedef struct relay_ctx_s |
|
45 |
{ |
|
46 |
struct gpiod_chip *chip; |
|
47 |
relay_info_t *relay; |
|
48 |
int count; |
|
49 |
} relay_ctx_t; |
|
50 |
|
|
51 |
extern int init_relay(relay_ctx_t *ctx); |
|
52 |
extern int term_relay(relay_ctx_t *ctx); |
|
53 |
extern int turn_relay(int which, int cmd); |
|
54 |
|
|
55 |
#endif /* ----- #ifndef _RELAY_H_ ----- */ |
|
56 |
|