Skip to content

Commit 8e7a759

Browse files
committed
Handle GPIO relays with inverse logic (active low)
2 parents 19c326b + a69e3e8 commit 8e7a759

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

HISTORY

+3
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ Version history
5555
0.11: 30/12/2016
5656
- Added multiple cards support for command line ("-s" option to specify cards serial number)
5757
- Created C library version of crelay for inclusion in third party applications
58+
59+
0.12: 03/11/2017
60+
- Handle GPIO relays with inverse logic (active low)

conf/crelay.conf

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ relay5_label = Device 5 # label for relay 5
2121
relay6_label = Device 6 # label for relay 6
2222
relay7_label = Device 7 # label for relay 7
2323
relay8_label = Device 8 # label for relay 8
24+
pulse_duration = 1 # duration of a 'pulse' command in seconds
2425

2526
# GPIO driver parameters
2627
################################################

src/crelay.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ config_t config;
7979
static char rlabels[MAX_NUM_RELAYS][32] = {"My appliance 1", "My appliance 2", "My appliance 3", "My appliance 4",
8080
"My appliance 5", "My appliance 6", "My appliance 7", "My appliance 8"};
8181

82-
8382
/**********************************************************
8483
* Function: config_cb()
8584
*
@@ -134,6 +133,10 @@ static int config_cb(void* user, const char* section, const char* name, const ch
134133
{
135134
pconfig->relay8_label = strdup(value);
136135
}
136+
else if (MATCH("HTTP server", "pulse_duration"))
137+
{
138+
pconfig->pulse_duration = atoi(value);
139+
}
137140
else if (MATCH("GPIO drv", "num_relays"))
138141
{
139142
pconfig->gpio_num_relays = atoi(value);
@@ -483,13 +486,13 @@ int process_http_request(int sock)
483486
if (rstate[relay-1] == ON)
484487
{
485488
crelay_set_relay(com_port, relay, OFF, serial);
486-
sleep(1);
489+
sleep(config.pulse_duration);
487490
crelay_set_relay(com_port, relay, ON, serial);
488491
}
489492
else
490493
{
491494
crelay_set_relay(com_port, relay, ON, serial);
492-
sleep(1);
495+
sleep(config.pulse_duration);
493496
crelay_set_relay(com_port, relay, OFF, serial);
494497
}
495498
}
@@ -668,6 +671,7 @@ int main(int argc, char *argv[])
668671
if (config.relay6_label != NULL) syslog(LOG_DAEMON | LOG_NOTICE, "relay6_label: %s\n", config.relay6_label);
669672
if (config.relay7_label != NULL) syslog(LOG_DAEMON | LOG_NOTICE, "relay7_label: %s\n", config.relay7_label);
670673
if (config.relay8_label != NULL) syslog(LOG_DAEMON | LOG_NOTICE, "relay8_label: %s\n", config.relay8_label);
674+
if (config.pulse_duration != 0) syslog(LOG_DAEMON | LOG_NOTICE, "pulse_duration: %u\n", config.pulse_duration);
671675
if (config.gpio_num_relays != 0) syslog(LOG_DAEMON | LOG_NOTICE, "gpio_num_relays: %u\n", config.gpio_num_relays);
672676
if (config.gpio_active_value >= 0) syslog(LOG_DAEMON | LOG_NOTICE, "gpio_active_value: %u\n", config.gpio_active_value);
673677
if (config.relay1_gpio_pin != 0) syslog(LOG_DAEMON | LOG_NOTICE, "relay1_gpio_pin: %u\n", config.relay1_gpio_pin);
@@ -705,11 +709,18 @@ int main(int argc, char *argv[])
705709
{
706710
port = config.server_port;
707711
}
712+
708713
}
709714
else
710715
{
711716
syslog(LOG_DAEMON | LOG_NOTICE, "Can't load %s, using default parameters\n", CONFIG_FILE);
712717
}
718+
719+
/* Ensure pulse duration is valid **/
720+
if (config.pulse_duration == 0)
721+
{
722+
config.pulse_duration = 1;
723+
}
713724

714725
/* Parse command line for relay labels (overrides config file)*/
715726
for (i=0; i<argc-2 && i<MAX_NUM_RELAYS; i++)

src/data_types.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef struct
5151
const char* relay6_label;
5252
const char* relay7_label;
5353
const char* relay8_label;
54+
uint8_t pulse_duration;
5455

5556
/* [GPIO drv] */
5657
uint8_t gpio_num_relays;

0 commit comments

Comments
 (0)