/********************************************************************************* * Copyright: (C) 2021 LingYun IoT System Studio * All rights reserved. * * Filename: relay.c * Description: This file is used to control Relay * * * Pin connection: * Relay Module Raspberry Pi Board * VCC <-----> 5V * I <-----> #Pin16(BCM GPIO23) * GND <-----> GND * * System install: * sudo apt install -y libgpiod-dev gpiod * * ********************************************************************************/ #ifndef _RELAY_H_ #define _RELAY_H_ #define ON 1 #define OFF 0 /* relay code */ enum { RELAY1 = 0, RELAY_CNT, }; /* Relay hardware information */ typedef struct relay_info_s { const char *name; /* Relay name */ int gpio; /* Relay BCM pin number */ int active;/* Relay active GPIO level: 0->low 1->high */ struct gpiod_line *line; /* libgpiod line */ } relay_info_t; /* Relay API context */ typedef struct relay_ctx_s { struct gpiod_chip *chip; relay_info_t *relay; int count; } relay_ctx_t; extern int init_relay(relay_ctx_t *ctx); extern int term_relay(relay_ctx_t *ctx); extern int turn_relay(int which, int cmd); #endif /* ----- #ifndef _RELAY_H_ ----- */